Skip to content

Commit

Permalink
improved entity kind check for new collaborators
Browse files Browse the repository at this point in the history
  • Loading branch information
ARADDCC002 committed Nov 26, 2024
1 parent 72eabf5 commit 2fd33d6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
7 changes: 4 additions & 3 deletions backend/src/services/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import ModelCardRevisionModel, {
} from '../models/ModelCardRevision.js'
import { UserInterface } from '../models/User.js'
import { GetModelCardVersionOptions, GetModelCardVersionOptionsKeys, GetModelFiltersKeys } from '../types/enums.js'
import { EntryUserPermissions } from '../types/types.js'
import { EntityKind, EntryUserPermissions } from '../types/types.js'
import { isValidatorResultError } from '../types/ValidatorResultError.js'
import { toEntity } from '../utils/entity.js'
import { fromEntity, toEntity } from '../utils/entity.js'
import { BadReq, Forbidden, InternalError, NotFound } from '../utils/error.js'
import { convertStringToId } from '../utils/id.js'
import { authResponseToUserPermission } from '../utils/permissions.js'
Expand Down Expand Up @@ -377,7 +377,8 @@ async function validateCollaborators(
throw BadReq('Collaborator name must be a valid string')
}
// TODO we currently only check for users, we should consider how we want to handle groups
if (collaborator.startsWith('user:')) {
const { kind } = fromEntity(collaborator)
if (kind === EntityKind.USER) {
await authentication.getUserInformation(collaborator)
}
}),
Expand Down
5 changes: 5 additions & 0 deletions backend/src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ export const RoleKind = {
SCHEMA: 'schema',
} as const

export enum EntityKind {
USER = 'user',
GROUP = 'group',
}

export type RoleKindKeys = (typeof RoleKind)[keyof typeof RoleKind]

export interface Role {
Expand Down

0 comments on commit 2fd33d6

Please sign in to comment.