Merge branch 'master' of ssh://git.fedorahosted.org/git/fedora-infrastructure

(removed some old seqs)

Conflicts:

	fas/fas2.sql
This commit is contained in:
Ricky Zhou (周家杰) 2008-03-11 20:02:13 -04:00
commit cf3b40d232
2 changed files with 235 additions and 241 deletions

View file

@ -436,7 +436,7 @@ class MakeShellAccounts(BaseClient):
def create_ssh_keys(self): def create_ssh_keys(self):
''' Create ssh keys ''' ''' Create ssh keys '''
home_base = config.get('users', 'home').strip('"') home_base = prefix + config.get('users', 'home').strip('"')
for person in self.people: for person in self.people:
username = person['username'] username = person['username']
if self.valid_user(username): if self.valid_user(username):

View file

@ -231,244 +231,244 @@ create table visit_identity (
-- --
-- When a person's fedorabugs role is updated, add them to bugzilla queue. -- When a person's fedorabugs role is updated, add them to bugzilla queue.
-- --
create or replace function bugzilla_sync() returns trigger as $bz_sync$ -- create or replace function bugzilla_sync() returns trigger as $bz_sync$
# Decide which row we are operating on and the action to take -- # Decide which row we are operating on and the action to take
if TD['event'] == 'DELETE': -- if TD['event'] == 'DELETE':
# 'r' for removing an entry from bugzilla -- # 'r' for removing an entry from bugzilla
newaction = 'r' -- newaction = 'r'
row = TD['old'] -- row = TD['old']
else: -- else:
# insert or update -- # insert or update
row = TD['new'] -- row = TD['new']
if row['role_status'] == 'approved': -- if row['role_status'] == 'approved':
# approved so add an entry to bugzilla -- # approved so add an entry to bugzilla
newaction = 'a' -- newaction = 'a'
else: -- else:
# no longer approved so remove the entry from bugzilla -- # no longer approved so remove the entry from bugzilla
newaction = 'r' -- newaction = 'r'
--
# Get the group id for fedorabugs -- # Get the group id for fedorabugs
result = plpy.execute("select id from groups where name = 'fedorabugs'", 1) -- result = plpy.execute("select id from groups where name = 'fedorabugs'", 1)
if not result: -- if not result:
# Danger Will Robinson! A basic FAS group does not exist! -- # Danger Will Robinson! A basic FAS group does not exist!
plpy.error('Basic FAS group fedorabugs does not exist') -- plpy.error('Basic FAS group fedorabugs does not exist')
# If this is not a fedorabugs role, no change needed -- # If this is not a fedorabugs role, no change needed
if row['group_id'] != result[0]['id']: -- if row['group_id'] != result[0]['id']:
return None -- return None
--
# Retrieve the bugzilla email address -- # Retrieve the bugzilla email address
plan = plpy.prepare("select email, purpose from person_emails as pem," -- plan = plpy.prepare("select email, purpose from person_emails as pem,"
" email_purposes as epu" -- " email_purposes as epu"
" where pem.id = epu.email_id and pem.person_id = $1" -- " where pem.id = epu.email_id and pem.person_id = $1"
" and epu.purpose in ('bugzilla', 'primary')", -- " and epu.purpose in ('bugzilla', 'primary')",
('int4',)) -- ('int4',))
result = plpy.execute(plan, (row['person_id'],)) -- result = plpy.execute(plan, (row['person_id'],))
email = None -- email = None
for record in result: -- for record in result:
email = record['email'] -- email = record['email']
if record['purpose'] == 'bugzilla': -- if record['purpose'] == 'bugzilla':
break -- break
if not email: -- if not email:
raise plpy.error('Cannot approve fedorabugs for person_id(%s) because they have no email address to use with bugzilla' % row['person_id']) -- raise plpy.error('Cannot approve fedorabugs for person_id(%s) because they have no email address to use with bugzilla' % row['person_id'])
--
# If there is already a row in bugzilla_queue update, otherwise insert -- # If there is already a row in bugzilla_queue update, otherwise insert
plan = plpy.prepare("select email from bugzilla_queue where email = $1", -- plan = plpy.prepare("select email from bugzilla_queue where email = $1",
('text',)) -- ('text',))
result = plpy.execute(plan, (email,), 1) -- result = plpy.execute(plan, (email,), 1)
if result: -- if result:
plan = plpy.prepare("update bugzilla_queue set action = $1" -- plan = plpy.prepare("update bugzilla_queue set action = $1"
" where email = $2", ('char', 'text')) -- " where email = $2", ('char', 'text'))
plpy.execute(plan, (newaction, email)) -- plpy.execute(plan, (newaction, email))
else: -- else:
plan = plpy.prepare("insert into bugzilla_queue (email, group_id" -- plan = plpy.prepare("insert into bugzilla_queue (email, group_id"
", person_id, action) values ($1, $2, $3, $4)", -- ", person_id, action) values ($1, $2, $3, $4)",
('text', 'int4', 'int4', 'char')) -- ('text', 'int4', 'int4', 'char'))
plpy.execute(plan, (email, row['group_id'], row['person_id'], newaction)) -- plpy.execute(plan, (email, row['group_id'], row['person_id'], newaction))
return None -- return None
$bz_sync$ language plpythonu; -- $bz_sync$ language plpythonu;
--
create trigger role_bugzilla_sync before update or insert or delete -- create trigger role_bugzilla_sync before update or insert or delete
on person_roles -- on person_roles
for each row execute procedure bugzilla_sync(); -- for each row execute procedure bugzilla_sync();
-- --
-- When an email address changes, check whether it needs to be changed in -- When an email address changes, check whether it needs to be changed in
-- bugzilla as well. -- bugzilla as well.
-- --
create or replace function bugzilla_sync_email() returns trigger AS $bz_sync_e$ -- create or replace function bugzilla_sync_email() returns trigger AS $bz_sync_e$
def is_member(group_id, person_id): -- def is_member(group_id, person_id):
'''Return true if the given id is a member of fedorabugs.''' -- '''Return true if the given id is a member of fedorabugs.'''
plan = plpy.prepare("select * from people as p, person_roles as r" -- plan = plpy.prepare("select * from people as p, person_roles as r"
" where p.id = r.person_id and r.group_id = $1" -- " where p.id = r.person_id and r.group_id = $1"
" and r.role_status = 'approved' and p.id = $2", -- " and r.role_status = 'approved' and p.id = $2",
('int4', 'int4',)) -- ('int4', 'int4',))
result = plpy.execute(plan, (group_id, person_id), 1) -- result = plpy.execute(plan, (group_id, person_id), 1)
if result: -- if result:
return True -- return True
else: -- else:
return False -- return False
--
def affects_bz(email_id, person_id, verified): -- def affects_bz(email_id, person_id, verified):
'''Check whether the given email address can affect bugzilla.''' -- '''Check whether the given email address can affect bugzilla.'''
if not verified: -- if not verified:
return False -- return False
emailAffectsBz = False -- emailAffectsBz = False
possible = False -- possible = False
plan = plpy.prepare("select purpose from email_purposes where" -- plan = plpy.prepare("select purpose from email_purposes where"
" email_id = $1", ('int4',)) -- " email_id = $1", ('int4',))
result = plpy.execute(plan, (email_id,)) -- result = plpy.execute(plan, (email_id,))
for record in result: -- for record in result:
if record['purpose'] == 'bugzilla': -- if record['purpose'] == 'bugzilla':
emailAffectsBz = True -- emailAffectsBz = True
break -- break
if record['purpose'] == 'primary': -- if record['purpose'] == 'primary':
possible = True -- possible = True
--
if not emailAffectsBz and possible: -- if not emailAffectsBz and possible:
# If it's primary, we have to check that the user doesn't have a -- # If it's primary, we have to check that the user doesn't have a
# different email setup for bugzilla -- # different email setup for bugzilla
plan = plpy.prepare("select purpose from email_purposes where" -- plan = plpy.prepare("select purpose from email_purposes where"
" person_id = $1 and purpose = 'bugzilla'", ('int4',)) -- " person_id = $1 and purpose = 'bugzilla'", ('int4',))
result = plpy.execute(plan, (person_id,), 1) -- result = plpy.execute(plan, (person_id,), 1)
if not result: -- if not result:
# A separate bugzilla email address does not exist -- # A separate bugzilla email address does not exist
emailAffectsBz = True -- emailAffectsBz = True
return emailAffectsBz -- return emailAffectsBz
--
def previous_emails(person_id): -- def previous_emails(person_id):
'''Find the previous email used for bugzilla.''' -- '''Find the previous email used for bugzilla.'''
plan = plpy.prepare("select email, purpose from person_emails as pem," -- plan = plpy.prepare("select email, purpose from person_emails as pem,"
" email_purposes as epu" -- " email_purposes as epu"
" where pem.id = epu.email_id and pem.person_id = $1" -- " where pem.id = epu.email_id and pem.person_id = $1"
" and epu.purpose in ('bugzilla', 'primary')", ('int4',)) -- " and epu.purpose in ('bugzilla', 'primary')", ('int4',))
result = plpy.execute(plan, (TD['new']['person_id'],)) -- result = plpy.execute(plan, (TD['new']['person_id'],))
email = None -- email = None
return result -- return result
--
# -- #
# Main body of function starts here -- # Main body of function starts here
# -- #
--
# Store the changes we need to make in this list -- # Store the changes we need to make in this list
changes = {} -- changes = {}
--
# Get the group id for fedorabugs -- # Get the group id for fedorabugs
result = plpy.execute("select id from groups where name = 'fedorabugs'", 1) -- result = plpy.execute("select id from groups where name = 'fedorabugs'", 1)
if not result: -- if not result:
# Danger Will Robinson! A basic FAS group does not exist! -- # Danger Will Robinson! A basic FAS group does not exist!
plpy.error('Basic FAS group fedorabugs does not exist') -- plpy.error('Basic FAS group fedorabugs does not exist')
fedorabugsId = result[0]['id'] -- fedorabugsId = result[0]['id']
--
# Check whether the new person belongs to fedorabugs -- # Check whether the new person belongs to fedorabugs
newHasBugs = is_member(fedorabugsId, TD['new']['person_id']) -- newHasBugs = is_member(fedorabugsId, TD['new']['person_id'])
oldHasBugs = is_member(fedorabugsId, TD['old']['person_id']) -- oldHasBugs = is_member(fedorabugsId, TD['old']['person_id'])
--
newAffectsBz = affects_bz(TD['new']['id'], TD['new']['person_id'], -- newAffectsBz = affects_bz(TD['new']['id'], TD['new']['person_id'],
TD['new']['verified']) -- TD['new']['verified'])
oldAffectsBz = affects_bz(TD['old']['id'], TD['old']['person_id'], -- oldAffectsBz = affects_bz(TD['old']['id'], TD['old']['person_id'],
TD['old']['verified']) -- TD['old']['verified'])
--
# Note: When setting the changes that we're going to make in -- # Note: When setting the changes that we're going to make in
# bugzilla_queue here are the rules we follow: -- # bugzilla_queue here are the rules we follow:
# For each email address: -- # For each email address:
# If we have multiple adds, condense to one. -- # If we have multiple adds, condense to one.
# If we have multiple deletes, condense to one. -- # If we have multiple deletes, condense to one.
# If we have an add and a delete, the delete wins. -- # If we have an add and a delete, the delete wins.
--
if TD['new']['email'] != TD['old']['email']: -- if TD['new']['email'] != TD['old']['email']:
# The email address has changed. Add the new one and remove the old -- # The email address has changed. Add the new one and remove the old
# if they affect bugzilla -- # if they affect bugzilla
if newHasBugs and newAffectsBz: -- if newHasBugs and newAffectsBz:
# Add the new email -- # Add the new email
if not TD['new']['email'] in changes: -- if not TD['new']['email'] in changes:
changes[TD['new']['email']] = (TD['new']['email'], fedorabugsId, TD['new']['person_id'], 'a') -- changes[TD['new']['email']] = (TD['new']['email'], fedorabugsId, TD['new']['person_id'], 'a')
if oldHasBugs and oldAffectsBz: -- if oldHasBugs and oldAffectsBz:
# Remove the old email -- # Remove the old email
changes[TD['old']['email']] = (TD['old']['email'], fedorabugsId, TD['old']['person_id'], 'r') -- changes[TD['old']['email']] = (TD['old']['email'], fedorabugsId, TD['old']['person_id'], 'r')
--
if TD['new']['person_id'] != TD['old']['person_id']: -- if TD['new']['person_id'] != TD['old']['person_id']:
# Email changed owners. If one owner has fedorabugs and the other -- # Email changed owners. If one owner has fedorabugs and the other
# does not we have to adjust. -- # does not we have to adjust.
if newHasBugs and newAffectsBz and not oldHasBugs: -- if newHasBugs and newAffectsBz and not oldHasBugs:
# Add the email address -- # Add the email address
if not TD['new']['email'] in changes: -- if not TD['new']['email'] in changes:
changes[TD['new']['email']] = (TD['new']['email'], fedorabugsId, TD['new']['person_id'], 'a') -- changes[TD['new']['email']] = (TD['new']['email'], fedorabugsId, TD['new']['person_id'], 'a')
if oldHasBugs and oldAffectsBz and not newHasBugs: -- if oldHasBugs and oldAffectsBz and not newHasBugs:
# Remove the email address -- # Remove the email address
changes[TD['old']['email']] = (TD['old']['email'], fedorabugsId, TD['old']['person_id'], 'r') -- changes[TD['old']['email']] = (TD['old']['email'], fedorabugsId, TD['old']['person_id'], 'r')
--
# If both have fedorabugs, we need to decide which of the addresses to -- # If both have fedorabugs, we need to decide which of the addresses to
# use with bugzilla. -- # use with bugzilla.
if oldHasBugs and newHasBugs and newAffectsBz: -- if oldHasBugs and newHasBugs and newAffectsBz:
# Retrieve the bugzilla email address -- # Retrieve the bugzilla email address
previous = previous_emails(TD['new']['person_id']) -- previous = previous_emails(TD['new']['person_id'])
--
# Note: we depend on the unique constraint having already run and -- # Note: we depend on the unique constraint having already run and
# stopped us from getting to this point with two email addresses -- # stopped us from getting to this point with two email addresses
# for the same purpose. -- # for the same purpose.
# Since only one can be the bzEmail address and only one the -- # Since only one can be the bzEmail address and only one the
# primary, we can do what we need only knowing the purpose for one -- # primary, we can do what we need only knowing the purpose for one
# of the email addresses. -- # of the email addresses.
if previous: -- if previous:
--
for email in previous: -- for email in previous:
if email['purpose'] == 'bugzilla': -- if email['purpose'] == 'bugzilla':
# Remove the new email address as the old one is the bz email -- # Remove the new email address as the old one is the bz email
changes[TD['new']['email']] = (TD['new']['email'], fedorabugsId, TD['new']['person_id'], 'r') -- changes[TD['new']['email']] = (TD['new']['email'], fedorabugsId, TD['new']['person_id'], 'r')
else: -- else:
# Remove the current email address -- # Remove the current email address
changes[email] = (email, fedorabugsId, TD['new']['person_id'], 'r') -- changes[email] = (email, fedorabugsId, TD['new']['person_id'], 'r')
--
if TD['new']['verified'] != TD['old']['verified']: -- if TD['new']['verified'] != TD['old']['verified']:
plpy.execute("insert into debug values ('In verified')") -- plpy.execute("insert into debug values ('In verified')")
if TD['new']['verified'] and newHasBugs and newAffectsBz: -- if TD['new']['verified'] and newHasBugs and newAffectsBz:
# Add the email address -- # Add the email address
plpy.execute("insert into debug values('Add email address')") -- plpy.execute("insert into debug values('Add email address')")
if not TD['new']['email'] in changes: -- if not TD['new']['email'] in changes:
plpy.execute("insert into debug values ('addind address for real')") -- plpy.execute("insert into debug values ('addind address for real')")
changes[TD['new']['email']] = (TD['new']['email'], fedorabugsId, TD['new']['person_id'], 'a') -- changes[TD['new']['email']] = (TD['new']['email'], fedorabugsId, TD['new']['person_id'], 'a')
# Check whether there's a previous email address this -- # Check whether there's a previous email address this
# obsoletes -- # obsoletes
previous = previous_email(TD['new']['person_id']) -- previous = previous_email(TD['new']['person_id'])
plan = plpy.prepare("insert into debug values ($1)", ('text',)) -- plan = plpy.prepare("insert into debug values ($1)", ('text',))
plpy.execute(plan, (str(previous),)) -- plpy.execute(plan, (str(previous),))
if previous and previous[0] == 'primary': -- if previous and previous[0] == 'primary':
changes[previous[1]] = (previous[1], fedorabugsId, TD['new']['person_id'], 'r') -- changes[previous[1]] = (previous[1], fedorabugsId, TD['new']['person_id'], 'r')
elif not TD['new']['verified'] and oldHasBugs and oldAffectsBz: -- elif not TD['new']['verified'] and oldHasBugs and oldAffectsBz:
# Remove the email address -- # Remove the email address
changes[TD['old']['email']] = (TD['old']['email'], fedorabugsId, TD['old']['person_id'], 'r') -- changes[TD['old']['email']] = (TD['old']['email'], fedorabugsId, TD['old']['person_id'], 'r')
# Check if there's another email address that should take it's -- # Check if there's another email address that should take it's
# place -- # place
previous = previous_email(TD['new']['person_id']) -- previous = previous_email(TD['new']['person_id'])
if previous and not pervious[1] in changes: -- if previous and not pervious[1] in changes:
changes[previous[1]] = (previous[1], fedorabugsId, TD['new']['person_id'], 'a') -- changes[previous[1]] = (previous[1], fedorabugsId, TD['new']['person_id'], 'a')
--
# Now actually add the changes to the queue. -- # Now actually add the changes to the queue.
plan = plpy.prepare("insert into debug values ($1)", ('text',)) -- plan = plpy.prepare("insert into debug values ($1)", ('text',))
plpy.execute(plan, (str(changes),)) -- plpy.execute(plan, (str(changes),))
for email in changes: -- for email in changes:
plan = plpy.prepare("select email from bugzilla_queue where email = $1", ('text',)) -- plan = plpy.prepare("select email from bugzilla_queue where email = $1", ('text',))
result = plpy.execute(plan, (email,), 1) -- result = plpy.execute(plan, (email,), 1)
if result: -- if result:
# Update another record with the new information -- # Update another record with the new information
plan = plpy.prepare("update bugzilla_queue set email = $1," -- plan = plpy.prepare("update bugzilla_queue set email = $1,"
" group_id = $2, person_id = $3, action = $4" -- " group_id = $2, person_id = $3, action = $4"
" where email = $5", ('text', 'int4', 'int4', 'char', 'text')) -- " where email = $5", ('text', 'int4', 'int4', 'char', 'text'))
params = list(changes[email]) -- params = list(changes[email])
params.append(email) -- params.append(email)
plpy.execute(plan, params) -- plpy.execute(plan, params)
else: -- else:
# Add a brand new record -- # Add a brand new record
plan = plpy.prepare("insert into bugzilla_queue" -- plan = plpy.prepare("insert into bugzilla_queue"
" (email, group_id, person_id, action) values" -- " (email, group_id, person_id, action) values"
" ($1, $2, $3, $4)", ('text', 'int4', 'int4', 'char')) -- " ($1, $2, $3, $4)", ('text', 'int4', 'int4', 'char'))
plpy.execute(plan, changes[email]) -- plpy.execute(plan, changes[email])
return None -- return None
$bz_sync_e$ language plpythonu; -- $bz_sync_e$ language plpythonu;
--
create trigger email_bugzilla_sync before update -- create trigger email_bugzilla_sync before update
on person_emails -- on person_emails
for each row execute procedure bugzilla_sync_email(); -- for each row execute procedure bugzilla_sync_email();
-- We have to fix this. Luckily, the purpose is usually primary. -- We have to fix this. Luckily, the purpose is usually primary.
-- create or replace function bugzilla_sync_purpose() returns trigger AS -- create or replace function bugzilla_sync_purpose() returns trigger AS
@ -581,10 +581,8 @@ create trigger email_bugzilla_sync before update
-- For Fas to connect to the database -- For Fas to connect to the database
GRANT ALL ON TABLE people, groups, person_roles, group_roles, bugzilla_queue, configs, person_seq, visit, visit_identity, log, log_id_seq, TO GROUP fedora; GRANT ALL ON TABLE people, groups, person_roles, group_roles, bugzilla_queue, configs, person_seq, visit, visit_identity, log, log_id_seq, TO GROUP fedora;
-- Create default admin user - Default Password "admin" -- Create default admin user - Default Password "admin"
INSERT INTO people (id, username, human_name, password) VALUES (100001, 'admin', 'Admin User', '$1$djFfnacd$b6NFqFlac743Lb4sKWXj4/'); INSERT INTO people (id, username, human_name, password, email) VALUES (100001, 'admin', 'Admin User', '$1$djFfnacd$b6NFqFlac743Lb4sKWXj4/', 'root@localhost');
-- Create default groups and populate -- Create default groups and populate
INSERT INTO groups (id, name, display_name, owner_id, group_type) VALUES (100002, 'cla_sign', 'Signed CLA Group', (SELECT id from people where username='admin'), 'tracking'); INSERT INTO groups (id, name, display_name, owner_id, group_type) VALUES (100002, 'cla_sign', 'Signed CLA Group', (SELECT id from people where username='admin'), 'tracking');
@ -595,7 +593,3 @@ INSERT INTO groups (name, display_name, owner_id, group_type) VALUES ('fas-syste
INSERT INTO person_roles (person_id, group_id, role_type, role_status, internal_comments, sponsor_id) VALUES ((SELECT id from people where username='admin'), (select id from groups where name='accounts'), 'administrator', 'approved', 'created at install time', (SELECT id from people where username='admin')); INSERT INTO person_roles (person_id, group_id, role_type, role_status, internal_comments, sponsor_id) VALUES ((SELECT id from people where username='admin'), (select id from groups where name='accounts'), 'administrator', 'approved', 'created at install time', (SELECT id from people where username='admin'));
-- Give admin user his email address
INSERT INTO person_emails (email, person_id, verified) VALUES ('root@localhost', (SELECT id from people where username='admin'), true);
INSERT INTO email_purposes (email_id, person_id, purpose) VALUES ((SELECT id from person_emails where email='root@localhost'), (SELECT id from people where username='admin'), 'primary');