| 1 | import { schema } from '@ghost/db'; |
| 2 | import { ApiProperty, ApiPropertyOptional |
| 3 | import { |
| 4 | ArrayMaxSize, |
| 5 | IsArray, |
| 6 | IsBoolean, |
| 7 | IsEmail, |
| 8 | IsIn, |
| 9 | IsNotEmpty, |
| 10 | IsOptional, |
| 11 | IsString, |
| 12 | IsUrl, |
| 13 | MaxLength, |
| 14 | ValidateIf, |
| 15 | } from 'class-validator'; |
| 16 | |
| 17 | import type { CollaboratorRole |
| 18 | |
| 19 | import { |
| 20 | type OrganizationRole, |
| 21 | organizationRoleHierarchy, |
| 22 | } from '@ghost/permissions'; |
| 23 | |
| 24 | export class OrganizationSummaryDTO |
| 25 | @ApiProperty() |
| 26 | slug: string; |
| 27 | |
| 28 | @ApiProperty() |
| 29 | name: string; |
| 30 | |
| 31 | @ApiProperty({ type |
| 32 | logo: string |
| 33 | } |
| 34 | |
| 35 | export class MyOrganizationDTO |
| 36 | @ApiProperty({ |
| 37 | enumName: 'OrganizationRole', |
| 38 | enum: organizationRoleHierarchy, |
| 39 | nullable: true, |
| 40 | description: |
| 41 | 'Highest built-in role held; null when only custom roles are held.', |
| 42 | }) |
| 43 | viewerRole: OrganizationRole |
| 44 | |
| 45 | @ApiProperty({ |
| 46 | description: |
| 47 | 'Whether the organization lets the viewer create repositories in it, of at least one visibility.', |
| 48 | }) |
| 49 | canCreateRepositories: boolean; |
| 50 | } |
| 51 | |
| 52 | export class ListMyOrganizationsResponseDTO |
| 53 | @ApiProperty({ type |
| 54 | organizations: MyOrganizationDTO |
| 55 | } |
| 56 | |
| 57 | export class ListOrganizationsResponseDTO |
| 58 | @ApiProperty({ type |
| 59 | organizations: OrganizationSummaryDTO |
| 60 | } |
| 61 | |
| 62 | export class OrganizationMemberDTO |
| 63 | @ApiProperty() |
| 64 | username: string; |
| 65 | |
| 66 | @ApiProperty() |
| 67 | name: string; |
| 68 | |
| 69 | @ApiProperty({ type |
| 70 | image: string |
| 71 | |
| 72 | @ApiProperty({ |
| 73 | description: |
| 74 | 'Whether the member shows their membership outside the organization.', |
| 75 | }) |
| 76 | public: boolean; |
| 77 | } |
| 78 | |
| 79 | export class PinnedRepositoryDTO |
| 80 | @ApiProperty() |
| 81 | slug: string; |
| 82 | |
| 83 | @ApiProperty() |
| 84 | name: string; |
| 85 | |
| 86 | @ApiProperty({ type |
| 87 | description: string |
| 88 | |
| 89 | @ApiProperty({ |
| 90 | enumName: 'RepositoryVisibility', |
| 91 | enum: schema.repositoryVisiblity |
| 92 | }) |
| 93 | visibility: (typeof |
| 94 | } |
| 95 | |
| 96 | export class OrganizationProfileDTO |
| 97 | @ApiProperty() |
| 98 | createdAt: string; |
| 99 | |
| 100 | @ApiProperty({ type |
| 101 | description: string |
| 102 | |
| 103 | @ApiProperty({ type |
| 104 | website: string |
| 105 | |
| 106 | @ApiProperty({ type |
| 107 | location: string |
| 108 | |
| 109 | @ApiProperty({ type |
| 110 | email: string |
| 111 | |
| 112 | @ApiProperty({ description |
| 113 | repositoryCount: number; |
| 114 | |
| 115 | @ApiProperty({ |
| 116 | type: [OrganizationMemberDTO], |
| 117 | description: |
| 118 | 'Every member for a member; only public members for anyone else.', |
| 119 | }) |
| 120 | members: OrganizationMemberDTO |
| 121 | |
| 122 | @ApiProperty({ |
| 123 | type: [PinnedRepositoryDTO], |
| 124 | description: |
| 125 | 'In pinned order, limited to repositories the viewer can read.', |
| 126 | }) |
| 127 | pinned: PinnedRepositoryDTO |
| 128 | |
| 129 | @ApiProperty({ |
| 130 | enumName: 'OrganizationRole', |
| 131 | enum: organizationRoleHierarchy, |
| 132 | nullable: true, |
| 133 | description: |
| 134 | "The viewer's role in the organization; null for anyone outside it.", |
| 135 | }) |
| 136 | viewerRole: OrganizationRole |
| 137 | } |
| 138 | |
| 139 | export class InviteByUsernameRequestDTO |
| 140 | @ApiProperty() |
| 141 | @IsString() |
| 142 | @IsNotEmpty() |
| 143 | username: string; |
| 144 | |
| 145 | @ApiProperty({ |
| 146 | enumName: 'OrganizationRole', |
| 147 | enum: organizationRoleHierarchy, |
| 148 | }) |
| 149 | @IsIn(organizationRoleHierarchy) |
| 150 | role: OrganizationRole |
| 151 | } |
| 152 | |
| 153 | export class ReceivedOrganizationInvitationDTO |
| 154 | @ApiProperty() |
| 155 | id: string; |
| 156 | |
| 157 | @ApiProperty({ type |
| 158 | organization: OrganizationSummaryDTO |
| 159 | |
| 160 | @ApiProperty({ type |
| 161 | role: string |
| 162 | |
| 163 | @ApiProperty({ type |
| 164 | invitedByUsername: string |
| 165 | |
| 166 | @ApiProperty() |
| 167 | expiresAt: string; |
| 168 | } |
| 169 | |
| 170 | export class ListReceivedOrganizationInvitationsResponseDTO |
| 171 | @ApiProperty({ type |
| 172 | invitations: ReceivedOrganizationInvitationDTO |
| 173 | } |
| 174 | |
| 175 | const repositoryRoleProperty = { |
| 176 | enumName: 'RepositoryRole', |
| 177 | enum: schema.repositoryRole |
| 178 | }; |
| 179 | |
| 180 | export class OrganizationSettingsDTO |
| 181 | @ApiProperty({ |
| 182 | ...repositoryRoleProperty, |
| 183 | nullable: true, |
| 184 | description: |
| 185 | "Every member's role on every repository; null grants members nothing beyond their teams and collaborations.", |
| 186 | }) |
| 187 | basePermission: CollaboratorRole |
| 188 | |
| 189 | @ApiProperty() |
| 190 | membersCanCreatePublicRepositories: boolean |
| 191 | |
| 192 | @ApiProperty() |
| 193 | membersCanCreatePrivateRepositories: boolean |
| 194 | |
| 195 | @ApiProperty({ |
| 196 | description: 'Whether its private repositories may be forked.', |
| 197 | }) |
| 198 | allowPrivateForks: boolean; |
| 199 | |
| 200 | @ApiProperty({ |
| 201 | type: String, |
| 202 | nullable: true, |
| 203 | description: 'Recorded as the default branch of each new repository.', |
| 204 | }) |
| 205 | defaultBranch: string |
| 206 | |
| 207 | @ApiProperty({ type |
| 208 | description: string |
| 209 | |
| 210 | @ApiProperty({ type |
| 211 | website: string |
| 212 | |
| 213 | @ApiProperty({ type |
| 214 | location: string |
| 215 | |
| 216 | @ApiProperty({ type |
| 217 | email: string |
| 218 | } |
| 219 | |
| 220 | /** Omitted fields are left as they are; null clears a field. */ |
| 221 | export class UpdateOrganizationSettingsDTO |
| 222 | @ApiPropertyOptional({ ... |
| 223 | @ValidateIf((_ |
| 224 | @IsIn(schema. |
| 225 | @IsOptional() |
| 226 | basePermission?: CollaboratorRole |
| 227 | |
| 228 | @ApiPropertyOptional() |
| 229 | @IsBoolean() |
| 230 | @IsOptional() |
| 231 | membersCanCreatePublicRepositories?: boolean |
| 232 | |
| 233 | @ApiPropertyOptional() |
| 234 | @IsBoolean() |
| 235 | @IsOptional() |
| 236 | membersCanCreatePrivateRepositories?: boolean |
| 237 | |
| 238 | @ApiPropertyOptional() |
| 239 | @IsBoolean() |
| 240 | @IsOptional() |
| 241 | allowPrivateForks?: boolean |
| 242 | |
| 243 | @ApiPropertyOptional({ type |
| 244 | @ValidateIf((_ |
| 245 | @IsString() |
| 246 | @MaxLength(255) |
| 247 | @IsOptional() |
| 248 | defaultBranch?: string |
| 249 | |
| 250 | @ApiPropertyOptional({ type |
| 251 | @ValidateIf((_ |
| 252 | @IsString() |
| 253 | @MaxLength(350) |
| 254 | @IsOptional() |
| 255 | description?: string |
| 256 | |
| 257 | @ApiPropertyOptional({ type |
| 258 | @ValidateIf((_ |
| 259 | @IsUrl({ require_protocol |
| 260 | @IsOptional() |
| 261 | website?: string |
| 262 | |
| 263 | @ApiPropertyOptional({ type |
| 264 | @ValidateIf((_ |
| 265 | @IsString() |
| 266 | @MaxLength(100) |
| 267 | @IsOptional() |
| 268 | location?: string |
| 269 | |
| 270 | @ApiPropertyOptional({ type |
| 271 | @ValidateIf((_ |
| 272 | @IsEmail() |
| 273 | @IsOptional() |
| 274 | email?: string |
| 275 | } |
| 276 | |
| 277 | export class SetPinnedRepositoriesDTO |
| 278 | @ApiProperty({ |
| 279 | type: [String], |
| 280 | description: "Slugs of the organization's repositories, in display order.", |
| 281 | }) |
| 282 | @IsArray() |
| 283 | @ArrayMaxSize(6) |
| 284 | @IsString({ each |
| 285 | repositories: string[] |
| 286 | } |
| 287 | |
| 288 | export class OutsideCollaboratorRepositoryDTO |
| 289 | @ApiProperty() |
| 290 | slug: string; |
| 291 | |
| 292 | @ApiProperty(repositoryRoleProperty) |
| 293 | role: CollaboratorRole |
| 294 | |
| 295 | @ApiProperty({ description |
| 296 | pending: boolean; |
| 297 | } |
| 298 | |
| 299 | export class OutsideCollaboratorDTO |
| 300 | @ApiProperty() |
| 301 | username: string; |
| 302 | |
| 303 | @ApiProperty() |
| 304 | name: string; |
| 305 | |
| 306 | @ApiProperty({ type |
| 307 | image: string |
| 308 | |
| 309 | @ApiProperty({ type |
| 310 | repositories: OutsideCollaboratorRepositoryDTO |
| 311 | } |
| 312 | |
| 313 | export class ListOutsideCollaboratorsResponseDTO |
| 314 | @ApiProperty({ type |
| 315 | collaborators: OutsideCollaboratorDTO |
| 316 | } |
| 317 | |
| 318 | export class OrganizationTeamSummaryDTO |
| 319 | @ApiProperty() |
| 320 | id: string; |
| 321 | |
| 322 | @ApiProperty() |
| 323 | name: string; |
| 324 | |
| 325 | @ApiProperty({ description |
| 326 | slug: string; |
| 327 | |
| 328 | @ApiProperty() |
| 329 | memberCount: number; |
| 330 | |
| 331 | @ApiProperty() |
| 332 | repositoryCount: number; |
| 333 | } |
| 334 | |
| 335 | export class ListOrganizationTeamsResponseDTO |
| 336 | @ApiProperty({ type |
| 337 | teams: OrganizationTeamSummaryDTO |
| 338 | } |
| 339 | |
| 340 | export class TeamMemberDTO |
| 341 | @ApiProperty() |
| 342 | username: string; |
| 343 | |
| 344 | @ApiProperty() |
| 345 | name: string; |
| 346 | |
| 347 | @ApiProperty({ type |
| 348 | image: string |
| 349 | |
| 350 | @ApiProperty() |
| 351 | maintainer: boolean; |
| 352 | } |
| 353 | |
| 354 | export class TeamRepositoryDTO |
| 355 | @ApiProperty() |
| 356 | slug: string; |
| 357 | |
| 358 | @ApiProperty() |
| 359 | name: string; |
| 360 | |
| 361 | @ApiProperty({ |
| 362 | enumName: 'RepositoryVisibility', |
| 363 | enum: schema.repositoryVisiblity |
| 364 | }) |
| 365 | visibility: (typeof |
| 366 | |
| 367 | @ApiProperty(repositoryRoleProperty) |
| 368 | role: CollaboratorRole |
| 369 | } |
| 370 | |
| 371 | export class OrganizationTeamDTO |
| 372 | @ApiProperty() |
| 373 | id: string; |
| 374 | |
| 375 | @ApiProperty() |
| 376 | name: string; |
| 377 | |
| 378 | @ApiProperty() |
| 379 | slug: string; |
| 380 | |
| 381 | @ApiProperty({ type |
| 382 | members: TeamMemberDTO |
| 383 | |
| 384 | @ApiProperty({ type |
| 385 | repositories: TeamRepositoryDTO |
| 386 | |
| 387 | @ApiProperty({ |
| 388 | description: |
| 389 | "Whether the viewer may change the team's members: an admin or one of its maintainers.", |
| 390 | }) |
| 391 | viewerCanManage: boolean; |
| 392 | } |