Skip to content

Commit 55e6620

Browse files
committed
feat: convert to staff or partner
1 parent 4e2c59b commit 55e6620

File tree

3 files changed

+88
-6
lines changed

3 files changed

+88
-6
lines changed

README.md

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,19 @@ for more information.
2525
bin/create.sh USER [OPTIONS]
2626
```
2727

28-
* `USER` is the username (sans domain) to create
29-
* `OPTIONS` is a list of options for [GAM user create](https://github.com/taers232c/GAMADV-XTD3/wiki/Users#create-a-user)
28+
- `USER` is the username (sans domain) to create
29+
- `OPTIONS` is a list of options for [GAM user create](https://github.com/taers232c/GAMADV-XTD3/wiki/Users#create-a-user)
30+
31+
## Convert a user
32+
33+
**Usage:**
34+
35+
```bash
36+
bin/convert.sh USER TYPE
37+
```
38+
39+
- `USER` is the username (sans domain) to convert
40+
- `TYPE` is either `STAFF` to convert the user to a staff member, or `PARTNER` to conver the user to a partner.
3041

3142
## Offboarding a user
3243

@@ -36,9 +47,9 @@ bin/create.sh USER [OPTIONS]
3647
bin/offboard.sh USER [ALIAS]
3748
```
3849

39-
* `USER` is the username (sans domain) to offboard
40-
* `ALIAS` is optional, and is a username (sans domain) that will get an alias
41-
added for the offboarded `USER`
50+
- `USER` is the username (sans domain) to offboard
51+
- `ALIAS` is optional, and is a username (sans domain) that will get an alias
52+
added for the offboarded `USER`
4253

4354
Read more about the [offboarding process in Compiler's notes](https://docs.google.com/document/d/1UEwQzJZyJEkRs3PRwOi0-KXwBFne70am4Nk9-_qYItE/edit#heading=h.liqi1hwxykhs).
4455

@@ -48,4 +59,4 @@ This script creates a local backup of `USER`'s inbox; a separate script can be r
4859
bin/archive-gmail-backup.sh USER
4960
```
5061

51-
* `USER` is the account in compiler.la (sans domain) with a local backup to archive
62+
- `USER` is the account in compiler.la (sans domain) with a local backup to archive

bin/common.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ DOMAIN="compiler.la"
66
# Compiler's archive account
77
ARCHIVE="archive@$DOMAIN"
88
# Compiler groups
9+
PARTNERS="partners@$DOMAIN"
10+
STAFF="staff@$DOMAIN"
911
TEAM="team@$DOMAIN"
1012

1113
# prints a simple timestamp HH:mm:ss
@@ -31,3 +33,18 @@ archive_user_exists() {
3133
exit 1
3234
fi
3335
}
36+
37+
user_in_group() {
38+
user="$1"
39+
group="$2"
40+
41+
gam print groups member "$user" | grep "$group" &> /dev/null
42+
}
43+
44+
user_is_partner() {
45+
user_in_group "$1" "$PARTNERS"
46+
}
47+
48+
user_is_staff() {
49+
user_in_group "$1" "$STAFF"
50+
}

bin/convert.sh

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/usr/bin/env bash
2+
set -u
3+
4+
SCRIPT_DIR=$(builtin cd "$(dirname ${BASH_SOURCE[0]})" && builtin pwd)
5+
6+
source "${SCRIPT_DIR}/common.sh"
7+
8+
__usage="
9+
Usage: $(basename $0) USER TYPE
10+
11+
Arguments:
12+
USER The account in $DOMAIN (sans domain) to convert
13+
TYPE The type of conversion [STAFF or PARTNER]
14+
"
15+
16+
# print usage for -? or -h or --help
17+
if [[ "$#" -lt 1 || "$1" =~ ^(-\?|-h|--help)$ ]]; then
18+
echo "$__usage"
19+
exit 0
20+
fi
21+
22+
# the full account name to convert
23+
ACCOUNT="$1@$DOMAIN"
24+
25+
# verify $ACCOUNT exists before continuing
26+
if ! user_exists $ACCOUNT; then
27+
echo_ts "Account $ACCOUNT does not exist, stopping"
28+
exit 1
29+
else
30+
echo_ts "Account $ACCOUNT exists, continuing..."
31+
fi
32+
33+
TYPE="$2"
34+
35+
if echo "$TYPE" | grep -i staff &> /dev/null; then
36+
if user_is_staff "$ACCOUNT"; then
37+
echo_ts "Account $ACCOUNT is already a member of $STAFF"
38+
exit 1
39+
fi
40+
GROUP="$STAFF"
41+
elif echo "$TYPE" | grep -i partner &> /dev/null; then
42+
if user_is_partner "$ACCOUNT"; then
43+
echo_ts "Account $ACCOUNT is already a member of $PARTNERS"
44+
exit 1
45+
fi
46+
GROUP="$PARTNERS"
47+
else
48+
echo_ts "Unsupported conversion type: $TYPE"
49+
exit 1
50+
fi
51+
52+
echo_ts "Converting $ACCOUNT to $TYPE..."
53+
54+
gam user $ACCOUNT add groups member $GROUP

0 commit comments

Comments
 (0)