Updating email addresses from all users

As we have a consortium and sometimes users are changing institutes and also their mail addresses, we need to be able to update them automatically.
The best way would be, that it is updated when the user is signing in.

Could that be done and if so, how?

I sent you this script some months ago:

You can run it as a cron job and it should sync the emails (mostly untested).

Hi Adrian, where the script need to be executed? I run command python sync_user_email.py but obtain follow error:

Traceback (most recent call last):
  File "sync_user_email.py", line 23, in <module>
    with make_app().app_context():
  File "/usr/lib/python2.7/site-packages/indico/web/flask/app.py", line 347, in make_app
    app.config['INDICO'] = load_config(only_defaults=testing, override=config_override)
  File "/usr/lib/python2.7/site-packages/indico/core/config.py", line 200, in load_config
    path = get_config_path()
  File "/usr/lib/python2.7/site-packages/indico/core/config.py", line 146, in get_config_path
    'move/symlink the config in one of the following locations: {}'.format(', '.join(paths)))
Exception: No indico config found. Point the INDICO_CONFIG env var to your config file or move/symlink the config in one of the following locations: /root/.indico.conf, /etc/indico.conf

Thanks,

Simone

Point the INDICO_CONFIG env var to your config file or move/symlink the config in one of the following locations: /root/.indico.conf, /etc/indico.conf

The problem is that you are running this script as root, and not as the indico user where it will just work…

PS: I guess you are not using the standard setup structure since you have Indico in your system environment instead of the /opt/indico/.venv virtualenv? In any case, you need to run it as the user used for Indico, and if you do not have a ~/.indico.conf symlink pointing to your actual indico.conf, then you need to use the INDICO_CONFIG env var to point to it.

Yes, I run the script in a test environment … and also in a wrong configuration as you have notice! I’m sorry … thanks for your suggestion!

I follow your suggestions, so I run the script under indico user and in .venv virtualenv where I have .indico.conf but I obtain this:

(.venv)[indico@indicohost2 ~]$ python2.7 sync_user_email.py 
/opt/indico/.venv/lib/python2.7/site-packages/indico/core/auth.py:72: UserWarning: There is no default group provider but you have providers with group support. This will break legacy ACLs referencing external groups and room ACLs will use local group IDs.
  warn('There is no default group provider but you have providers with group support. '
Traceback (most recent call last):
  File "sync_user_email.py", line 24, in <module>
    for user in User.query.filter_by(is_deleted=False):
NameError: name 'User' is not defined

ah, it’s missing some imports. probably i only tested it in indico shell back then…

from indico.modules.users import User
from indico.modules.users.models.emails import UserEmail

PS: When pasting code or shell output, please wrap it in a triple-backtick fence so it’s correctly displayed here:

```
your stuff here
```

ok!! some else import missing?

Traceback (most recent call last):
  File "sync_user_email.py", line 28, in <module>
    db.session.commit()
NameError: name 'db' is not defined

I add from indico.web.flask.app import db

from indico.core.db import db

Adrian I ran the script without any (visible) error but the email is always the same on a couple of users who changed their address a week ago on our Active Directory. I tried to restart the Indico services and also the command indico user search -e ‘@’ --substring returns old values. any ideas?

I’ve never used the script myself, so I’d add some debug prints to see if it returns early for example…