-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
484 lines (462 loc) · 17.1 KB
/
index.html
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<script src="https://cdn.jsdelivr.net/npm/jquery@3/dist/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4/dist/js/bootstrap.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap-notify@3/bootstrap-notify.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6/js/all.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/bootswatch@4/dist/materia/bootstrap.min.css" rel="stylesheet" />
<style>body{padding-top:40px}</style>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-12">
<div class="card border-light mb-3">
<div class="card-header">
<span class="fas fa-sliders-h"></span>Google Group Advanced Settings
<div class="float-right">
<button type="button" id="refresh" class="btn btn-primary btn-sm"><span class="fas fa-sync"></i></button>
</div>
</div>
<div class="card-body">
<form>
<div class="form-group">
<fieldset>
<label class="control-label" for="groups"><span class="fas fa-users"></span>Group</label>
<select id="groups" class="custom-select">
<option selected>Loading...</option>
</select>
</fieldset>
</div>
<div class="form-group row">
<fieldset class="col">
<label class="control-label" for="settingQuestion"><span class="far fa-question-circle"></span>Setting to Change</label>
<select id="settingQuestion" class="custom-select">
<option selected>Loading...</option>
</select>
</fieldset>
<fieldset class="col">
<label class="control-label" for="settingAnswer"><span class="fas fa-cog"></i></label>
<select id="settingAnswer" class="custom-select">
<option selected>Loading...</option>
</select>
</fieldset>
</div>
<div class="col-auto">
<button id="submit" type="submit" class="btn btn-block btn-primary">Update Setting</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<script>
$(document).ready(function() {
getGroups();
populateSettingQuestions();
});
// the function to update the "groups" dropdown.
// happens on load and when the refresh button is pressed.
function getGroups() {
console.log("Updating all groups...");
disableRefresh();
disableSubmit("Just a minute...");
$('#groups').find('option').remove().append('<option selected>Refreshing...</option>');
google.script.run.withSuccessHandler(updateGroupsDropdown).withFailureHandler(handleError).getAllGroups();
}
// getGroups() has run successfully
// this updates the dropdown with all of the groups as choices
function updateGroupsDropdown(groups) {
$('#groups').find('option').remove();
for (var i in groups) {
$('#groups').append('<option value="' + groups[i].email + '">' + groups[i].name + ' (' + groups[i].email + ')</option>');
}
console.log("Updated!");
var groupId = $('#groups option:selected').val();
google.script.run.withSuccessHandler(selectCurrentSettingAnswer).withFailureHandler(handleError).getGroupSettings(groupId);
enableRefresh();
enableSubmit();
}
// handles all errors that might happen from any of the server-side apps script functions
function handleError(error) {
$.notify({
"icon": "fas fa-exclamation-triangle",
"delay": 30000,
"message": error
},{
"type": "danger"
});
enableSubmit();
enableRefresh();
}
// this is what happens when the form is submitted.
// disable the buttons, then grab the group, the setting to change, and the new value,
// then run setGroupSetting() server-side to update that setting
function update(event) {
event.preventDefault();
disableSubmit('Setting...');
disableRefresh();
var groupId = $('#groups option:selected').val();
var settingQuestion = $('#settingQuestion option:selected').val();
var settingAnswer = $('#settingAnswer option:selected').val();
console.log("Attempting to update " + settingQuestion + " setting to " + settingAnswer + " for " + groupId + "...");
google.script.run.withSuccessHandler(settingSetSuccessfully).withFailureHandler(handleError).setGroupSetting(groupId, settingQuestion, settingAnswer);
}
// once the above function runs successfully,
// this resets the form, sends a "success" notification,
// sets the correct settings colors, and re-enables the buttons
function settingSetSuccessfully(setting) {
var groupId = $('#groups option:selected').val();
getQuestionSelectionAndColors();
$.notify({
"icon": "fas fa-thumbs-up",
"delay": 30000,
"message": '"' + $('#settingQuestion option:selected').val() + '" set to "' + $('#settingAnswer option:selected').val() + '"'
},{
"type": "success"
});
console.log("Setting set successfully!");
enableSubmit();
enableRefresh();
}
//
//
function disableSubmit(buttonText) {
$('#submit').addClass('disabled').html(buttonText).off().click(function(event){event.preventDefault()});
}
function enableSubmit() {
$('#submit').removeClass('disabled').html('Update Setting').off().click(update);
}
function disableRefresh() {
$('#refresh').addClass('disabled').html('<span class="fas fa-spin fa-sync"></i>').off().click(function(event){event.preventDefault()});
}
function enableRefresh() {
$('#refresh').removeClass('disabled').html('<span class="fas fa-sync"></i>').off().click(refresh);
}
//
//
// the click listener for the refresh
function refresh() {
if (!$('#refresh').hasClass('disabled')) {
getGroups();
}
populateSettingQuestions();
}
</script>
<script>
// this is an objectified and clarified version of all of the groups properties available via the api
// https://developers.google.com/admin-sdk/groups-settings/v1/reference/groups
var settings = {
"whoCanViewGroup": {
"name": "Who has permission to view the group?",
"choices": [
{
"name": "Any Google Apps user",
"setting": "ANYONE_CAN_VIEW"
},
{
"name": "Anyone in the domain",
"setting": "ALL_IN_DOMAIN_CAN_VIEW"
},
{
"name": "All group members",
"setting": "ALL_MEMBERS_CAN_VIEW"
},
{
"name": "Only managers and owners",
"setting": "ALL_MANAGERS_CAN_VIEW"
}
]
},
"whoCanJoin": {
"name": "Who has permission to join the group?",
"choices": [
{
"name": "Anyone can join (even outside the domain)",
"setting": "ANYONE_CAN_JOIN"
},
{
"name": "Anyone in the domain",
"setting": "ALL_IN_DOMAIN_CAN_JOIN"
},
{
"name": "Non group members can request an invitation to join",
"setting": "CAN_REQUEST_TO_JOIN"
},
{
"name": "Users can be invited to join",
"setting": "INVITED_CAN_JOIN"
}
]
},
"whoCanViewMembership": {
"name": "Who has permission to view membership of the group?",
"choices": [
{
"name": "Anyone in the domain",
"setting": "ALL_IN_DOMAIN_CAN_VIEW"
},
{
"name": "All members",
"setting": "ALL_MEMBERS_CAN_VIEW"
},
{
"name": "Only managers and owners",
"setting": "ALL_MANAGERS_CAN_VIEW"
}
]
},
"whoCanAdd": {
"name": "Who has permission to directly add members to the group?",
"choices": [
{
"name": "All members",
"setting": "ALL_MEMBERS_CAN_ADD"
},
{
"name": "Only managers and owners",
"setting": "ALL_MANAGERS_CAN_ADD"
},
{
"name": "No one",
"setting": "NONE_CAN_ADD"
}
]
},
"whoCanInvite": {
"name": "Who has permission to invite members to the group?",
"choices": [
{
"name": "All members",
"setting": "ALL_MEMBERS_CAN_INVITE"
},
{
"name": "Only managers and owners",
"setting": "ALL_MANAGERS_CAN_INVITE"
},
{
"name": "No one",
"setting": "NONE_CAN_ADD"
}
]
},
"allowExternalMembers": {
"name": "Can users outside the domain view and join the group?",
"choices": [
{
"name": "Yes",
"setting": "true"
},
{
"name": "No",
"setting": "false"
}
]
},
"whoCanPostMessage": {
"name": "Who has permission to post messages to the group?",
"choices": [
{
"name": "Anyone (even outside the domain)",
"setting": "ANYONE_CAN_POST"
},
{
"name": "Anyone in the domain",
"setting": "ALL_IN_DOMAIN_CAN_POST"
},
{
"name": "Managers and group owners",
"setting": "ALL_MANAGERS_CAN_POST"
},
{
"name": "Any group member",
"setting": "ALL_MEMBERS_CAN_POST"
}
]
},
"allowWebPosting": {
"name": "Can users post from the web?",
"choices": [
{
"name": "Yes",
"setting": "true"
},
{
"name": "No",
"setting": "false"
}
]
},
"messageModerationLevel": {
"name": "How are messages moderated?",
"choices": [
{
"name": "All messages are sent to the group owner's email address for approval",
"setting": "MODERATE_ALL_MESSAGES"
},
{
"name": "All messages from non group members are sent to the group owner's email address for approval",
"setting": "MODERATE_NON_MEMBERS"
},
{
"name": "All messages from new members are sent to the group owner's email address for approval",
"setting": "MODERATE_NEW_MEMBERS"
},
{
"name": "No moderator approval is required",
"setting": "MODERATE_NONE"
}
]
},
"spamModerationLevel": {
"name": "How to handle moderation for messages detected as spam?",
"choices": [
{
"name": "Post the message to the group",
"setting": "ALLOW"
},
{
"name": "Send the message to the moderation queue",
"setting": "MODERATE"
},
{
"name": "Send the message to the moderation queue, but do not send notification to moderators",
"setting": "SILENTLY_MODERATE"
},
{
"name": "Immediately reject the message",
"setting": "REJECT"
}
]
},
"showInGroupDirectory": {
"name": "Show group in the domain's Google Groups directory?",
"choices": [
{
"name": "Yes",
"setting": "true"
},
{
"name": "No",
"setting": "false"
}
]
},
"includeInGlobalAddressList": {
"name": "Show group in the domain's email address directory?",
"choices": [
{
"name": "Yes",
"setting": "true"
},
{
"name": "No",
"setting": "false"
}
]
},
"membersCanPostAsTheGroup": {
"name": "Allow members to post using the group email address?",
"choices": [
{
"name": "Yes",
"setting": "true"
},
{
"name": "No",
"setting": "false"
}
]
},
"whoCanLeaveGroup": {
"name": "Who can leave the group?",
"choices": [
{
"name": "All members",
"setting": "ALL_MEMBERS_CAN_LEAVE"
},
{
"name": "Managers and owners",
"setting": "ALL_MANAGERS_CAN_LEAVE"
},
{
"name": "No one",
"setting": "NONE_CAN_LEAVE"
}
]
},
"whoCanContactOwner": {
"name": "Who can contact the owner of the group?",
"choices": [
{
"name": "Anyone",
"setting": "ANYONE_CAN_CONTACT"
},
{
"name": "Anyone in the domain",
"setting": "ALL_IN_DOMAIN_CAN_CONTACT"
},
{
"name": "All members",
"setting": "ALL_MEMBERS_CAN_CONTACT"
},
{
"name": "Managers and owners",
"setting": "ALL_MANAGERS_CAN_CONTACT"
}
]
}
}
// runs on page load, and when the refresh button is pressed.
// this goes through the object above and adds the possible "questions", or settings, to the dropdown.
function populateSettingQuestions() {
$('#settingQuestion').find('option').remove();
$('#settingAnswer').attr('disabled',true);
for (var i in settings) {
$('#settingQuestion').append('<option value="' + i + '">' + settings[i].name + '</option>');
}
populateSettingAnswers();
}
// when the "group" or "question" dropdown changes, we need to change the available "answers".
$('#groups, #settingQuestion').change(function() {
disableRefresh();
disableSubmit("Just a minute...");
$('#settingAnswer').attr('disabled',true).find('option').remove().append('<option selected>Loading...</option>');
populateSettingAnswers();
getQuestionSelectionAndColors();
});
// this only runs when the question changes (above).
// it uses the above object so that only the correct "answers" are available for the current "question"
function populateSettingAnswers() {
$('#settingAnswer').find('option').remove();
var selected = $('#settingQuestion option:selected').val();
var choices = settings[selected].choices;
for (var i in choices) {
$('#settingAnswer').append('<option value="' + choices[i].setting + '">' + choices[i].name + '</option>');
}
}
// this last set is a convenience to let the user know what the "current" setting (or "answer") is when they change the question.
function getQuestionSelectionAndColors() {
google.script.run.withSuccessHandler(selectCurrentSettingAnswer).withFailureHandler(handleError).getGroupSettings($('#groups option:selected').val());
}
// once getQuestionSelectionAndColors() runs, this will look at the current "question"
// and move the "answer" dropdown to have the current setting be the "selected" answer.
// it will also color every other setting besides the "selected" one green,
// to make it obvious which setting would be an update if selected.
// this seems to work in some browsers only.
// silly bootstrap.
function selectCurrentSettingAnswer(setting) {
var selected = $('#settingQuestion option:selected').val();
$('#settingAnswer').attr('disabled',false).val(setting[selected]).change();
$('#settingAnswer option').removeClass('text-success text-muted');
$('#settingAnswer option:not(:selected)').addClass('text-success');
$('#settingAnswer option:selected').addClass('text-muted');
enableRefresh();
enableSubmit();
}
</script>
</body>
</html>