-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcode.gs
64 lines (55 loc) · 2.31 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
54
55
56
57
58
59
60
61
62
63
64
function doGet() {
return HtmlService.createHtmlOutputFromFile('index.html').setTitle('Google Group Directory Unlister');
}
function test_() {
//var groups = getAllGroups();
//console.log(JSON.stringify(groups));
//console.log(showGroupInDirectory("[email protected]", false));
//console.log(getGroupSettings("[email protected]"));
}
// 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": "yourdomain.com",
"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 showGroupInDirectory(groupId, showInDirectory) {
let re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
if (!groupId || typeof groupId != "string" || !re.test(groupId.toLowerCase())) {
throw 'Please call this function with a Google Group ID';
}
if (showInDirectory == null) {
showInDirectory = "true";
}
showInDirectory = showInDirectory.toString();
if (showInDirectory != "true" && showInDirectory != 'false') {
throw 'Please call this function with a boolean. Do you want this group to show in the directory or not?';
}
// okay. we now have a valid email address for the group id, and if we do or don't want it to be in the directory.
// get the group object
var group = AdminGroupsSettings.Groups.get(groupId);
// update it's "included in the list" property
group.includeInGlobalAddressList = showInDirectory;
// then patch the group with it's new setting
AdminGroupsSettings.Groups.patch(group, groupId);
return group;
}
function getGroupSettings(groupId) {
let re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
if (!groupId || typeof groupId != 'string' || !re.test(groupId.toLowerCase())) {
throw 'Please call this function with a Google Group ID';
}
return AdminGroupsSettings.Groups.get(groupId);
}