def set_bundles_perm(self, bundle_uuids, group_spec, permission_spec): ''' Give the given |group_spec| the desired |permission_spec| on |bundle_uuids|. ''' check_bundles_have_all_permission(self.model, self._current_user(), bundle_uuids) group_info = self._get_group_info(group_spec, need_admin=False) for bundle_uuid in bundle_uuids: old_permission = self.model.get_group_bundle_permission(group_info['uuid'], bundle_uuid) new_permission = parse_permission(permission_spec) if new_permission > 0: if old_permission > 0: self.model.update_bundle_permission(group_info['uuid'], bundle_uuid, new_permission) else: self.model.add_bundle_permission(group_info['uuid'], bundle_uuid, new_permission) else: if old_permission > 0: self.model.delete_bundle_permission(group_info['uuid'], bundle_uuid) return {'group_info': group_info, 'permission': new_permission}
def set_worksheet_perm(self, worksheet_spec, permission_name, group_spec): uuid = self.get_worksheet_uuid(worksheet_spec) worksheet = self.model.get_worksheet(uuid) check_has_full_permission(self.model, self._current_user_id(), worksheet) new_permission = parse_permission(permission_name) group_info = permission.unique_group(self.model, group_spec) old_permissions = self.model.get_permission(group_info['uuid'], worksheet.uuid) if new_permission == 0: if len(old_permissions) > 0: self.model.delete_permission(group_info['uuid'], worksheet.uuid) else: if len(old_permissions) == 1: self.model.update_permission(group_info['uuid'], worksheet.uuid, new_permission) else: if len(old_permissions) > 0: self.model.delete_permission(group_info['uuid'], worksheet.uuid) self.model.add_permission(group_info['uuid'], worksheet.uuid, new_permission) return {'worksheet': worksheet, 'group_info': group_info, 'permission': new_permission}
def set_worksheet_perm(self, worksheet_uuid, group_spec, permission_spec): ''' Give the given |group_spec| the desired |permission_spec| on |worksheet_uuid|. ''' worksheet = self.model.get_worksheet(worksheet_uuid, fetch_items=False) check_has_all_permission(self.model, self._current_user(), worksheet) group_info = self._get_group_info(group_spec, need_admin=False) old_permission = self.model.get_group_permission(group_info['uuid'], worksheet.uuid) new_permission = parse_permission(permission_spec) if new_permission > 0: if old_permission > 0: self.model.update_permission(group_info['uuid'], worksheet.uuid, new_permission) else: self.model.add_permission(group_info['uuid'], worksheet.uuid, new_permission) else: if old_permission > 0: self.model.delete_permission(group_info['uuid'], worksheet.uuid) return {'worksheet': {'uuid': worksheet.uuid, 'name': worksheet.name}, 'group_info': group_info, 'permission': new_permission}
def _deserialize(self, value, attr, data): try: return parse_permission(value) except UsageError as e: raise ValidationError(e.message)