User management

_images/users.png

Main module

User (aka character), corporation, and alliance management

sni.user.user.ensure_alliance(alliance_id: int) → sni.user.models.Alliance[source]

Ensures that an alliance exists, and returns it. It it does not, creates it by fetching relevant data from the ESI.

sni.user.user.ensure_autogroup(name: str) → sni.user.models.Group[source]

Ensured that an automatically created group exists. Automatic groups are owned by root.

sni.user.user.ensure_corporation(corporation_id: int) → sni.user.models.Corporation[source]

Ensures that a corporation exists, and returns it. It it does not, creates it by fetching relevant data from the ESI.

sni.user.user.ensure_user(character_id: int) → sni.user.models.User[source]

Ensures that a user (with a valid ESI character ID) exists, and returns it. It it does not, creates it by fetching relevant data from the ESI. Also creates the character’s corporation and alliance (if applicable).

Database models

Models

class sni.user.models.Alliance(*args, **values)[source]

Bases: mongoengine.document.Document

EVE alliance database model.

SCHEMA_VERSION = 3

Latest schema version for this collection

_version

Schema version of this document

alliance_id

Alliance id (according to the ESI)

alliance_name

Self explanatory

authorized_to_login

Wether the members of this alliance are allowed to login to SNI. See sni.uac.uac.is_authorized_to_login().

property ceo

Returns the ceo of the executor corporation.

coalitions() → List[sni.user.models.Coalition][source]

Returns the list of coalition this alliance is part of.

Todo

Paginate the results

cumulated_mandatory_esi_scopes() → Set[sni.esi.scope.EsiScope][source]

Returns the list (although it really is a set) of all the ESI scopes required by this alliance, and all the coalitions this alliance belongs to.

property executor

Returns the alliance’s executor corporation as a sni.user.Corporation object.

executor_corporation_id

Id of the executor of this alliance

mandatory_esi_scopes

Mandatory ESI scopes for the members of this alliance

ticker

Ticker of the alliance

updated_on

Timestamp of the last update of this document

user_iterator() → Iterator[sni.user.models.User][source]

Returns an iterator over all the members of this alliance, according to the database. This may not be up to date with the ESI.

users() → List[sni.user.models.User][source]

Return the member list of this alliance, according to the database. This may not be up to date with the ESI.

class sni.user.models.Coalition(*args, **values)[source]

Bases: mongoengine.document.Document

EVE coalition. Coalitions are not formally represented in EVE, so they have to be created manually. An alliance can be part of multiple coalitions.

SCHEMA_VERSION = 6

Latest schema version for this collection

_version

Schema version of this document

authorized_to_login

Wether the members of this coalition are allowed to login to SNI. See sni.uac.uac.is_authorized_to_login().

coalition_name

Name of the coalition

created_on

Timestamp of the creation of this document

mandatory_esi_scopes

Mandatory ESI scopes for the members of this coalition

member_alliances

List of references to the member alliances (NOT users, for that, see sni.user.models.Coalition.users() and sni.user.models.Coalition.user_iterator().

member_corporations

Corporations that are direct members of this coalition (i.e. not through an alliance)

ticker

Ticker of the coalition

updated_on

Timestamp of the last update of this document

user_iterator() → Iterator[sni.user.models.User][source]

Returns an iterator over all the members of this coalition.

users() → List[sni.user.models.User][source]

Return the member list of this coalition.

class sni.user.models.Corporation(*args, **values)[source]

Bases: mongoengine.document.Document

EVE corporation database model.

SCHEMA_VERSION = 3

Latest schema version for this collection

_version

Schema version of this document

alliance

Optional reference to the alliance this corporation belongs to

authorized_to_login

Wether the members of this corporation are allowed to login to SNI. See sni.uac.uac.is_authorized_to_login().

property ceo

Returns the corporation’s ceo as a sni.user object.

ceo_character_id

Character id (according to the ESI) of the CEO. See also sni.user.models.Corporation.ceo().

coalitions() → List[sni.user.models.Coalition][source]

Returns the list of coalition this user is part of.

corporation_id

Id of the corporation (according to the ESI)

corporation_name

Name of the corporation

cumulated_mandatory_esi_scopes() → Set[sni.esi.scope.EsiScope][source]

Returns the list (although it really is a set) of all the ESI scopes required by this corporation, alliance, and all the coalitions this corporation is part of.

guest_iterator() → Iterator[sni.user.models.User][source]

Returns an iterator over all the guests of this corporation, according to the database. A guest is a member with a clearance level of -1.

guests() → List[sni.user.models.User][source]

Return the guest list of this corporation, according to the database. A guest is a member with a clearance level of -1.

mandatory_esi_scopes

Mandatory ESI scopes for the members of this corporation

ticker

Ticker of the corporation

updated_on

Timestamp of the last update of this document

user_iterator() → Iterator[sni.user.models.User][source]

Returns an iterator over all the members of this corporation, according to the database. This may not be up to date with the ESI.

users() → List[sni.user.models.User][source]

Return the member list of this corporation, according to the database. This may not be up to date with the ESI.

class sni.user.models.Group(*args, **values)[source]

Bases: mongoengine.document.Document

Group model. A group is simply a collection of users.

SCHEMA_VERSION = 4

Latest schema version for this collection

_version

Schema version of this document

authorized_to_login

Wether the members of this alliance are allowed to login to SNI. See sni.uac.uac.is_authorized_to_login().

created_on

Timestamp of the creation of this document

description

Self explanatory

discord_role_id

Id of the corresponding discord role

group_name

Name of the group

is_autogroup

Wether this group was created automatically by SNI (e.g. group of a corporation)

map_to_discord

Wether this group should be mapped as a Discord role

map_to_teamspeak

Wether this group should be mapped as a Teamspeak group

members

Member list

owner

Owner of the group. Can be None.

teamspeak_sgid

Teamspeak group id, if applicable

updated_on

Timestamp of the last update of this document

class sni.user.models.User(*args, **values)[source]

Bases: mongoengine.document.Document

User model.

A user corresponds to a single EVE character.

SCHEMA_VERSION = 3

Latest schema version for this collection

_version

Schema version of this document

property alliance

Returns the alliance the user is part of, if any

authorized_to_login

Wether the members of this alliance are allowed to login to SNI. See sni.uac.uac.is_authorized_to_login().

character_id

Character id (according to the ESI)

character_name

Character name

clearance_level

Clearance level of this user. See sni.uac.clearance.

coalitions() → List[sni.user.models.Coalition][source]

Returns the list of coalition this user is part of.

corporation

Corporation this character belongs to, if applicable

created_on

Timestamp of the creation of this document

cumulated_mandatory_esi_scopes() → Set[sni.esi.scope.EsiScope][source]

Returns the list (although it really is a set) of all the ESI scopes required by the corporation, alliance, and all the coalitions the user is part of.

discord_user_id

Discord user id associated to this user, if applicable

is_ceo_of_alliance() → bool[source]

Tells wether the user is the ceo of its corporation.

is_ceo_of_corporation() → bool[source]

Tells wether the user is the ceo of its corporation.

teamspeak_cldbid

Teamspeak user id associated to this user, if applicable

property tickered_name

Returns the user’s character name with its alliance ticker as a prefix. If the user is not in an alliance, then the corporation’s ticker is used instead. If the user is not in any coproration (e.g. root), then there is no prefix.

updated_on

Timestamp of the last update of this document

Jobs

User and eve player structure management jobs.

sni.user.jobs.ensure_alliance_members(alliance: sni.user.models.Alliance)[source]

Makes sure all members of a given alliance exist in the database.

sni.user.jobs.ensure_alliances_members()[source]

Iterates through all alliances (in the database) and makes sure their member corporations exist in the database. See sni.user.jobs.ensure_alliance_members().

sni.user.jobs.ensure_corporation_members(corporation: sni.user.models.Corporation)[source]

Ensure that all members of a corporation exist in the database.

sni.user.jobs.ensure_corporations_members()[source]

Iterates through all corporations (in the database) and makes sure their members exist in the database. See sni.user.jobs.ensure_corporation_members().

sni.user.jobs.update_alliance_autogroup(alliance: sni.user.models.Alliance)[source]

Updates an alliance autogroup.

sni.user.jobs.update_alliance_autogroups()[source]

Resets all the alliance autogroup. Instead of querying the ESI, it queries the database for all user in the corporations in that alliance, assuming the user and corporation records are up-to-date.

sni.user.jobs.update_alliance_from_esi(alliance: sni.user.models.Alliance)[source]

Updates an alliance’s properties from the ESI.

sni.user.jobs.update_alliances_from_esi()[source]

Updates the alliances properties from the ESI.

sni.user.jobs.update_coalition_autogroup(coalition: sni.user.models.Coalition)[source]

Resets the coalition autogroup. Instead of querying the ESI, it queries the database for all user in that coalition, assuming the user, coalition, and alliance records are up-to-date.

sni.user.jobs.update_coalition_autogroups()[source]

Resets the coalition autogroups.

sni.user.jobs.update_corporation_autogroup(corporation: sni.user.models.Corporation)[source]

Resets the corporations autogroup. Instead of querying the ESI, it queries the database for all user in that corporation, assuming the user records are up-to-date.

sni.user.jobs.update_corporation_autogroups()[source]

Resets the corporations autogroups.

sni.user.jobs.update_corporation_from_esi(corporation: sni.user.models.Corporation)[source]

Updates a corporation properties from the ESI.

sni.user.jobs.update_corporations_from_esi()[source]

Updates corporations properties. (yes)

sni.user.jobs.update_user_autogroup(usr: sni.user.models.User)[source]

Makes sure a user belongs to its corporation, alliance, and coalitions autogroups.

sni.user.jobs.update_user_from_esi(usr: sni.user.models.User)[source]

Updates a user’s information from the ESI

sni.user.jobs.update_users_from_esi()[source]

Iterated through all users and updates their field from ESI.

Database signal handlers

ODM signal handlers

sni.user.signals.on_coalition_post_save(_sender: Any, **kwargs)[source]

Whenever a coalition is saved in the database.

sni.user.signals.on_user_post_save(_sender: Any, **kwargs)[source]

Whenever a user is saved in the database.

Database migration

Migration methode for user related collections

sni.user.migration.ensure_root() → None[source]

Create root user if it does not exist.

sni.user.migration.ensure_superuser_group() → None[source]

Ensure that the superusers group exists and makes sure that root is the owner.

sni.user.migration.migrate()[source]

Migrates all schema

sni.user.migration.migrate_alliance()[source]

Migrate the alliances documents to the latest schema

sni.user.migration.migrate_coalition()[source]

Migrate the coalition documents to the latest schema

sni.user.migration.migrate_corporation()[source]

Migrate the corporation documents to the latest schema

sni.user.migration.migrate_group()[source]

Migrate the group documents to the latest schema

sni.user.migration.migrate_user()[source]

Migrate the user documents to the latest schema