Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions dim/dim/ldap_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,24 @@ def sync_users(ldap: LDAP, deletion_threshold: int = -1, ignore_deletion_thresho
check_deletion_threshold(User, deletion_threshold)


@time_function
@transaction
def add_user(username: str):
try:
_ = User.query.filter(User.username == username).one()
log_stdout('User %s already present' % username)
except:
try:
ldap = LDAP()
ldap_user = ldap.users(f'(o={username})')[0]
db.session.add(ldap_user)
log_stdout('Added user %s' % username)
ldap_user.register()
log_stdout('Added user %s to user-group all_users' % username)
except:
log_stdout('User %s not in LDAP' % username)


@time_function
@transaction
def ldap_sync(ignore_deletion_threshold: bool = False, cleanup_department_groups: bool = False):
Expand Down
8 changes: 8 additions & 0 deletions dim/dim/manage_dim.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ def update_validity():
dim.models.db.session.commit()


@manage_dim.cli.command('ldap_add_user')
@click.option('-u', '--username')
@click.option('-n', '--dry-run', '--noop', 'dryrun', is_flag=True)
def ldap_sync(dryrun: bool, username: str):
'''Add User from LDAP'''
dim.ldap_sync.add_user(dryrun=dryrun, username=username)


@manage_dim.cli.command('ldap_sync')
@click.option('-n', '--dry-run', '--noop', 'dryrun', is_flag=True)
@click.option('-f', '--ignore-deletion-threshold', 'ignore_deletion_threshold', is_flag=True)
Expand Down