fedora-vote castvote.cgi, 1.12, 1.13 newelection.py, 1.8, 1.9 vote.cgi, 1.10, 1.11 voting.py, 1.11, 1.12 votingadmin.py, 1.7, 1.8
Toshio くらとみ (toshio)
fedora-extras-commits at redhat.com
Sun Apr 20 23:59:12 UTC 2008
- Previous message (by thread): rpms/util-vserver/devel util-vserver.spec,1.37,1.38
- Next message (by thread): fedora-vote fedora-vote.conf, NONE, 1.1 castvote.cgi, 1.13, 1.14 newelection.py, 1.9, 1.10 vote.cgi, 1.11, 1.12 voting.py, 1.12, 1.13 votingadmin.py, 1.8, 1.9
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Author: toshio
Update of /cvs/fedora/fedora-vote
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv21228
Modified Files:
castvote.cgi newelection.py vote.cgi voting.py votingadmin.py
Log Message:
Ricky's changes to enable FAS2.
Index: castvote.cgi
===================================================================
RCS file: /cvs/fedora/fedora-vote/castvote.cgi,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- castvote.cgi 15 Dec 2007 00:11:27 -0000 1.12
+++ castvote.cgi 20 Apr 2008 23:58:49 -0000 1.13
@@ -24,6 +24,8 @@
import voting
import votingadmin
+from fedora.accounts.fas2 import AccountSystem
+
electionName = 'Fedora Documentation Steering Committee December 2007'
def make_thank_you(electionName, receipt):
@@ -39,15 +41,20 @@
form = cgi.FieldStorage()
dbh = website.get_dbh()
- username, password = website.get_auth(dbh, form)
+ username = os.environ['REMOTE_USER']
+
+ # TODO: fill in fas_username/fas_password
+ fas_username = ''
+ fas_password = ''
+
+ fas = AccountSystem('http://admin.fedoraproject.org/accounts/', fas_username, fas_password)
+
content = ''
pageTitle = 'Vote for %s Submitted' % electionName
website.print_header(pageTitle, username)
- website.handle_auth(username, password, form, 'castvote.cgi',
- title=pageTitle, require_auth = True)
try:
- election = votingadmin.ElectionAdmin(dbh=dbh, commonName=electionName)
+ election = votingadmin.ElectionAdmin(dbh=dbh, fas=fas, commonName=electionName)
except (voting.VotingError, pgdb.Error), e:
website.send_email(voting.sendAs, voting.sendErrorsTo, 'Voting Error',
'''The Fedora Voting Application failed to retrieve information
Index: newelection.py
===================================================================
RCS file: /cvs/fedora/fedora-vote/newelection.py,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- newelection.py 15 Dec 2007 00:11:27 -0000 1.8
+++ newelection.py 20 Apr 2008 23:58:50 -0000 1.9
@@ -9,6 +9,7 @@
import pgdb
import website
+from fedora.accounts.fas2 import AccountSystem
dbName = 'elections'
dbHost = 'db2.fedora.phx.redhat.com'
@@ -41,15 +42,24 @@
# Establish the connection to the elections database
dbPass = getpass.getpass('Enter the database password: ')
db = pgdb.connect(database=dbName, host=dbHost, user=dbUser, password=dbPass)
+
+username = raw_input('FAS Username: ')
+password = getpass.getpass('FAS Password: ')
+
+try:
+ fas = AccountSystem('http://localhost:8088/accounts/', username, password)
+except AuthError:
+ print "Invalid username/password."
+ sys.exit(1)
+
dbCmd = db.cursor()
dbh = website.get_dbh()
print "Check that these are the candidates you were expecting"
for cand in candidates:
- id = website.get_user_id(dbh, cand)
- candidateUserInfo = website.get_user_info(dbh, id)
- print "%s -- Id: %s" % (candidateUserInfo['human_name'], id)
- candList.append(id)
+ person = fas.person_by_username(cand)
+ print "%s -- Id: %s" % (person['human_name'], person['id'])
+ candList.append(person['id'])
print "Were those the correct candidates? (y/n)"
letter = sys.stdin.readline()
@@ -58,10 +68,9 @@
print "Check that these are the groups you want to vote in this election"
for group in votingGroups:
- gid = website.get_group_id(dbh, group)
- gname = website.get_group_name(dbh, gid)
- print '%s -- %s' % (gname, gid)
- groupList.append(gid)
+ gid = fas.group_by_name(group)
+ print '%s -- %s' % (group['name'], group['id'])
+ groupList.append(group['id'])
print "Were those the correct groups? (y/n)"
letter = sys.stdin.readline()
Index: vote.cgi
===================================================================
RCS file: /cvs/fedora/fedora-vote/vote.cgi,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- vote.cgi 15 Dec 2007 00:11:27 -0000 1.10
+++ vote.cgi 20 Apr 2008 23:58:51 -0000 1.11
@@ -88,19 +88,23 @@
form = cgi.FieldStorage()
dbh = website.get_dbh()
+ username = os.environ['REMOTE_USER']
+
+ # TODO: fill in fas_username/fas_password
+ fas_username = ''
+ fas_password = ''
+
+ fas = AccountSystem('https://admin.fedoraproject.org/accounts/', fas_username, fas_password)
- auth_username, auth_password = website.get_auth(dbh, form)
content = ''
pageTitle = 'Ballot for %s Election' % electionName
- website.print_header(pageTitle, auth_username)
- website.handle_auth(auth_username, auth_password, form, 'vote.cgi',
- title=pageTitle, require_auth = True)
+ website.print_header(pageTitle, username)
try:
- election = voting.Election(dbh=dbh, commonName=electionName)
- authorized = election.authorize_user(auth_username)
+ election = voting.Election(dbh=dbh, fas=fas, commonName=electionName)
+ authorized = election.authorize_user(username)
occurs = election.occurring()
- alreadyCast = election.already_cast_vote(auth_username)
+ alreadyCast = election.already_cast_vote(username)
candidates = election.get_candidates()
openSeats = election.votes_to_allocate()
except (voting.VotingError, pgdb.Error), e:
@@ -108,7 +112,7 @@
'''The Fedora Voting Application failed to pull information
from the database in order to register a vote for %s during the %s Election.
The error occurred in vote.cgi. The error was: %s'''
- % (auth_username, electionName, str(e)))
+ % (username, electionName, str(e)))
content = '<p class="error">Failed to get information on the election' \
' from the database. An email has been sent to the voting' \
' administrators. Please try to vote again later.</p>'
Index: voting.py
===================================================================
RCS file: /cvs/fedora/fedora-vote/voting.py,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- voting.py 3 Oct 2006 00:51:51 -0000 1.11
+++ voting.py 20 Apr 2008 23:58:51 -0000 1.12
@@ -23,10 +23,11 @@
class Election(object):
electionDB = 'elections'
- def __init__(self, dbh, commonName):
+ def __init__(self, dbh, fas, commonName):
'''Initialize the election with the database backend.'''
self.commonName = commonName
self.dbh = dbh
+ self.fas = fas
self.db = website.get_dbh(self.electionDB)
self.dbCmd = self.db.cursor()
self.dbCmd.execute("select id from election"
@@ -51,14 +52,17 @@
self.votingGroups.append(group[0])
# Get user_id from accounts
- userId = website.get_user_id(self.dbh, user)
- if not userId:
- raise VotingError, 'Could not retrieve userId from the accounts' \
- ' db for %s' % user
+ person = self.fas.person_by_username(username)
+ if not person:
+ raise VotingError, 'Unable to find voter %s in the accounts db' % \
+ username
+ else:
+ userId = person['id']
# Ask the accounts db if user belongs to that group.
- for group in self.votingGroups:
- if (website.have_group(self.dbh, userId, group)):
+ for groupid in self.votingGroups:
+ group = self.fas.group_by_id(groupid)
+ if (group in person.approved_memberships):
return True
return False
@@ -104,7 +108,7 @@
raise VotingError, 'No candidates listed for election %s' % \
self.electionId
for candidate in candidates:
- candInfo = website.get_user_info(self.dbh, candidate[0])
+ candInfo = self.fas.person_by_id(candidate[0])
if not candInfo:
raise VotingError, 'Candidate %s not in the accounts db' % \
candidate[0]
@@ -131,10 +135,12 @@
def already_cast_vote(self, username):
'''Check if a user has already submitted a ballot.'''
# Get user_id from accounts
- userId = website.get_user_id(self.dbh, username)
- if not userId:
- raise VotingError, 'Could not retrieve userId for %s from the' \
- ' accounts db' % username
+ person = self.fas.person_by_username(username)
+ if not person:
+ raise VotingError, 'Unable to find voter %s in the accounts db' % \
+ username
+ else:
+ userId = person['id']
# Ask the voting db whether the userId has already voted
self.dbCmd.execute("select id from ballots where voter = '%s' and election_id = '%s'" % (userId, self.electionId))
Index: votingadmin.py
===================================================================
RCS file: /cvs/fedora/fedora-vote/votingadmin.py,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- votingadmin.py 15 Dec 2007 00:11:27 -0000 1.7
+++ votingadmin.py 20 Apr 2008 23:58:51 -0000 1.8
@@ -13,10 +13,11 @@
'''
'''
from voting import *
+from fedora.accounts.fas2 import AccountSystem
class ElectionAdmin(Election):
- def __init__(self, dbh, commonName):
- Election.__init__(self, dbh, commonName)
+ def __init__(self, dbh, fas, commonName):
+ Election.__init__(self, dbh, fas, commonName)
# If we need to customize the read-write interface (different user and
# password or some such, do it here.)
@@ -65,10 +66,12 @@
raise VotingError, 'Election is not in progress'
# Enter the ballot information into the database
- userId = website.get_user_id(self.dbh, username)
- if not userId:
+ person = self.fas.person_by_username(username)
+ if not person:
raise VotingError, 'Unable to find voter %s in the accounts db' % \
- userId
+ username
+ else:
+ userId = person['id']
self.dbCmd.execute('insert into ballots (voter, election_id)'
" values('%s', '%s')" % (userId, self.electionId))
- Previous message (by thread): rpms/util-vserver/devel util-vserver.spec,1.37,1.38
- Next message (by thread): fedora-vote fedora-vote.conf, NONE, 1.1 castvote.cgi, 1.13, 1.14 newelection.py, 1.9, 1.10 vote.cgi, 1.11, 1.12 voting.py, 1.12, 1.13 votingadmin.py, 1.8, 1.9
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the fedora-extras-commits
mailing list