add cli for expiring members

This commit is contained in:
Rio Liu 2021-10-30 12:23:57 -04:00
parent 67a7cc2d05
commit 45e30b23ba
2 changed files with 16 additions and 1 deletions

View File

@ -187,3 +187,18 @@ def delete(username):
click.confirm(f"Are you sure you want to delete {username}?", abort=True)
resp = http_delete(f'/api/members/{username}')
handle_stream_response(resp, DeleteMemberTransaction.operations)
@members.command(short_help="Check for and mark expired members")
@click.option('--dry-run', is_flag=True, default=False)
def expire(dry_run):
resp = http_post(f'/api/members/expire?dry_run={dry_run and "yes" or "no"}')
result = handle_sync_response(resp)
if len(result) > 0:
if dry_run:
click.echo("The following members will be marked as expired:")
else:
click.echo("The following members has been marked as expired:")
for usernmae in result:
click.echo(f" * {username}")

View File

@ -259,7 +259,7 @@ class LDAPService:
query.append(f'term={last_term}')
query.append(f'nonMemberTerm={last_term}')
query = '(!(|(' + ')('.join(query) + ')))'
query = '(!(|(shadowExpire=1)(' + ')('.join(query) + ')))'
conn = self._get_ldap_conn()
conn.search(