Index: openacs-4/packages/oct-election/oct-election.info =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/oct-election/oct-election.info,v diff -u -N -r1.3 -r1.4 --- openacs-4/packages/oct-election/oct-election.info 14 May 2005 23:16:28 -0000 1.3 +++ openacs-4/packages/oct-election/oct-election.info 12 Sep 2013 10:59:03 -0000 1.4 @@ -8,12 +8,15 @@ f oct-election - + Joel Aufrecht Web app for voting in OCT elections. + + + Index: openacs-4/packages/oct-election/sql/postgresql/oct-election-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/oct-election/sql/postgresql/oct-election-create.sql,v diff -u -N -r1.1 -r1.2 --- openacs-4/packages/oct-election/sql/postgresql/oct-election-create.sql 14 May 2005 19:49:49 -0000 1.1 +++ openacs-4/packages/oct-election/sql/postgresql/oct-election-create.sql 12 Sep 2013 10:59:03 -0000 1.2 @@ -5,7 +5,8 @@ end_time timestamptz, vote_forum_cutoff timestamptz, number_of_candidates integer, - label varchar(100) + label varchar(100), + cvs_history_days integer ); create table oct_candidate ( Index: openacs-4/packages/oct-election/sql/postgresql/upgrade/upgrade-1.0.1-1.0.2.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/oct-election/sql/postgresql/upgrade/upgrade-1.0.1-1.0.2.sql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/oct-election/sql/postgresql/upgrade/upgrade-1.0.1-1.0.2.sql 12 Sep 2013 10:59:03 -0000 1.2 @@ -0,0 +1,11 @@ +-- +-- +-- +-- @author Victor Guerra (guerra@galileo.edu) +-- @creation-date 2006-10-03 +-- @arch-tag: 56805ca6-5f68-4ef7-883f-9026e46fcfa1 +-- @cvs-id $Id: upgrade-1.0.1-1.0.2.sql,v 1.2 2013/09/12 10:59:03 victorg Exp $ +-- + +alter table oct_election add column cvs_history_days integer; +update oct_election set cvs_history_days = 0; Index: openacs-4/packages/oct-election/tcl/oct-election-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/oct-election/tcl/oct-election-procs.tcl,v diff -u -N -r1.1 -r1.2 --- openacs-4/packages/oct-election/tcl/oct-election-procs.tcl 14 May 2005 19:49:49 -0000 1.1 +++ openacs-4/packages/oct-election/tcl/oct-election-procs.tcl 12 Sep 2013 10:59:03 -0000 1.2 @@ -11,6 +11,7 @@ @author Joel Aufrecht } { set status 1 + set text "" # Has the user already voted in this election? set ballot_p [db_string get_ballot { select count(*) @@ -25,37 +26,118 @@ return [list $status $text] } - set num_days 90 + set num_days 180 + set valid_voter_p 0 db_1row get_election { - select start_time, - end_time, - vote_forum_cutoff, - label + select start_time, + end_time, + vote_forum_cutoff, + label, + cvs_history_days, + (case when now() > start_time then 1 else 0 end) as past_start_p, + (case when now() > end_time then 1 else 0 end) as past_end_p from oct_election where election_id = :election_id } + set pretty_vote_forum_cutoff [lc_time_fmt $vote_forum_cutoff %c] set before_sql "to_date(:vote_forum_cutoff, 'YYYY-MM-DD')" - #TODO: enable and test this on openacs - set num_posts 2 - # set num_posts [db_string get_count " - # select count(message_id) as num_posts - # from cc_users, forums_messages - # where cc_users.user_id = forums_messages.user_id - # and posting_date between $before_sql - interval '$num_days days' and $before_sql - # and cc_users.user_id = $user_id - # group by cc_users.user_id - #"] + set num_posts [db_string get_count " + select count(message_id) as num_posts + from cc_users, forums_messages + where cc_users.user_id = forums_messages.user_id + and posting_date between $before_sql - interval '$num_days days' and $before_sql + and cc_users.user_id = $user_id + "] if {$num_posts < 2} { set status 0 - set text "You are not a valid voter for this election. See OpenACS Governance" + ns_log warning "not valid voter b/c forums $user_id" + set text "You are not a valid voter for this election because you have not posted at least twice in the OpenACS forums since $pretty_vote_forum_cutoff. See OpenACS Governance" + } else { + set valid_voter_p 1 + } + + #Checking CVS commit history + set cvs_user [acs_user::get_element -user_id $user_id -element username] + set cvs_history_date [db_string get_cvs_days { + select start_time::date - cvs_history_days + from oct_election + where election_id = :election_id + } ] + + set ql "select revisions where date in \[${cvs_history_date},[lc_time_fmt $start_time %Y-%m-%d]\] and author=$cvs_user order by date group by directory return totalLines" + set csv "true" + set service_url [export_vars -base "http://fisheye.openacs.org/search/OpenACS/" {ql csv}] + + ns_log Warning "vguerra trying request: $service_url" + + if {![catch { + set commit_info [ns_httpget $service_url] + } errmsg] } { + set commits [llength [split $commit_info "\n"]] + if {$commits < 3} { + if {$status} { + set status 0 + set text "You are not a valid voter for this election because you have not committed in the CVS Repository in the last $cvs_history_days . See OpenACS Governance" + } + } else { + set valid_voter_p 1 + } + } else { + if {$status} { + set status 0 + set text "We can not confirm your commit history in our CVS Repository, so you can not vote at this moment." + } + } + + if {!$valid_voter_p} { return [list $status $text] } + + if {!$past_start_p} { + set status 0 + set text "The election will not begin until [lc_time_fmt $start_time %c]" + return [list $status $text] + } + if {$past_end_p} { + set status 0 + set text "The election ended at [lc_time_fmt $end_time %c]" + return [list $status $text] + } set status 1 - set text "You have already voted in this election." + set text "We look forward to your vote." return [list $status $text] } + +ad_proc -public oct-election::valid_voters { + {-status "not_voted"} + -election_id:required +} { + Return a list of valid voters + + @param status Could be "voted" or "non_voted", reflecting the voters who have voted for the elections already and the ones who did not vote yet. +} { + + + if {$status eq "voted"} { + return [db_list voters "select u. user_id from cc_users u, (select count(user_id) as ballot,user_id from oct_ballot o where election_id = 5 group by user_id) ballots where ballots.user_id = u.user_id and ballot > 0 and u.member_state = 'approved'"] + ad_script_abort + } else { + set voter_ids [list] + db_foreach possible_voter "select u. user_id from cc_users u where u.member_state = 'approved'" { + + # Check if the user is actually allowed to vote + set valid_voter [oct-election::valid_voter_p -election_id $election_id -user_id $user_id] + set valid_voter_p [lindex $valid_voter 0] + if {$valid_voter_p} { + lappend voter_ids $user_id + } + } + } + + return $voter_ids +} \ No newline at end of file Index: openacs-4/packages/oct-election/www/election-edit.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/oct-election/www/election-edit.tcl,v diff -u -N -r1.2 -r1.3 --- openacs-4/packages/oct-election/www/election-edit.tcl 14 May 2005 23:16:28 -0000 1.2 +++ openacs-4/packages/oct-election/www/election-edit.tcl 12 Sep 2013 10:59:03 -0000 1.3 @@ -15,6 +15,7 @@ {start_time:text {label "Start Time (2005-04-01 10:00PST)"}} {end_time:text {label "End Time"}} {vote_forum_cutoff:text {label "Forum Posting cutoff date (2005-04-01 10:00PST)"}} + {cvs_history_days:text {label "Number of days for checking Commit History"}} {number_of_candidates:integer {label "Number of Candidates"}} } -new_request { auth::require_login @@ -31,6 +32,7 @@ end_time, label, vote_forum_cutoff, + cvs_history_days, number_of_candidates from oct_election where election_id = :election_id; @@ -40,17 +42,18 @@ } -new_data { db_dml create_election { insert into oct_election - (start_time, end_time, number_of_candidates, label) - values (:start_time, :end_time, :number_of_candidates, :label); + (start_time, end_time, number_of_candidates, vote_forum_cutoff, label, cvs_history_days) + values (:start_time, :end_time, :number_of_candidates, :vote_forum_cutoff, :label, :cvs_history_days); } } -edit_data { db_dml update_election { update oct_election set start_time = :start_time, end_time = :end_time, vote_forum_cutoff = :vote_forum_cutoff, + cvs_history_days = :cvs_history_days, number_of_candidates = :number_of_candidates, - label = :label + label = :label where election_id = :election_id} ad_returnredirect [export_vars -base election {election_id}] } Index: openacs-4/packages/oct-election/www/election.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/oct-election/www/election.adp,v diff -u -N -r1.2 -r1.3 --- openacs-4/packages/oct-election/www/election.adp 14 May 2005 23:16:28 -0000 1.2 +++ openacs-4/packages/oct-election/www/election.adp 12 Sep 2013 10:59:03 -0000 1.3 @@ -3,10 +3,11 @@ @context;noquote@

Election: @label@ -

Number of winners possible: @number_of_candidates@ -

Start time: @start_time@ -

End time: @end_time@ -

Forum cutoff date: @vote_forum_cutoff@ +

Number of OCT vacancies: @number_of_candidates@ +

Start time: @pretty_start_time@ +

End time: @pretty_end_time@ +

Forum cutoff date: @pretty_vote_forum_cutoff@ +

Check CVS Commit History for the las @cvs_history_days@ days

Ballots: @ballot_count@

Edit

@@ -30,6 +31,6 @@ - @valid_voter_text@ + @valid_voter_text;noquote@ Index: openacs-4/packages/oct-election/www/election.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/oct-election/www/election.tcl,v diff -u -N -r1.3 -r1.4 --- openacs-4/packages/oct-election/www/election.tcl 14 May 2005 23:16:28 -0000 1.3 +++ openacs-4/packages/oct-election/www/election.tcl 12 Sep 2013 10:59:03 -0000 1.4 @@ -10,18 +10,25 @@ set valid_voter_p [lindex $valid_voter 0] set valid_voter_text [lindex $valid_voter 1] -db_1row get_election { +if {![db_0or1row get_election { select start_time, end_time, vote_forum_cutoff, number_of_candidates, label, + cvs_history_days, (case when now() > start_time then 1 else 0 end) as past_start_p, (case when now() > end_time then 1 else 0 end) as past_end_p from oct_election - where election_id = :election_id + where election_id = :election_id and election_id <> 2 +}]} { + ad_returnredirect "election2" } +set pretty_start_time [lc_time_fmt $start_time %c] +set pretty_end_time [lc_time_fmt $end_time %c] +set pretty_vote_forum_cutoff [lc_time_fmt $vote_forum_cutoff %c] + set ballot_count [db_string get_ballot_count { select count(*) from oct_ballot @@ -52,7 +59,7 @@ } } -if {$past_end_p} { +if {!$past_end_p} { set order_clause "order by label" } else { set order_clause "order by cand_count desc" @@ -87,4 +94,3 @@ select now() as now from dual; } - Index: openacs-4/packages/oct-election/www/election2.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/oct-election/www/election2.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/oct-election/www/election2.adp 12 Sep 2013 10:59:03 -0000 1.2 @@ -0,0 +1,11 @@ + +Andrew Grumet has advised us that he will not be able to serve on the OCT if he is reelected. +

+To make sure everyone's is able to get their full 5 votes, the election will be restarted with a new ballot with Andrew's name removed. +

+The election starts now and will continue until Midnight 11 Novemeber UTC. +

+I apologize for the inconvenience, I hope everyone who has the opporunity to vote will take it. +

+The URL of the election is http://openacs.org/oct-election/election?election%5fid=3 + Index: openacs-4/packages/oct-election/www/find-match-cvs-users-2.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/oct-election/www/find-match-cvs-users-2.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/oct-election/www/find-match-cvs-users-2.adp 12 Sep 2013 10:59:03 -0000 1.2 @@ -0,0 +1,14 @@ + + @title@ + @context@ + + + + +

  • @users.last_name@, @users.first_names@ (@users.email@) - CVS user: @users.username@
  • + + +
  • @users.last_name@, @users.first_names@ (@users.email@)
  • +
    + + Index: openacs-4/packages/oct-election/www/find-match-cvs-users-2.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/oct-election/www/find-match-cvs-users-2.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/oct-election/www/find-match-cvs-users-2.tcl 12 Sep 2013 10:59:03 -0000 1.2 @@ -0,0 +1,46 @@ +# + +ad_page_contract { + + + + @author Victor Guerra (guerra@galileo.edu) + @creation-date 2006-11-17 + @arch-tag: e71ac791-82c4-4e2d-9bc6-9d773c882bd3 + @cvs-id $Id: find-match-cvs-users-2.tcl,v 1.2 2013/09/12 10:59:03 victorg Exp $ +} { + search_text + cvs_user:notnull +} -properties { +} -validate { +} -errors { +} + +if {![acs_user::site_wide_admin_p]} { + ad_return_complaint 1 "You have no permission to manage cvs users!" +} + +set search_text [string trim $search_text] +set title "Searching user" +set context [list $title] + +db_multirow -extend {assigned_p} users select_users { + select pe.person_id, + pe.first_names, + pe.last_name, + pa.email, + us.username + from persons pe, parties pa, users us + where pe.person_id = pa.party_id + and pe.person_id = us.user_id + and (lower(last_name) like lower('%' || :search_text || '%') + or lower(first_names) like lower('%' || :search_text || '%') + or lower(email) like lower('%' || :search_text || '%')) +} { + set assigned_p 1 + if {$username eq "" || [util_email_valid_p $username]} { + set assigned_p 0 + } +} + +ad_return_template Index: openacs-4/packages/oct-election/www/find-match-cvs-users.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/oct-election/www/find-match-cvs-users.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/oct-election/www/find-match-cvs-users.adp 12 Sep 2013 10:59:04 -0000 1.2 @@ -0,0 +1,8 @@ + + @title@ + @context@ + +
    + Find a user match for cvs user: @cvs_user@ + +
    Index: openacs-4/packages/oct-election/www/find-match-cvs-users.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/oct-election/www/find-match-cvs-users.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/oct-election/www/find-match-cvs-users.tcl 12 Sep 2013 10:59:04 -0000 1.2 @@ -0,0 +1,23 @@ +# + +ad_page_contract { + + Matchs a openacs.org user with a given cvs user. + + @author Victor Guerra (guerra@galileo.edu) + @creation-date 2006-11-17 + @arch-tag: bb0f9ebe-7f89-4e2c-a40e-e0086ff80d70 + @cvs-id $Id: find-match-cvs-users.tcl,v 1.2 2013/09/12 10:59:04 victorg Exp $ + } { + cvs_user:notnull +} -properties { +} -validate { +} -errors { +} + +if {![acs_user::site_wide_admin_p]} { + ad_return_complaint 1 "You have no permission to manage cvs users!" +} + +set title "Searching user" +set context [list $title] Index: openacs-4/packages/oct-election/www/match-cvs-users-2.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/oct-election/www/match-cvs-users-2.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/oct-election/www/match-cvs-users-2.tcl 12 Sep 2013 10:59:04 -0000 1.2 @@ -0,0 +1,26 @@ +# + +ad_page_contract { + + Assigns a given cvs user ( useranem ) for a given user + + @author Victor Guerra (guerra@galileo.edu) + @creation-date 2006-11-17 + @arch-tag: ba6f1ea5-8703-4ff3-8f17-9e0b5f3aeae3 + @cvs-id $Id: match-cvs-users-2.tcl,v 1.2 2013/09/12 10:59:04 victorg Exp $ +} { + user_id:integer,notnull + cvs_user:notnull +} -properties { +} -validate { +} -errors { +} + +if {![acs_user::site_wide_admin_p]} { + ad_return_complaint 1 "You have no permission to manage cvs users!" +} + +acs_user::update -user_id $user_id \ + -username $cvs_user + +ad_returnredirect match-cvs-users \ No newline at end of file Index: openacs-4/packages/oct-election/www/match-cvs-users.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/oct-election/www/match-cvs-users.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/oct-election/www/match-cvs-users.adp 12 Sep 2013 10:59:04 -0000 1.2 @@ -0,0 +1,5 @@ + + @title@ + @context@ + + Index: openacs-4/packages/oct-election/www/match-cvs-users.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/oct-election/www/match-cvs-users.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/oct-election/www/match-cvs-users.tcl 12 Sep 2013 10:59:04 -0000 1.2 @@ -0,0 +1,97 @@ +# + +ad_page_contract { + + This script tries to match the cvs accounts with the openacs.org accounts + + @author Victor Guerra (guerra@galileo.edu) + @creation-date 2006-11-13 + @arch-tag: 868cdf88-cbc4-4e37-8f6c-ba7caab5d2cd + @cvs-id $Id: match-cvs-users.tcl,v 1.2 2013/09/12 10:59:04 victorg Exp $ +} { + +} -properties { +} -validate { +} -errors { +} + +if {![acs_user::site_wide_admin_p]} { + ad_return_complaint 1 "You have no permission to manage cvs users!" +} + +set title "CVS Users Sync" +set context [list $title] +set cvs_users_file "[acs_root_dir]/cvs_users.txt" + +if {![file exists $cvs_users_file]} { + ad_return_complaint 1 "file cvs_users.txt not found!!, it should be under [acs_root_dir]" +} + +set fp [open $cvs_users_file r] +set cvs_users [read $fp] +close $fp + +template::list::create \ + -name users_info \ + -multirow users_info \ + -key line_id \ + -elements { + line_id { + label "Line \#" + html { align center } + } + cvs_user { + label "CVS User" + display_template { @users_info.cvs_user@ } + html { align center} + } + associated_user { + label "openacs.org user" + html { align center } + } + possible_user { + label "Possible openacs.org user" + display_template { @users_info.possible_user;noquote@ } + html { align center} + } + actions { + label "Actions" + display_template { @users_info.actions;noquote@} + html { align center } + } + } + +multirow create users_info line_id cvs_user associated_user possible_user actions + +set line_number 0 +foreach line [split $cvs_users "\n"] { + set actions "-" + set associated_user "" + set possible_user "" + incr line_number + set line_splitted [split $line ":"] + set cvs_user [lindex $line_splitted 0] + + if {$cvs_user ne ""} { + set user_names [lindex $line_splitted 4] + set user_id [acs_user::get_by_username -username $cvs_user] + if {$user_id ne ""} { + acs_user::get -user_id $user_id -array user_info + set associated_user "$user_info(name) ($user_info(email))" + } else { + regsub " " [string tolower $user_names] "" lower_user_names + foreach person_id [db_list get_persons { + select person_id from persons + where lower(replace(first_names || last_name, ' ', '')) = :lower_user_names + }] { + acs_user::get -user_id $person_id -array user_info + append possible_user "$user_info(name) ($user_info(email)) match
    " + } + } + if {$associated_user eq "" && $possible_user eq ""} { + set actions "Find a match" + } + multirow append users_info $line_number "$user_names ($cvs_user)" $associated_user $possible_user $actions + } +} + Index: openacs-4/packages/oct-election/www/user-list.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/oct-election/www/user-list.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/oct-election/www/user-list.adp 12 Sep 2013 10:59:04 -0000 1.2 @@ -0,0 +1,6 @@ + + @page_title;noquote@ + "@context;noquote@" + + + Index: openacs-4/packages/oct-election/www/user-list.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/oct-election/www/user-list.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/oct-election/www/user-list.tcl 12 Sep 2013 10:59:04 -0000 1.2 @@ -0,0 +1,109 @@ +ad_page_contract { + @cvs-id $Id: user-list.tcl,v 1.2 2013/09/12 10:59:04 victorg Exp $ +} { +} + +set page_title "OCT Voting List" +set context $page_title + +template::list::create \ + -name voters_foo \ + -multirow voters \ + -elements { + name { + label "Name" + html { align center} + aggregate count + aggregate_label "Total" + } + cvs_user { + label "cvs_user" + html { align center} + } + num_posts { + label "num_posts" + html { align center} + } + } + +# set up basic vars + +set election_id 5 + +db_1row get_election { + select start_time, + end_time, + vote_forum_cutoff, + label, + (case when now() > start_time then 1 else 0 end) as past_start_p, + (case when now() > end_time then 1 else 0 end) as past_end_p + from oct_election + where election_id = :election_id +} +set cvs_history_days [db_string get_cvs_days { + select cvs_history_days + from oct_election + where election_id = :election_id +} ] + + + +set num_days 90 +set valid_voter_p 0 + +set before_sql "to_date(:vote_forum_cutoff, 'YYYY-MM-DD')" + +set usernames [list] + + +db_multirow \ + -extend { + mailto + name + } voters voters_select " + (select u2.user_id, u2.username as cvs_user, count(message_id) as num_posts + from users u2, forums_messages + where u2.user_id = forums_messages.user_id + and posting_date between $before_sql - interval \'$num_days days\' and $before_sql + group by u2.user_id, u2.username + having count(*) > 1) + UNION + (select user_id, username as cvs_user, -1 as num_post from users + where username not like '%@%') + order by num_posts DESC + " { + + # don't repeat users + if {[lsearch -exact $usernames $cvs_user] != -1} { + continue + } + lappend usernames $cvs_user + + set status 0 + if {$num_posts < 2} { + + set num_posts "Through CVS commits" + #Checking CVS commit history + # set cvs_user [acs_user::get_element -user_id $user_id -element username] + if {$cvs_history_days eq 0} { + set cvs_history_days "all" + } + set service_url "http://xarg.net/tools/cvs/rss/?user=$cvs_user&days=$cvs_history_days" + if {![catch { + set commit_info [ns_httpget $service_url] + } errmsg] } { + set doc [dom parse $commit_info] + set root_node [$doc documentElement] + set commits [llength [$root_node selectNodes /rss/channel/item]] + if {!$commits} { + continue + } + } else { + continue + } + + } + + set name [acs_user::get_element -user_id $user_id -element name] + + }