forked from CMS/memberPlumbing
ucsAccounts: Add groups for certifications, door access, membership level, and volunteer type
This commit is contained in:
parent
deddf1605a
commit
852e8a51e8
@ -1,20 +1,40 @@
|
||||
#!/usr/bin/env python3
|
||||
import random
|
||||
import re
|
||||
import subprocess
|
||||
import string
|
||||
|
||||
from common import *
|
||||
|
||||
LDAP_BASE = "cn=users,dc=sawtooth,dc=claremontmakerspace,dc=org"
|
||||
GROUP_BASE = "cn=groups,dc=sawtooth,dc=claremontmakerspace,dc=org"
|
||||
GROUPS_REGEX = "|".join(['Certified: .*', 'Access .*\?', 'CMS .*', 'Volunteer: .*'])
|
||||
RAND_PW_LEN = 20
|
||||
|
||||
def makeGroups(members):
|
||||
groups = [key.replace(':', '.').replace('?', '')
|
||||
for key in members[0].keys()
|
||||
if re.match(GROUPS_REGEX, key) is not None]
|
||||
for group in groups:
|
||||
subprocess.call(["udm", "groups/group", "create",
|
||||
"--position", GROUP_BASE,
|
||||
"--set", "name=" + group])
|
||||
|
||||
def makeSets(props):
|
||||
return sum([["--set", key + "=" + value]
|
||||
for key, value in props.items()], [])
|
||||
|
||||
def makeAppendGroups(member):
|
||||
groups = [key.replace(':', '.').replace('?', '')
|
||||
for key, value in member.items()
|
||||
if re.match(GROUPS_REGEX, key) is not None and value != '']
|
||||
return sum([["--append", "groups=cn=" + group + ',' + GROUP_BASE]
|
||||
for group in groups], [])
|
||||
|
||||
def main():
|
||||
members = getMembershipworksData(['members', 'staff'],
|
||||
"lvl,phn,eml,lbl,nam,end,_id")
|
||||
makeGroups(members)
|
||||
|
||||
for member in members:
|
||||
randomPass = ''.join(random.choice(string.ascii_letters + string.digits)
|
||||
@ -36,8 +56,6 @@ def main():
|
||||
"employeeNumber": member["Account ID"],
|
||||
#"employeeType": "", # Employee type
|
||||
|
||||
#"groups": "", # Groups
|
||||
|
||||
"homedrive": "H:", # Windows home drive
|
||||
"sambahome": "\\\\ucs\\" + username, # Windows home path
|
||||
"profilepath": "%LOGONSERVER%\\%USERNAME%\\windows-profiles\\default", # Windows profile directory
|
||||
@ -64,7 +82,8 @@ def main():
|
||||
|
||||
subprocess.call(["udm", "users/user", "modify",
|
||||
"--dn", "uid=" + username + "," + LDAP_BASE]
|
||||
+ makeSets(props))
|
||||
+ makeSets(props)
|
||||
+ makeAppendGroups(member))
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
Loading…
Reference in New Issue
Block a user