Add many users to a group

I have a request to set up a group with about 100 existing indico users. Is there a way to do this in bulk, from the command line or the gui, or does it have to be done manually? We do not use LDAP, only local indico accounts.

Thanks,

Chris

1 Like

This could easily be done from indico shell if you have some criteria by which to find those users.

group = LocalGroup.get(1234)  # put the group ID here instead of 1234
users = User.query.filter(...).all()  # find some suitable criteria
group.members |= set(users)
db.session.commit()

A possible filter could be User.email.in_('foo@bar.com,abc@example.com'.split(',')) for a comma-separated list of email addresses.

1 Like

Thanks. Indico shell doesn’t recognise “User.email.in_”. This is with version 2.1.6. Are the paramenters to filter documented somewhere?

Regards,

Chris

Ah sorry, forgot that email is “special” because a user can have multiple emails.

Use this instead:

db.or_(User.all_emails.contains(email) for email in 'your,email,list'.split(','))

Thanks. That works well. I needed LocalGroup.find_first(name=“groupname”) to get the group id and then it was very simple.

Regards,

Chris

In that case you can use the find_first() result; it’s already the LocalGroup object. No need to get it again by ID afterwards.