Ejemplo n.º 1
0
def log_permissions(user_field):

    return (AnyoneCanWriteAnonymousLogs(field_name=user_field + '_id')
            | IsOwn(field_name=user_field + '_id') | RoleBasedPermissions(
                target_field=user_field,
                can_be_created_by=(role_kinds.ADMIN, ),
                can_be_read_by=(role_kinds.ADMIN, role_kinds.COACH),
                can_be_updated_by=(role_kinds.ADMIN, ),
                can_be_deleted_by=(role_kinds.ADMIN, ),
            ))
Ejemplo n.º 2
0
class BaseLogModel(AbstractFacilityDataModel):

    permissions = (AnyoneCanWriteAnonymousLogs() | IsOwn()
                   | RoleBasedPermissions(
                       target_field="user",
                       can_be_created_by=(role_kinds.ADMIN, ),
                       can_be_read_by=(role_kinds.ADMIN, role_kinds.COACH),
                       can_be_updated_by=(role_kinds.ADMIN, ),
                       can_be_deleted_by=(role_kinds.ADMIN, ),
                   ))

    class Meta:
        abstract = True

    def infer_dataset(self):
        if self.user:
            return self.user.dataset
        else:
            facility = Facility.get_default_facility()
            assert facility, "Before you can save logs, you must have a facility"
            return facility.dataset