-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgroup.py
67 lines (52 loc) · 2.35 KB
/
group.py
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
"""
Scripts to manage groups and their membership.
"""
from typing import Optional
from sqlalchemy.orm import Session
from srcf.database.schema import Member, Society
from srcf.mail import SYSADMINS
from .utils import confirm, entrypoint, error
from ..email import send
from ..tasks import membership
@entrypoint
def grant(sess: Session, member: Member, society: Society, actor: Optional[Member]):
"""
Add a member to a group account's admins.
Usage: {script} MEMBER SOCIETY [ACTOR]
An actor, if given, will appear in user-facing emails as the person who requested the change.
"""
if member.crsid in society.admin_crsids:
error("Warning: {} is already an admin of {}".format(member.crsid, society.society))
if not actor:
error("Warning: no actor given")
elif actor.crsid not in society.admin_crsids:
error("Warning: actor {} is not an admin of {}".format(actor.crsid, society.society))
confirm("Add {} to {}?".format(member.name, society.description))
if membership.add_society_admin(sess, member, society, actor):
send(SYSADMINS, "scripts/group_grant.j2", {"member": member, "society": society})
@entrypoint
def revoke(sess: Session, member: Member, society: Society, actor: Optional[Member]):
"""
Remove a member from a group account's admins.
Usage: {script} MEMBER SOCIETY [ACTOR]
An actor, if given, will appear in user-facing emails as the person who requested the change.
"""
if member.crsid not in society.admin_crsids:
error("Warning: {} is not an admin of {}".format(member.crsid, society.society))
elif society.admin_crsids == {member.crsid}:
error("Warning: removing the only remaining admin")
if not actor:
error("Warning: no actor given")
elif actor.crsid not in society.admin_crsids:
error("Warning: actor {} is not an admin of {}".format(actor.crsid, society.society))
confirm("Remove {} from {}?".format(member.name, society.description))
if membership.remove_society_admin(sess, member, society, actor=actor):
send(SYSADMINS, "scripts/group_revoke.j2", {"member": member, "society": society})
@entrypoint
def delete(sess: Session, society: Society):
"""
Delete a group account.
Usage: {script} SOCIETY
"""
confirm("Delete {}?".format(society.description))
membership.delete_society(sess, society)