def sync(self): try: for ldap_group, dest_group in self.SYNC_PAIRS: ldap_members = set(list_staff(group=ldap_group)) dest_members = set( self.dest_service().list_members(dest_group)) to_add = ldap_members - dest_members missing = dest_members - ldap_members if missing: missing_header = '''The following users are in the {dest} destination group but are not in the {ldap} LDAP group:'''.format(dest=dest_group, ldap=ldap_group) self.logger.warning(missing_header) for m in missing: self.logger.warning(m) for username in to_add: if not self.args.dry_run: self.dest_service().add_to_group(username, dest_group) self.logger.info('Adding {} to group {}'.format( username, dest_group)) except Exception as e: self.logger.exception('Exception caught: {}'.format(e)) if not self.args.dry_run: mail.send_problem_report( 'An exception occurred in ldapsync: \n\n{}'.format(e))
def update_staff(): staff = list_staff() cnx = db.get_connection() cursor = cnx.cursor() cursor.execute('DELETE FROM `staff`') for user in staff: cursor.execute('INSERT INTO `staff` (`user`) VALUES (%s)', (user,)) cnx.commit()
def update_staff(): staff = list(list_staff()) + ['pubstaff'] cnx = db.get_connection() cursor = cnx.cursor() cursor.execute('DELETE FROM `staff`') for user in staff: cursor.execute('INSERT INTO `staff` (`user`) VALUES (%s)', (user, )) cnx.commit()
def test_list_staff(): staff = list_staff() assert 'ckuehl' in staff assert 'bpreview' not in staff assert 5 <= len(staff) <= 125
import flask from flask import Flask, render_template, redirect from ocflib.account.utils import list_staff import utils app = Flask(__name__) staff = list_staff() @app.route('/') def root(): return redirect('/graph/slobo/') @app.route('/graph/<user>/') def chart_for_user(user): return render_template('timeseries.html', user=user, staff=staff) # -------------------------------------------------- @app.route('/<user>/data/logins_over_time/') def data_for_user(user): return flask.json.jsonify(utils.get_data(user)) @app.route('/staff_members/') def get_staff(): return flask.json.jsonify(staff)
def test_list_staff(): staff = list_staff() assert 'ckuehl' in staff assert 'bpreview' not in staff assert 5 <= len(staff) <= 50