(self)
| 166 | } |
| 167 | |
| 168 | def validate(self): |
| 169 | # Parent JSON schema validation |
| 170 | cleaned = super(RoleDefinitionFileFormatAPI, self).validate() |
| 171 | |
| 172 | # Custom validation |
| 173 | |
| 174 | # Validate that only the correct permission types are used |
| 175 | permission_grants = getattr(self, "permission_grants", []) |
| 176 | for permission_grant in permission_grants: |
| 177 | resource_uid = permission_grant.get("resource_uid", None) |
| 178 | permission_types = permission_grant.get("permission_types", []) |
| 179 | |
| 180 | if resource_uid: |
| 181 | # Permission types which apply to a resource |
| 182 | resource_type, _ = parse_uid(uid=resource_uid) |
| 183 | valid_permission_types = ( |
| 184 | PermissionType.get_valid_permissions_for_resource_type( |
| 185 | resource_type=resource_type |
| 186 | ) |
| 187 | ) |
| 188 | |
| 189 | for permission_type in permission_types: |
| 190 | if permission_type not in valid_permission_types: |
| 191 | message = ( |
| 192 | 'Invalid permission type "%s" for resource type "%s"' |
| 193 | % ( |
| 194 | permission_type, |
| 195 | resource_type, |
| 196 | ) |
| 197 | ) |
| 198 | raise ValueError(message) |
| 199 | else: |
| 200 | # Right now we only support single permission type (list) which is global and |
| 201 | # doesn't apply to a resource |
| 202 | for permission_type in permission_types: |
| 203 | if permission_type not in GLOBAL_PERMISSION_TYPES: |
| 204 | valid_global_permission_types = ", ".join( |
| 205 | GLOBAL_PERMISSION_TYPES |
| 206 | ) |
| 207 | message = ( |
| 208 | 'Invalid permission type "%s". Valid global permission types ' |
| 209 | "which can be used without a resource id are: %s" |
| 210 | % (permission_type, valid_global_permission_types) |
| 211 | ) |
| 212 | raise ValueError(message) |
| 213 | |
| 214 | return cleaned |
| 215 | |
| 216 | |
| 217 | class BaseRoleAssigmentAPI(BaseAPI): |
nothing calls this directly
no test coverage detected