User

Todo

Docstrings (module, models, utilities)

Models

class indico.modules.users.models.users.NameFormat

Bases: indico.util.struct.enum.RichIntEnum

f_last = 3
f_last_upper = 7
first_last = 0
first_last_upper = 4
last_f = 2
last_f_upper = 6
last_first = 1
last_first_upper = 5
class indico.modules.users.models.users.PersonMixin

Bases: object

Add convenience properties and methods to person classes.

Assumes the following attributes exist: * first_name * last_name * title

display_full_name

Return the full name using the user’s preferred name format.

full_name

Return the person’s name in ‘Firstname Lastname’ notation.

get_full_name(last_name_first=True, last_name_upper=True, abbrev_first_name=True, show_title=False, _show_empty_names=False)

Return the person’s name in the specified notation.

Note: Do not use positional arguments when calling this method. Always use keyword arguments!

Parameters:
  • last_name_first – if “lastname, firstname” instead of “firstname lastname” should be used
  • last_name_upper – if the last name should be all-uppercase
  • abbrev_first_name – if the first name should be abbreviated to use only the first character
  • show_title – if the title of the person should be included
name

Return the person’s name in ‘Firstname Lastname’ notation.

title

The title of the user

class indico.modules.users.models.users.User(**kwargs)

Bases: indico.modules.users.models.users.PersonMixin, flask_sqlalchemy.Model

Indico users

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

address

the address of the user

affiliation

the affiliation of the user

all_emails

all emails of the user. read-only; use it only for searching by email! also, do not use it between modifying email or secondary_emails and a session expire/commit!

api_key

the active API key of the user

as_avatar
as_legacy
as_principal

The serializable principal identifier of this user

attachments
avatar_css
can_be_modified(user)

If this user can be modified by the given user

email

the primary email address of the user

event_notes_revisions
external_identities

The external identities of the user

favorite_categories

the users’s favorite categories

favorite_users

the users’s favorite users

first_name

the first name of the user

get_full_name(*args, **kwargs)
static get_system_user()
id

the unique id of the user

identities

the identities used by this user

in_blocking_acls
in_category_acls
in_contribution_acls
in_event_acls
is_admin

if the user is an administrator with unrestricted access to everything

is_blocked

if the user has been blocked

is_deleted

if the user is deleted (e.g. due to a merge)

is_group = False
is_network = False
is_pending

if the user is pending (e.g. never logged in, only added to some list)

is_single_person = True
is_system

if the user is the default system user

iter_identifiers(check_providers=False, providers=None)

Yields (provider, identifier) tuples for the user.

Parameters:
  • check_providers – If True, providers are searched for additional identifiers once all existing identifiers have been yielded.
  • providers – May be a set containing provider names to get only identifiers from the specified providers.
last_name

the last/family name of the user

local_identities

The local identities of the user

local_identity

The main (most recently used) local identity

locator

Defines a smart locator property.

This behaves pretty much like a normal read-only property and the decorated function should return a dict containing the necessary data to build a URL for the object.

This decorator should usually be applied to a method named locator as this name is required for get_locator to find it automatically when just passing the object.

If you need more than one locator, you can define it like this:

@locator_property
def locator(self):
    return {...}

@locator.other
def locator(self):
    return {...}

The other locator can then be accessed by passing obj.locator.other to the code expecting an object with a locator.

make_email_primary(email)

Promotes a secondary email address to the primary email address

Parameters:email – an email address that is currently a secondary email
merged_into_id

the id of the user this user has been merged into

merged_into_user

the user this user has been merged into

old_api_keys

the previous API keys of the user

paper_competences
phone

the phone number of the user

principal_order = 0
principal_type = 1
secondary_emails

any additional emails the user might have

secondary_local_identities

The local identities of the user except the main one

settings

Returns the user settings proxy for this user

suggested_categories

the user’s category suggestions

synced_fields

The fields of the user whose values are currently synced.

This set is always a subset of the synced fields define in synced fields of the idp in ‘indico.conf’.

synced_values

The values from the synced identity for the user.

Those values are not the actual user’s values and might differ if they are not set as synchronized.

synchronize_data(refresh=False)

Synchronize the fields of the user from the sync identity.

This will take only into account synced_fields.

Parameters:refresh – bool – Whether to refresh the synced identity with the sync provider before instead of using the stored data. (Only if the sync provider supports refresh.)
class indico.modules.users.models.users.UserTitle

Bases: indico.util.struct.enum.RichIntEnum

dr = 4
mr = 1
mrs = 3
ms = 2
none = 0
prof = 5
indico.modules.users.models.users.format_display_full_name(user, obj)
indico.modules.users.models.users.syncable_fields = {u'affiliation': lu'affiliation', u'first_name': lu'first name', u'last_name': lu'family name', u'phone': lu'phone number', u'address': lu'address'}

Fields which can be synced as keys and a mapping to a more human readable version, used for flashing messages

class indico.modules.users.models.affiliations.UserAffiliation(**kwargs)

Bases: flask_sqlalchemy.Model

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

id

the unique id of the affiliations

name

the affiliation

user_id

the id of the associated user

class indico.modules.users.models.emails.UserEmail(**kwargs)

Bases: flask_sqlalchemy.Model

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

email

the email address

id

the unique id of the email address

is_primary

if the email is the user’s primary email

is_user_deleted

if the user is marked as deleted (e.g. due to a merge). DO NOT use this flag when actually deleting an email

user_id

the id of the associated user

class indico.modules.users.models.suggestions.SuggestedCategory(**kwargs)

Bases: flask_sqlalchemy.Model

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

category
category_id
is_ignored
classmethod merge_users(target, source)

Merge the suggestions for two users.

Parameters:
  • target – The target user of the merge.
  • source – The user that is being merged into target.
score
user_id
class indico.modules.users.models.settings.UserSetting(**kwargs)

Bases: indico.core.settings.models.base.JSONSettingsBase, flask_sqlalchemy.Model

User-specific settings

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

id
module
name
user
user_id
value
class indico.modules.users.models.settings.UserSettingsProxy(module, defaults=None, strict=True, acls=None, converters=None)

Bases: indico.core.settings.proxy.SettingsProxyBase

Proxy class to access user-specific settings for a certain module

delete(user, *args, **kwargs)

Deletes settings.

Parameters:
  • user{'user': user} or {'user_id': id}
  • names – One or more names of settings to delete
delete_all(user, *args, **kwargs)

Deletes all settings.

Parameters:user{'user': user} or {'user_id': id}
get(user, *args, **kwargs)

Retrieves the value of a single setting.

Parameters:
  • user{'user': user} or {'user_id': id}
  • name – Setting name
  • default – Default value in case the setting does not exist
Returns:

The settings’s value or the default value

get_all(user, *args, **kwargs)

Retrieves all settings

Parameters:
  • user{'user': user} or {'user_id': id}
  • no_defaults – Only return existing settings and ignore defaults.
Returns:

Dict containing the settings

query

Returns a query object filtering by the proxy’s module.

set(user, *args, **kwargs)

Sets a single setting.

Parameters:
  • user{'user': user} or {'user_id': id}
  • name – Setting name
  • value – Setting value; must be JSON-serializable
set_multi(user, *args, **kwargs)

Sets multiple settings at once.

Parameters:
  • user{'user': user} or {'user_id': id}
  • items – Dict containing the new settings
indico.modules.users.models.settings.user_or_id(f)

Operations

indico.modules.users.operations.create_user(email, data, identity=None, settings=None, other_emails=None, from_moderation=True)

Create a new user.

This may also convert a pending user to a proper user in case the email address matches such a user.

Parameters:
  • email – The primary email address of the user.
  • data – The data used to populate the user.
  • identity – An Identity to associate with the user.
  • settings – A dict containing user settings.
  • other_emails – A set of email addresses that are also used to check for a pending user. They will also be added as secondary emails to the user.
  • from_moderation – Whether the user was created through the moderation process or manually by an admin.

Utilities

indico.modules.users.util.get_admin_emails()

Get the email addresses of all Indico admins

indico.modules.users.util.get_color_for_username(username)
indico.modules.users.util.get_linked_events(user, dt, limit=None)

Get the linked events and the user’s roles in them

Parameters:
  • user – A User
  • dt – Only include events taking place on/after that date
  • limit – Max number of events

Gets the related categories of a user for the dashboard

indico.modules.users.util.get_suggested_categories(user)

Gets the suggested categories of a user for the dashboard

indico.modules.users.util.get_user_by_email(email, create_pending=False)

finds a user based on his email address.

Parameters:
  • email – The email address of the user.
  • create_pending – If True, this function searches for external users and creates a new pending User in case no existing user was found.
Returns:

A User instance or None if not exactly one user was found.

indico.modules.users.util.merge_users(source, target, force=False)

Merge two users together, unifying all related data

Parameters:
  • source – source user (will be set as deleted)
  • target – target user (final)
indico.modules.users.util.search_users(exact=False, include_deleted=False, include_pending=False, external=False, allow_system_user=False, **criteria)

Searches for users.

Parameters:
  • exact – Indicates if only exact matches should be returned. This is MUCH faster than a non-exact saerch, especially when searching external users.
  • include_deleted – Indicates if also users marked as deleted should be returned.
  • include_pending – Indicates if also users who are still pending should be returned.
  • external – Indicates if identity providers should be searched for matching users.
  • allow_system_user – Whether the system user may be returned in the search results.
  • criteria – A dict containing any of the following keys: first_name, last_name, email, affiliation, phone, address
Returns:

A set of matching users. If external was set, it may contain both IdentityInfo objects for external users not yet in Indico and User objects for existing users.

indico.modules.users.util.serialize_user(user)

Serialize user to JSON-like object

class indico.modules.users.ext.ExtraUserPreferences(user)

Bases: object

Defines additional user preferences

To use this class, subclass it and override defaults, fields and save to implement your custom logic.

extend_defaults(defaults)

Adds values to the FormDefaults.

extend_form(form_class)

Creates a subclass of the form containing the extra field

fields = {}

a dict containing all the fields that should be added to the user preferences

load()

Returns a dict with the current values for the user

process_form_data(data)

Processes and saves submitted data.

This modifies data so the core code doesn’t receive any extra data it doesn’t expect.

save(data)

Saves the updated settings