Skip to content

Commit

Permalink
update command to take specific ad group titles
Browse files Browse the repository at this point in the history
  • Loading branch information
claire-peters committed Feb 1, 2024
1 parent 10839ad commit 1bf8b47
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions coldfront/plugins/ldap/management/commands/id_add_new_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,24 @@
class Command(BaseCommand):
help = 'Identify AD Groups that do not have a corresponding ColdFront Project and add them.'

def handle(self, *args, **options):
def add_arguments(self, parser):
parser.add_argument(
'--groups',
dest='groups',
default='*_lab,*_l3',
help='specific groups to add, with commas separating the names',
)

def handle(self, *args, **kwargs):
groups = groups = kwargs['groups']
if groups:
groups = groups.split(",")
# compare projects in AD to projects in coldfront
ldap_conn = LDAPConn()
project_titles = [project.title for project in Project.objects.all()]
# get all AD groups that have a manager and a name ending in _lab or _l3
ad_groups = ldap_conn.search_groups({
'sAMAccountName': ['*_lab', '*_l3'],
'sAMAccountName': groups,
'managedBy': '*'
}, attributes=['sAMAccountName'])
ad_group_names = [group['sAMAccountName'][0] for group in ad_groups] # get all AD group names
Expand Down

0 comments on commit 1bf8b47

Please sign in to comment.