def edit_role(argv): c_name = cfg.ROLES if len(argv) != 1: usage_create_role() return False role_name = argv[0] if not dataset.key_exists(c_name, role_name): print(f'{role_name} does not exist in {c_name}') return False role, err = dataset.read(c_name, role_name) if err != '': print(f'ERROR: {err}') return False for c_name in [cfg.USERS, cfg.ROLES, cfg.OBJECTS]: print(f'Collection {c_name}') perms = role[c_name] for perm in ['create', 'read', 'update', 'delete']: val = role[c_name][perm] t_or_f = input(f'{perm} is {val}, T(rue)/F(alse)/K(eep)? ').lower() if t_or_f in ['t', 'true']: role[c_name][perm] = True if t_or_f in ['f', 'false']: role[c_name][perm] = False c_name = cfg.ROLES err = dataset.update(c_name, role_name, role) if err != '': print(f'ERROR: {err}') return False return True
def load(self, cl_people_id): c_name = cfg.OBJECTS if dataset.key_exists(c_name, cl_people_id): u, err = dataset.read(c_name, cl_people_id) if err != '': return err self.cl_people_id = u['cl_people_id'] if 'cl_people_id' in u else '' self.family_name = u['family_name'] if 'family_name' in u else '' self.given_name = u['given_name'] if 'given_name' in u else '' self.thesis_id = u['thesis_id'] if 'thesis_id' in u else '' self.authors_id = u['authors_id'] if 'authors_id' in u else '' self.archivesspace_id = u[ 'archivesspace_id'] if 'archivesspace_id' in u else '' self.directory_id = u['directory_id'] if 'directory_id' in u else '' self.viaf = u['viaf'] if 'viaf' in u else '' self.lcnaf = u['lcnaf'] if 'lcnaf' in u else '' self.isni = u['isni'] if 'isni' in u else '' self.wikidata = u['wikidata'] if 'wikidata' in u else '' self.snac = u['snac'] if 'snac' in u else '' self.orcid = u['orcid'] if 'orcid' in u else '' self.image = u['image'] if 'image' in u else '' self.educated_at = u['educated_at'] if 'educated_at' in u else '' self.caltech = u['caltech'] if 'caltech' in u else False self.jpl = u['jpl'] if 'jpl' in u else False self.faculty = u['faculty'] if 'faculty' in u else False self.alumn = u['alumn'] if 'alumn' in u else False self.notes = u['notes'] if 'notes' in u else '' return ''
def get(self, role_name): if dataset.key_exists(self.c_name, role_name) == False: return False role, err = dataset.read(self.c_name, role_name) if err != '': return False self.role_name = role['role_name'] self.objects = role['objects'] self.roles = roles['roles'] self.users = roles['users'] return True
def save(self): c_name = self.c_name key = self.username if dataset.key_exists(c_name, key): err = dataset.update(c_name, key, self) if err != '': return False else: err = dataset.create(c_name, key, self) if err != '': return False return True
def delete_role(argv): c_name = cfg.ROLES if len(argv) != 1: usage_delete_role() return False role_name = argv[0] if dataset.key_exists(c_name, role_name): err = dataset.delete(c_name, role_name) if err != '': return False return True print(f'{role_name} not found in {c_name}') return False
def set_display_name(argv): c_name = cfg.USERS if len(argv) != 2: return usage_set_email() username, display_name = argv[0], argv[1] if dataset.key_exists(c_name, username) == True: u = models.User(c_name) if u.get(username): u.display_name = display_name return u.save() return True print(f'{username} does not exist in {c_name}') return False
def disable_user(argv): c_name = cfg.USERS if len(argv) != 1: usage_disable_user() return False username = argv[0] if dataset.key_exists(c_name, username) == False: print(f'{username} not found in {c_name}') return False u = models.User(c_name) if u.get(username) == False: print(f'{username} not found in {c_name}') return False u.is_active = False return u.save()
def people_new(): if current_user.is_authenticated == False: flash(f'Must be logged in to curate people') return redirect(url_for('index')) form = PeopleForm() if form.validate_on_submit(): people = People() people.cl_people_id = form.cl_people_id.data people.family_name = form.family_name.data people.given_name = form.given_name.data people.thesis_id = form.thesis_id.data people.authors_id = form.authors_id.data people.archivesspace_id = form.archivesspace_id.data people.directory_id = form.directory_id.data people.viaf = form.viaf.data people.lcnaf = form.lcnaf.data people.isni = form.isni.data people.wikidata = form.wikidata.data people.snac = form.snac.data people.orcid = form.orcid.data people.image = form.image.data people.educated_at = form.educated_at.data people.caltech = form.caltech.data people.jpl = form.jpl.data people.faculty = form.faculty.data people.alumn = form.alumn.data people.notes = form.notes.data c_name = cfg.OBJECTS key = people.cl_people_id now = datetime.now() if dataset.key_exists(c_name, key): err = dataset.update(c_name, key, people.to_dict()) if err != '': flash(f'WARNING: failed to update {key} in {c_name}, {err}') else: flash(f'{people.cl_people_id} updated {now}') else: err = dataset.create(c_name, key, people.to_dict()) if err != '': flash(f'WARNING: failed to create {key} in {c_name}, {err}') else: flash(f'{people.cl_people_id} created {now}') return redirect( url_for('people_edit', cl_people_id=people.cl_people_id)) return render_template('people_edit.html', title="New People", user=current_user, form=form)
def assign_role(argv): c_name = cfg.USERS if len(argv) != 2: return usage_asign_role() username, role = argv[0], argv[1] if dataset.key_exists(c_name, username) == False: print(f'{username} does not exist in {c_name}') return False u, err = dataset.read(c_name, username) if err != '': print(f'Failed to read {username} from {c_name}, {err}') return False u['role'] = role err = dataset.update(c_name, username, u) if err != '': print(f'Failed to write {username} to {c_name}, {err}') return False return True
def create_role(argv): c_name = cfg.ROLES if len(argv) != 1: usage_create_role() return False role_name = argv[0] if dataset.key_exists(c_name, role_name): print(f'{role_name} already exists in {c_name}') return False role = { f'{cfg.USERS}': { 'create': False, 'read': False, 'update': False, 'delete': False }, f'{cfg.ROLES}': { 'create': False, 'read': False, 'update': False, 'delete': False }, f'{cfg.OBJECTS}': { 'create': False, 'read': False, 'update': False, 'delete': False }, } for c_name in [cfg.USERS, cfg.ROLES, cfg.OBJECTS]: print(f'Collection {c_name}') perms = role[c_name] for perm in ['create', 'read', 'update', 'delete']: y_or_n = input(f'allow {perm}? [Y/n] ').lower() if y_or_n in ['y', 'yes']: role[c_name][perm] = True else: role[c_name][perm] = False c_name = cfg.ROLES err = dataset.create(c_name, role_name, role) if err != '': print(f'ERROR: {err}') return False return True
def NewUser(username, email, display_name): '''NewUser create a new user in cfg.USERS, then returns a new User().''' c_name = cfg.USERS user = { 'c_name': c_name, 'id': username, 'username': username, 'display_name': display_name, 'email': email, 'role': '', 'password': '' } if dataset.key_exists(c_name, username): return None err = dataset.create(c_name, username, user) if err != '': return None u = User(username) return u
def add_user(argv): c_name = cfg.USERS if len(argv) != 3: usage_add_user() return False username, email, display_name = argv[0], argv[1], argv[2] if dataset.key_exists(c_name, username) == True: print(f'{username} already exists in {c_name}') return False user = { 'id': username, 'username': username, 'email': email, 'display_name': display_name, } err = dataset.create(c_name, username, user) if err != '': return False print(f'NOTE: {username} will need to have a role and password set.') return True
def load_user(user_id): c_name = cfg.USERS if dataset.key_exists(c_name, user_id) == False: return None u = User(user_id) return u
"cl_people_id", "family_name", "given_name", "thesis_id", "authors_id", "archivesspace_id", "directory_id", "viaf", "lcnaf", "isni", "wikidata", "snac", "orcid", "image", "educated_at", "caltech", "jpl", "faculty", "alumn", "notes" ]: obj2[attr2] = '' for attr1 in obj1: attr2 = attr1.lower().replace(' ', '_').replace('(', '').replace( ')', '') if attr2 in [ "cl_people_id", "family_name", "given_name", "thesis_id", "authors_id", "archivesspace_id", "directory_id", "viaf", "lcnaf", "isni", "wikidata", "snac", "orcid", "image", "educated_at", "caltech", "jpl", "faculty", "alumn", "notes" ]: if attr2 in ['caltech', 'alumn', 'jpl', 'faculty']: obj2[attr2] = True if obj1[attr1] == '': obj2[attr2] = False elif obj1[attr1]: obj2[attr2] = obj1[attr1] if dataset.key_exists(c_name2, key): err = dataset.update(c_name2, key, obj2) else: err = dataset.create(c_name2, key, obj2) if err != '': print(f'WARNING: write failed, {key} in {c_name2}, {err}')