-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGroupEntitlement.ts
69 lines (63 loc) · 2.69 KB
/
GroupEntitlement.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import { AzureDevOpsConnection } from "./AzureDevopConnection";
import { LicenseRule } from "./LicenseRule";
import { UserEntitlement } from "./UserEntitlement";
import { Group } from "./Group";
import { Logger } from "./Logger";
export class GroupEntitlement {
public id?: string;
public group?: Group;
public licenseRule: LicenseRule;
public lastExecuted?: string;
public status?: number;
/**
* adds a group
* @param { Group } group The Group to be created
* @return { GroupEntitlement } this Group Entitlement
*/
public withGroup(group: Group): this {
this.group = group;
return this;
}
/**
* adds a license Rule
* @param { LicenseRule } licenseRule The license Rule
* @return { GroupEntitlement } this Group Entitlement
*/
public withLicenseRule(licenseRule: LicenseRule): this {
this.licenseRule = licenseRule;
return this;
}
/**
* adds a member to this Group Entitlement
* @param { UserEntitlement } userEntitlement The User Entitlement that needs to be added to this Group Entitlement
* @return { GroupEntitlement } this Group Entitlement
*/
public async addMember(userEntitlement: UserEntitlement): Promise<this> {
await AzureDevOpsConnection.replace(`_apis/GroupEntitlements/${this.id}/members/${userEntitlement.id}?api-version=6.0-preview.1`, undefined);
Logger.log(`Added User '${userEntitlement.user.displayName}' to group '${this.group.displayName}`);
return this;
}
/**
* removes a member from this Group Entitlement
* @param { UserEntitlement } userEntitlement The User Entitlement that needs to be removed from this Group Entitlement
* @return { GroupEntitlement } this Group Entitlement
*/
public async removeMember(userEntitlement: UserEntitlement): Promise<this> {
await AzureDevOpsConnection.del(`_apis/GroupEntitlements/${this.id}/members/${userEntitlement.id}?api-version=6.0-preview.1`);
Logger.log(`Removed User '${userEntitlement.user.displayName}' from group '${this.group.displayName}`);
return this;
}
/**
* Creates this Group Entitlement in Azure DevOps
* @return { GroupEntitlement } this Group Entitlement
*/
public async create(): Promise<this> {
const apiResult = await AzureDevOpsConnection.create<GroupEntitlement>(`_apis/groupentitlements?api-version=6.1-preview.1`, this);
this.id = apiResult.result.id;
this.lastExecuted = apiResult.result.lastExecuted;
this.licenseRule = apiResult.result.licenseRule;
this.group = apiResult.result.group;
this.status = apiResult.result.status;
return this;
}
}