-
Notifications
You must be signed in to change notification settings - Fork 0
/
code.gs
53 lines (44 loc) · 1.58 KB
/
code.gs
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
//
//
const domain = "yourdomain.com";
//
//
function doGet() {
return HtmlService.createHtmlOutputFromFile('index.html').setTitle('Google Group Duplicator');
}
// https://developers.google.com/apps-script/advanced/admin-sdk-directory#list_all_groups
function getAllGroups() {
let groups = [];
let pageToken, page;
do {
page = AdminDirectory.Groups.list({
"domain": domain,
"pageToken": pageToken
});
if (page.groups) {
groups = groups.concat(page.groups);
} else {
throw 'No groups found on this check.'; // shouldn't be possible
}
pageToken = page.nextPageToken;
} while (pageToken);
return groups;
}
function getGroup(groupId) {
return AdminDirectory.Groups.get(groupId);
}
function copyGroup(groupIdToCopyFrom, newGroupId, newGroupName, newGroupDescription) {
// get the settings from the group we're copying from
let groupToCopyFromSettings = AdminGroupsSettings.Groups.get(groupIdToCopyFrom);
// change it's name and email to the one supplied
groupToCopyFromSettings.email = newGroupId;
groupToCopyFromSettings.name = newGroupName;
groupToCopyFromSettings.description = newGroupDescription;
// make a new group
let newGroup = AdminDirectory.Groups.insert({"email": newGroupId, "name": newGroupName, "description": newGroupDescription});
// update the new group's settings with our settings object from the old group
let newGroupSettings = AdminGroupsSettings.Groups.update(groupToCopyFromSettings, newGroup.email);
// for testing
//AdminDirectory.Groups.remove(newGroupId);
return newGroupSettings;
}