Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restructuring the AccessLevel enum #3501

Merged
merged 2 commits into from
Dec 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ plugins:
- jest-extended

rules:
"@typescript-eslint/dot-notation": error
no-shadow: off
import/no-default-export: off
import/prefer-default-export: off
import/no-extraneous-dependencies:
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ export function getGlobalConfig(env = process.env): GlobalCLIConfig {
}

export function getExposedAPIs(map: Record<string, MethodTemplate[]>) {
// Exclude Gitlab resource from exposure
const { Gitlab, ...expose } = map;
// Exclude Gitlab resource and constants from exposure
const { Gitlab, AccessLevel, ...exposed } = map;

return expose;
return exposed;
}
10 changes: 10 additions & 0 deletions packages/core/src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export enum AccessLevel {
NO_ACCESS = 0,
MINIMAL_ACCESS = 5,
GUEST = 10,
REPORTER = 20,
DEVELOPER = 30,
MAINTAINER = 40,
OWNER = 50,
ADMIN = 60,
}
1 change: 1 addition & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* ---------------- Resources --------------- */
export * from './resources';
export * from './constants';
export type * from './templates';
export type {
Camelize,
Expand Down
12 changes: 9 additions & 3 deletions packages/core/src/resources/BroadcastMessages.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { BaseResource } from '@gitbeaker/requester-utils';
import { RequestHelper } from '../infrastructure';
import type { AccessLevel } from '../templates/ResourceAccessRequests';
import type {
GitlabAPIResponse,
PaginationRequestOptions,
PaginationTypes,
ShowExpanded,
Sudo,
} from '../infrastructure';
import { AccessLevel } from '../constants';

export interface BroadcastMessageSchema extends Record<string, unknown> {
message: string;
Expand All @@ -18,7 +18,10 @@ export interface BroadcastMessageSchema extends Record<string, unknown> {
id: number;
active: boolean;
target_path: string;
target_access_levels: AccessLevel[];
target_access_levels: Exclude<
AccessLevel,
AccessLevel.MINIMAL_ACCESS | AccessLevel.NO_ACCESS | AccessLevel.ADMIN
>[];
broadcast_type: string;
dismissable: boolean;
}
Expand All @@ -31,7 +34,10 @@ export interface BroadcastMessageOptions extends Record<string, unknown> {
font?: string;
active?: boolean;
targetPath?: string;
targetAccessLevels?: AccessLevel[];
targetAccessLevels?: Exclude<
AccessLevel,
AccessLevel.MINIMAL_ACCESS | AccessLevel.NO_ACCESS | AccessLevel.ADMIN
>[];
broadcastType?: string;
dismissable?: boolean;
}
Expand Down
5 changes: 3 additions & 2 deletions packages/core/src/resources/GroupAccessRequests.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import type { BaseResourceOptions } from '@gitbeaker/requester-utils';
import { ResourceAccessRequests } from '../templates';
import type { AccessLevel, AccessRequestSchema } from '../templates/ResourceAccessRequests';
import type { AccessRequestSchema } from '../templates/ResourceAccessRequests';
import type {
GitlabAPIResponse,
PaginationRequestOptions,
PaginationTypes,
ShowExpanded,
Sudo,
} from '../infrastructure';
import { AccessLevel } from '../constants';

export interface GroupAccessRequests<C extends boolean = false> extends ResourceAccessRequests<C> {
all<E extends boolean = false, P extends PaginationTypes = 'offset'>(
Expand All @@ -23,7 +24,7 @@ export interface GroupAccessRequests<C extends boolean = false> extends Resource
approve<E extends boolean = false>(
groupId: string | number,
userId: number,
options?: { accessLevel?: AccessLevel } & Sudo & ShowExpanded<E>,
options?: { accessLevel?: Exclude<AccessLevel, AccessLevel.ADMIN> } & Sudo & ShowExpanded<E>,
): Promise<GitlabAPIResponse<AccessRequestSchema, C, E, void>>;

deny<E extends boolean = false>(
Expand Down
11 changes: 9 additions & 2 deletions packages/core/src/resources/GroupAccessTokens.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import type { BaseResourceOptions } from '@gitbeaker/requester-utils';
import { ResourceAccessTokens } from '../templates';
import type { AccessTokenSchema, AccessTokenScopes } from '../templates/ResourceAccessTokens';
import type { AccessLevel } from '../templates/ResourceAccessRequests';
import type {
GitlabAPIResponse,
PaginationRequestOptions,
PaginationTypes,
ShowExpanded,
Sudo,
} from '../infrastructure';
import { AccessLevel } from '../constants';

export interface GroupAccessTokens<C extends boolean = false> extends ResourceAccessTokens<C> {
all<E extends boolean = false, P extends PaginationTypes = 'offset'>(
Expand All @@ -20,7 +20,14 @@ export interface GroupAccessTokens<C extends boolean = false> extends ResourceAc
groupId: string | number,
name: string,
scopes: AccessTokenScopes[],
options?: { accessLevel?: AccessLevel; expiresAt?: string } & Sudo & ShowExpanded<E>,
options?: {
accessLevel?: Exclude<
AccessLevel,
AccessLevel.MINIMAL_ACCESS | AccessLevel.NO_ACCESS | AccessLevel.ADMIN
>;
expiresAt?: string;
} & Sudo &
ShowExpanded<E>,
): Promise<GitlabAPIResponse<AccessTokenSchema, C, E, void>>;

revoke<E extends boolean = false>(
Expand Down
7 changes: 4 additions & 3 deletions packages/core/src/resources/GroupInvitations.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { BaseResourceOptions } from '@gitbeaker/requester-utils';
import { ResourceInvitations } from '../templates';
import type { InvitationSchema } from '../templates/ResourceInvitations';
import type { AccessLevel } from '../templates/ResourceAccessRequests';
import type {
GitlabAPIResponse,
OneOf,
Expand All @@ -10,11 +9,12 @@ import type {
ShowExpanded,
Sudo,
} from '../infrastructure';
import { AccessLevel } from '../constants';

export interface GroupInvitations<C extends boolean = false> {
add<E extends boolean = false>(
groupId: string | number,
accessLevel: AccessLevel,
accessLevel: Exclude<AccessLevel, AccessLevel.ADMIN>,
options: OneOf<{ email: string; userId: string }> & {
expiresAt?: string;
inviteSource?: string;
Expand All @@ -32,7 +32,8 @@ export interface GroupInvitations<C extends boolean = false> {
edit<E extends boolean = false>(
groupId: string | number,
email: string,
options?: { expiresAt?: string; accessLevel?: AccessLevel } & Sudo & ShowExpanded<E>,
options?: { expiresAt?: string; accessLevel?: Exclude<AccessLevel, AccessLevel.ADMIN> } & Sudo &
ShowExpanded<E>,
): Promise<GitlabAPIResponse<InvitationSchema, C, E, void>>;

remove<E extends boolean = false>(
Expand Down
5 changes: 3 additions & 2 deletions packages/core/src/resources/GroupLDAPLinks.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import { BaseResource } from '@gitbeaker/requester-utils';
import { RequestHelper, endpoint } from '../infrastructure';
import type { AccessLevel } from '../templates/ResourceAccessRequests';
import type {
GitlabAPIResponse,
PaginationRequestOptions,
PaginationTypes,
ShowExpanded,
Sudo,
} from '../infrastructure';
import { AccessLevel } from '../constants';

// Documentation: https://docs.gitlab.com/ee/api/groups.html#ldap-group-links
export class GroupLDAPLinks<C extends boolean = false> extends BaseResource<C> {
add<E extends boolean = false>(
groupId: string | number,
groupAccess: number,
provider: string,
options?: { cn?: string; groupAccess?: AccessLevel } & Sudo & ShowExpanded<E>,
options?: { cn?: string; groupAccess?: Exclude<AccessLevel, AccessLevel.ADMIN> } & Sudo &
ShowExpanded<E>,
): Promise<GitlabAPIResponse<string, C, E, void>> {
return RequestHelper.post<string>()(this, endpoint`groups/${groupId}/ldap_group_links`, {
groupAccess,
Expand Down
7 changes: 5 additions & 2 deletions packages/core/src/resources/GroupMemberRoles.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { BaseResource } from '@gitbeaker/requester-utils';
import type { AccessLevel } from '../templates/ResourceAccessRequests';
import { RequestHelper, endpoint } from '../infrastructure';
import type {
GitlabAPIResponse,
Expand All @@ -8,6 +7,7 @@ import type {
ShowExpanded,
Sudo,
} from '../infrastructure';
import { AccessLevel } from '../constants';

export interface MemberRoleSchema extends Record<string, unknown> {
id: number;
Expand All @@ -19,7 +19,10 @@ export interface MemberRoleSchema extends Record<string, unknown> {
export class GroupMemberRoles<C extends boolean = false> extends BaseResource<C> {
add<E extends boolean = false>(
groupId: string | number,
baseAccessLevel: AccessLevel,
baseAccessLevel: Exclude<
AccessLevel,
AccessLevel.NO_ACCESS | AccessLevel.MINIMAL_ACCESS | AccessLevel.ADMIN
>,
options?: { readCode?: boolean } & Sudo & ShowExpanded<E>,
): Promise<GitlabAPIResponse<MemberRoleSchema, C, E, void>> {
return RequestHelper.post<MemberRoleSchema>()(this, endpoint`groups/${groupId}/members`, {
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/resources/GroupMembers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { BaseResourceOptions } from '@gitbeaker/requester-utils';
import { ResourceMembers } from '../templates';
import type { AccessLevel } from '../templates/ResourceAccessRequests';
import type {
AddMemeberOptions,
AllMembersOptions,
Expand All @@ -17,6 +16,7 @@ import type {
ShowExpanded,
Sudo,
} from '../infrastructure';
import { AccessLevel } from '../constants';

export interface BillableGroupMemberSchema extends CondensedMemberSchema {
last_activity_on: string;
Expand All @@ -34,7 +34,7 @@ export interface BillableGroupMemberMembershipSchema extends Record<string, unkn
expires_at: string;
access_level: {
string_value: string;
integer_value: AccessLevel;
integer_value: Exclude<AccessLevel, AccessLevel.ADMIN>;
};
}

Expand All @@ -46,7 +46,7 @@ export interface GroupMembers<C extends boolean = false> extends ResourceMembers
add<E extends boolean = false>(
projectId: string | number,
userId: number,
accessLevel: AccessLevel,
accessLevel: Exclude<AccessLevel, AccessLevel.ADMIN>,
options?: AddMemeberOptions & Sudo & ShowExpanded<E>,
): Promise<GitlabAPIResponse<MemberSchema, C, E, void>>;

Expand All @@ -62,7 +62,7 @@ export interface GroupMembers<C extends boolean = false> extends ResourceMembers
edit<E extends boolean = false>(
projectId: string | number,
userId: number,
accessLevel: AccessLevel,
accessLevel: Exclude<AccessLevel, AccessLevel.ADMIN>,
options?: { expiresAt?: string; memberRoleId?: number } & Sudo & ShowExpanded<E>,
): Promise<GitlabAPIResponse<MemberSchema, C, E, void>>;

Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/resources/GroupSAMLLinks.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { BaseResource } from '@gitbeaker/requester-utils';
import { RequestHelper, endpoint } from '../infrastructure';
import type { AccessLevel } from '../templates/ResourceAccessRequests';
import type {
GitlabAPIResponse,
PaginationRequestOptions,
PaginationTypes,
ShowExpanded,
Sudo,
} from '../infrastructure';
import { AccessLevel } from '../constants';

export interface SAMLGroupSchema extends Record<string, unknown> {
name: string;
Expand All @@ -29,7 +29,7 @@ export class GroupSAMLLinks<C extends boolean = false> extends BaseResource<C> {
create<E extends boolean = false>(
groupId: string | number,
samlGroupName: string,
accessLevel: AccessLevel,
accessLevel: Exclude<AccessLevel, AccessLevel.ADMIN>,
options?: Sudo & ShowExpanded<E>,
): Promise<GitlabAPIResponse<SAMLGroupSchema, C, E, void>> {
return RequestHelper.post<SAMLGroupSchema>()(
Expand Down
5 changes: 3 additions & 2 deletions packages/core/src/resources/Groups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type {
import type { CondensedProjectSchema, ProjectSchema } from './Projects';
import type { UserSchema } from './Users';
import type { CustomAttributeSchema } from '../templates/ResourceCustomAttributes';
import { AccessLevel } from '../constants';

export interface GroupStatisticsSchema {
storage_size: number;
Expand Down Expand Up @@ -76,7 +77,7 @@ export type AllGroupsOptions = {
statistics?: boolean;
withCustomAttributes?: boolean;
owned?: boolean;
minAccessLevel?: number;
minAccessLevel?: Exclude<AccessLevel, AccessLevel.ADMIN>;
topLevelOnly?: boolean;
};

Expand All @@ -100,7 +101,7 @@ export type AllGroupProjectsOptions = {
withMergeRequestsEnabled?: boolean;
withShared?: boolean;
includeSubgroups?: boolean;
minAccessLevel?: number;
minAccessLevel?: Exclude<AccessLevel, AccessLevel.ADMIN>;
withCustomAttributes?: boolean;
withSecurityReports?: boolean;
};
Expand Down
5 changes: 3 additions & 2 deletions packages/core/src/resources/ProjectAccessRequests.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import type { BaseResourceOptions } from '@gitbeaker/requester-utils';
import { ResourceAccessRequests } from '../templates';
import type { AccessLevel, AccessRequestSchema } from '../templates/ResourceAccessRequests';
import type { AccessRequestSchema } from '../templates/ResourceAccessRequests';
import type {
GitlabAPIResponse,
PaginationRequestOptions,
PaginationTypes,
ShowExpanded,
Sudo,
} from '../infrastructure';
import { AccessLevel } from '../constants';

export interface ProjectAccessRequests<C extends boolean = false>
extends ResourceAccessRequests<C> {
Expand All @@ -24,7 +25,7 @@ export interface ProjectAccessRequests<C extends boolean = false>
approve<E extends boolean = false>(
projectId: string | number,
userId: number,
options?: { accessLevel?: AccessLevel } & Sudo & ShowExpanded<E>,
options?: { accessLevel?: Exclude<AccessLevel, AccessLevel.ADMIN> } & Sudo & ShowExpanded<E>,
): Promise<GitlabAPIResponse<AccessRequestSchema, C, E, void>>;

deny<E extends boolean = false>(
Expand Down
11 changes: 9 additions & 2 deletions packages/core/src/resources/ProjectAccessTokens.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import type { BaseResourceOptions } from '@gitbeaker/requester-utils';
import { ResourceAccessTokens } from '../templates';
import type { AccessTokenSchema, AccessTokenScopes } from '../templates/ResourceAccessTokens';
import type { AccessLevel } from '../templates/ResourceAccessRequests';
import type {
GitlabAPIResponse,
PaginationRequestOptions,
PaginationTypes,
ShowExpanded,
Sudo,
} from '../infrastructure';
import { AccessLevel } from '../constants';

export interface ProjectAccessTokens<C extends boolean = false> extends ResourceAccessTokens<C> {
all<E extends boolean = false, P extends PaginationTypes = 'offset'>(
Expand All @@ -20,7 +20,14 @@ export interface ProjectAccessTokens<C extends boolean = false> extends Resource
projectId: string | number,
name: string,
scopes: AccessTokenScopes[],
options?: { accessLevel?: AccessLevel; expiresAt?: string } & Sudo & ShowExpanded<E>,
options?: {
accessLevel?: Exclude<
AccessLevel,
AccessLevel.MINIMAL_ACCESS | AccessLevel.NO_ACCESS | AccessLevel.ADMIN
>;
expiresAt?: string;
} & Sudo &
ShowExpanded<E>,
): Promise<GitlabAPIResponse<AccessTokenSchema, C, E, void>>;

revoke<E extends boolean = false>(
Expand Down
7 changes: 4 additions & 3 deletions packages/core/src/resources/ProjectInvitations.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { BaseResourceOptions } from '@gitbeaker/requester-utils';
import { ResourceInvitations } from '../templates';
import type { InvitationSchema } from '../templates/ResourceInvitations';
import type { AccessLevel } from '../templates/ResourceAccessRequests';
import type {
GitlabAPIResponse,
OneOf,
Expand All @@ -10,11 +9,12 @@ import type {
ShowExpanded,
Sudo,
} from '../infrastructure';
import { AccessLevel } from '../constants';

export interface ProjectInvitations<C extends boolean = false> {
add<E extends boolean = false>(
projectId: string | number,
accessLevel: AccessLevel,
accessLevel: Exclude<AccessLevel, AccessLevel.ADMIN>,
options: OneOf<{ email: string; userId: string }> & {
expiresAt?: string;
inviteSource?: string;
Expand All @@ -32,7 +32,8 @@ export interface ProjectInvitations<C extends boolean = false> {
edit<E extends boolean = false>(
projectId: string | number,
email: string,
options?: { expiresAt?: string; accessLevel?: AccessLevel } & Sudo & ShowExpanded<E>,
options?: { expiresAt?: string; accessLevel?: Exclude<AccessLevel, AccessLevel.ADMIN> } & Sudo &
ShowExpanded<E>,
): Promise<GitlabAPIResponse<InvitationSchema, C, E, void>>;

remove<E extends boolean = false>(
Expand Down
Loading