Ejemplo n.º 1
0

def _suffix_property_check(inst, name):
    if not name.startswith('_'):
        suffix = '_' + name.rsplit('_', 1)[-1]
        prop_func = getattr(inst, suffix, None)
        if getattr(prop_func, '_is_suffix_property', False):
            field_name = name[:-len(suffix)]
            field_val = getattr(inst, field_name)
            return prop_func(field_name, field_val)


suffix_property.check = _suffix_property_check


department_id_adapter = argmod(['location', 'department', 'department_id'], lambda d: uber.models.Department.to_id(d))


@department_id_adapter
def check_can_edit_dept(session, department_id=None, inherent_role=None, override_access=None):
    from uber.models import AdminAccount, DeptMembership, Department
    account_id = cherrypy.session.get('account_id')
    admin_account = session.query(AdminAccount).get(account_id)
    if not getattr(admin_account, override_access, None):
        dh_filter = [
            AdminAccount.id == account_id,
            AdminAccount.attendee_id == DeptMembership.attendee_id]
        if inherent_role in ('dept_head', 'poc', 'checklist_admin'):
            role_attr = 'is_{}'.format(inherent_role)
            dh_filter.append(getattr(DeptMembership, role_attr) == True)  # noqa: E712
        else:
Ejemplo n.º 2
0

def _suffix_property_check(inst, name):
    if not name.startswith('_'):
        suffix = '_' + name.rsplit('_', 1)[-1]
        prop_func = getattr(inst, suffix, None)
        if getattr(prop_func, '_is_suffix_property', False):
            field_name = name[:-len(suffix)]
            field_val = getattr(inst, field_name)
            return prop_func(field_name, field_val)


suffix_property.check = _suffix_property_check


department_id_adapter = argmod(['location', 'department', 'department_id'], lambda d: uber.models.Department.to_id(d))


@department_id_adapter
def check_dept_admin(session, department_id=None, inherent_role=None):
    from uber.models import AdminAccount, DeptMembership, Department
    account_id = cherrypy.session['account_id']
    admin_account = session.query(AdminAccount).get(account_id)
    if c.ACCOUNTS not in admin_account.access_ints:
        dh_filter = [
            AdminAccount.id == account_id,
            AdminAccount.attendee_id == DeptMembership.attendee_id]
        if inherent_role in ('dept_head', 'poc', 'checklist_admin'):
            role_attr = 'is_{}'.format(inherent_role)
            dh_filter.append(getattr(DeptMembership, role_attr) == True)  # noqa: E712
        else: