예제 #1
0
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
예제 #2
0
def set_password(argv):
    c_name = cfg.USERS
    if len(argv) < 1:
        return usage_password()
    username = argv[0]
    pw1, pw2 = '', ' '
    i = 0
    while pw1 != pw2:
        pw1 = getpass.getpass(
            prompt=f'Please enter a new password for {username}: ')
        pw2 = getpass.getpass(
            prompt=f'Please enter the password a second time: ')
        if pw1 != pw2:
            i += 1
        if i > 3:
            print(f'Passwords do not match, exiting')
            return False
    u, err = dataset.read(c_name, username)
    if err != '':
        print(f'{username} not found in {c_name}, {err}')
        return False
    u['password'] = generate_password_hash(pw1)
    err = dataset.update(c_name, username, u)
    if err != '':
        print(f'{username} in {c_name}, {err}')
        return False
    return True
예제 #3
0
 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
예제 #4
0
 def save(self):
     c_name = self.c_name
     key = self.role_name
     role = {
         "role_name": self.role_name,
         "objects": self.objects,
         "roles": self.roles,
         "users": self.users,
     }
     err = dataset.update(c_name, key, user)
     if err != '':
         return False
     return True
예제 #5
0
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)
예제 #6
0
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
예제 #7
0
        sys.exit(1)

expected_keys = ["k1", "k2", "k3"]
keys = dataset.keys(c_name)
i = 0
for key in keys:
    if not key in expected_keys:
        print(f"expected {key} in {expected_keys} for {c_name}")
        sys.exit(1)
    obj, err = dataset.read(c_name, key)
    if err != '':
        print(f"expected '', got '{err}' for dataset.read({c_name}, {key}")
        sys.exit(1)
    obj['t_count'] = i
    i += 1
    err = dataset.update(c_name, key, obj)
    if err != '':
        print(
            f"expected '', got '{err}' for dataset.update({c_name}, {key}, ..."
        )
        sys.exit(1)

f_name = "f1"
err = dataset.frame_create(c_name, f_name, keys[1:], ['._Key', '.title'],
                           ['id', 'title'])
if err != '':
    print(
        f"expected '', got '{err}' for dataset.frame_create({c_name}, {f_name}, ...)"
    )
    sys.exit(1)
예제 #8
0
                    "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}')