Skip to content

Admin

amlit.admin

amlit.admin.Organisation

Bases: TermModel

Organisation that has management. Having users with their role. Also has the owner Organisation can just access specific community

community_name property

community_name

Return name of community

operators property

operators

Return the list of operators

scheduler_data property

scheduler_data: list

Return scheduler data in list

scheduler_templates property

scheduler_templates: list

Return scheduler data in list

check_user_access

check_user_access()

Check user access UserOrganisation and UserOrganisationInvitation are combined Delete UserOrganisationInvitation first if more than max user Delete older UserOrganisation if more than max user

Source code in django_project/amlit/models/organisation.py
def check_user_access(self):
    """
    Check user access
    UserOrganisation and UserOrganisationInvitation are combined
    Delete UserOrganisationInvitation first if more than max user
    Delete older UserOrganisation if more than max user
    """

    # check the owner is the one of user organisation
    UserOrganisation.objects.get_or_create(
        user=self.owner,
        organisation=self,
        defaults={
            'role': UserRole.objects.filter(
                permissions__name=RolePermission.ASSIGN_USER).first()
        }
    )

    access_counter = 1  # first is from the owner access
    user_org_set = self.userorganisation_set.exclude(
        user=self.owner).order_by('-pk')
    user_invitation_set = self.userorganisationinvitation_set.all().order_by(
        '-pk')
    for accesses in [user_org_set, user_invitation_set]:
        for access in accesses:
            access_counter += 1
            if access_counter > self.max_user:
                access.delete()

has_permission

has_permission()

Return the permissions interface

Source code in django_project/amlit/models/organisation.py
def has_permission(self):
    """ Return the permissions interface
    """
    return _OrganisationPermissionsInterface(self)

is_admin

is_admin(user)

Return user is admin role

Source code in django_project/amlit/models/organisation.py
def is_admin(self, user):
    """ Return user is admin role
    :type user: User
    """
    if self.is_owner(user):
        return True
    try:
        return UserRole.ADMIN in UserOrganisation.objects.get(
            user=user, organisation=self).role.name
    except UserOrganisation.DoesNotExist:
        return False

is_owner

is_owner(user)

Return user is owner role

Source code in django_project/amlit/models/organisation.py
def is_owner(self, user):
    """ Return user is owner role
    :type user: User
    """
    if self.owner == user:
        return True
    return False

role

role(user: User)

Return role of user

Source code in django_project/amlit/models/organisation.py
def role(self, user: User):
    """ Return role of user
    :type user: User
    """
    if self.is_owner(user):
        return UserRole.OWNER
    try:
        return UserOrganisation.objects.get(
            user=user, organisation=self).role.name
    except UserOrganisation.DoesNotExist:
        return UserRole.UNKNOWN

amlit.admin.RolePermission

Bases: TermModel

Permissions for role

amlit.admin.SitePreferences

Bases: SingletonModel

Setting specifically for amlit

amlit.admin.User

Bases: AbstractUser

Users within the Django authentication system are represented by this model.

Username and password are required. Other fields are optional. We make username as email format

avatar_url property

avatar_url: str

return avatar url

communities property

communities

Return communities that user have access to

organisations property

organisations

Return organisations that user have access to

organisations_as_admin property

organisations_as_admin

Return organisation that has admin role or owner

amlit.admin.UserOrganisation

Bases: Model

Model that link user with organisation with their role

delete

delete(using=None, keep_parents=False)

When user organisation deleted, we need to notify user

Source code in django_project/amlit/models/organisation.py
def delete(self, using=None, keep_parents=False):
    """
    When user organisation deleted, we need to notify user
    """
    super(UserOrganisation, self).delete(using, keep_parents)

amlit.admin.UserOrganisationInvitation

Bases: Model

Model that have invitation of user to organisation

accept

accept(user)

Accept invitation by user The user needs to be same with email

Source code in django_project/amlit/models/organisation.py
def accept(self, user):
    """
    Accept invitation by user
    The user needs to be same with email
    :type user: User
    """
    if user.email == self.email:
        self.delete()
        UserOrganisation.objects.get_or_create(
            user=user,
            organisation=self.organisation,
            defaults={
                'role': self.role
            }
        )

reject

reject()

Reject invitation by user

Source code in django_project/amlit/models/organisation.py
def reject(self):
    """
    Reject invitation by user
    """
    self.delete()

send_invitation

send_invitation()

Send email for this notification

Source code in django_project/amlit/models/organisation.py
def send_invitation(self):
    """ Send email for this notification """
    send_mail(
        subject='{} You are invited to {}'.format(
            settings.EMAIL_SUBJECT_PREFIX, self.organisation.name),
        message=render_to_string(
            'pages/invitation/invitation_template.html', {
                'object': self
            }),
        from_email=settings.DEFAULT_FROM_EMAIL,
        recipient_list=[self.email],
        fail_silently=False,
    )

amlit.admin.UserRole

Bases: TermModel

Role for user in organisation

amlit.admin.UserTitle

Bases: TermModel

Contains title of an user specification

API

amlit.api

amlit.api.Organisation

Bases: TermModel

Organisation that has management. Having users with their role. Also has the owner Organisation can just access specific community

community_name property

community_name

Return name of community

operators property

operators

Return the list of operators

scheduler_data property

scheduler_data: list

Return scheduler data in list

scheduler_templates property

scheduler_templates: list

Return scheduler data in list

check_user_access

check_user_access()

Check user access UserOrganisation and UserOrganisationInvitation are combined Delete UserOrganisationInvitation first if more than max user Delete older UserOrganisation if more than max user

Source code in django_project/amlit/models/organisation.py
def check_user_access(self):
    """
    Check user access
    UserOrganisation and UserOrganisationInvitation are combined
    Delete UserOrganisationInvitation first if more than max user
    Delete older UserOrganisation if more than max user
    """

    # check the owner is the one of user organisation
    UserOrganisation.objects.get_or_create(
        user=self.owner,
        organisation=self,
        defaults={
            'role': UserRole.objects.filter(
                permissions__name=RolePermission.ASSIGN_USER).first()
        }
    )

    access_counter = 1  # first is from the owner access
    user_org_set = self.userorganisation_set.exclude(
        user=self.owner).order_by('-pk')
    user_invitation_set = self.userorganisationinvitation_set.all().order_by(
        '-pk')
    for accesses in [user_org_set, user_invitation_set]:
        for access in accesses:
            access_counter += 1
            if access_counter > self.max_user:
                access.delete()

has_permission

has_permission()

Return the permissions interface

Source code in django_project/amlit/models/organisation.py
def has_permission(self):
    """ Return the permissions interface
    """
    return _OrganisationPermissionsInterface(self)

is_admin

is_admin(user)

Return user is admin role

Source code in django_project/amlit/models/organisation.py
def is_admin(self, user):
    """ Return user is admin role
    :type user: User
    """
    if self.is_owner(user):
        return True
    try:
        return UserRole.ADMIN in UserOrganisation.objects.get(
            user=user, organisation=self).role.name
    except UserOrganisation.DoesNotExist:
        return False

is_owner

is_owner(user)

Return user is owner role

Source code in django_project/amlit/models/organisation.py
def is_owner(self, user):
    """ Return user is owner role
    :type user: User
    """
    if self.owner == user:
        return True
    return False

role

role(user: User)

Return role of user

Source code in django_project/amlit/models/organisation.py
def role(self, user: User):
    """ Return role of user
    :type user: User
    """
    if self.is_owner(user):
        return UserRole.OWNER
    try:
        return UserOrganisation.objects.get(
            user=user, organisation=self).role.name
    except UserOrganisation.DoesNotExist:
        return UserRole.UNKNOWN

amlit.api.OrganisationAvailableUserSearch

Bases: APIView

Return user that available for organisation

get

get(request, pk)

Return data of features

Source code in django_project/amlit/api/organisation.py
def get(self, request, pk):
    """ Return data of features """
    q = request.GET.get('q', 'none')
    org = get_object_or_404(Organisation, pk=pk)
    return Response(
        [getattr(user, User.USERNAME_FIELD) for user in User.objects.filter(
            Q(first_name__icontains=q) |
            Q(last_name__icontains=q) |
            Q(email__icontains=q)
        ).exclude(
            id__in=list(org.userorganisation_set.values_list('user', flat=True))
        )]
    )

amlit.api.OrganisationCreateScheduler

Bases: APIView

Create scheduler

amlit.api.OrganisationEditScheduler

Bases: APIView

Edit scheduler

amlit.api.OrganisationInvitation

Bases: APIView

Create user invitation for an organisation

post

post(request, pk)

Return data of features

Source code in django_project/amlit/api/organisation.py
def post(self, request, pk):
    """ Return data of features """
    data = request.data
    org = get_object_or_404(Organisation, pk=pk)
    try:
        if not org.has_permission().assign_user(request.user):
            return HttpResponseForbidden()
        if org.able_to_add_user:
            email = data.get('email', None)
            # create invitation if user has not been invited or already have access
            if not org.userorganisationinvitation_set.filter(
                    email=email
            ).first() and not org.userorganisation_set.filter(
                **{
                    'user__{}'.format(User.USERNAME_FIELD): email,
                    'organisation': org
                }
            ).first():
                form = UserOrganisationInvitationForm(data)
                if form.is_valid():
                    UserOrganisationInvitation.objects.get_or_create(
                        email=email,
                        organisation=org,
                        role=UserRole.objects.get(id=data.get('role', None))
                    )
                else:
                    return HttpResponseBadRequest("The data is wrong.")

            return redirect(
                reverse('organisation_detail', args=[pk]) + '#manage-access'
            )
        else:
            return HttpResponseBadRequest("Can't add new user anymore.")
    except UserRole.DoesNotExist:
        return HttpResponseBadRequest('User role does not exist')

amlit.api.OrganisationSchedulerActivate

Bases: APIView

Active scheduler

amlit.api.OrganisationSchedulerInactivate

Bases: APIView

Inactive scheduler

amlit.api.OrganisationSchedulerList

Bases: APIView

Scheduler list of organisation

amlit.api.SchedulerOrganisation

Bases: Model

Overridden scheduler for an organisation

activate

activate()

Activate the schedule

Source code in django_project/amlit_helpdesk/models/scheduler.py
def activate(self):
    """ Activate the schedule"""
    recurring_ticket = self.recurring_ticket
    if recurring_ticket:
        recurring_ticket.active = True
        recurring_ticket.save()

inactivate

inactivate()

Inactivate the schedule

Source code in django_project/amlit_helpdesk/models/scheduler.py
def inactivate(self):
    """ Inactivate the schedule"""
    recurring_ticket = self.recurring_ticket
    if recurring_ticket:
        recurring_ticket.active = False
        recurring_ticket.save()

update

update(data, user: User)

Update the scheduler based on data TODO: LIT We need to fix it to reuse function to create ticket, feature ticket and recurring ticket

Source code in django_project/amlit_helpdesk/models/scheduler.py
def update(self, data, user: User):
    """
    Update the scheduler based on data
    TODO: LIT
     We need to fix it to reuse function to create ticket, feature ticket and recurring ticket
    """
    from amlit_helpdesk.forms.ticket import AmlitTicketForm
    from amlit_helpdesk.views.ticket.update import update_ticket_data
    type_obj = self.feature_type_combination_obj
    if not type_obj:
        return

    preference = SitePreferences.load()
    data['queue'] = preference.recurred_queues.first().id

    features = FeatureBase.objects.filter(
        system__community__code=self.organisation.community_code,
        the_class=type_obj.the_class,
        sub_class=type_obj.sub_class,
        type=type_obj.type
    )
    recurring_ticket = self.recurring_ticket
    if not recurring_ticket:
        data['start_date'] = timezone.now()
        form = AmlitTicketForm(
            None,
            data,
            queue_choices=[(queue.id, queue.title) for queue in preference.recurred_queues.all()],
            assigned_to_choices=self.organisation.operators
        )
        if form.is_valid():
            ticket = form.save(user)
            feature_ticket = FeatureTicket.objects.create(
                ticket=ticket,
                features=list(features.values_list('id', flat=True))
            )
            recurring_ticket, created = RecurringTicket.create_recurring(
                feature_ticket.ticket, form.data['recurring_type'])
            self.recurring_ticket = recurring_ticket
            self.save()
    else:
        ticket = recurring_ticket.last_ticket
        feature_ticket = ticket.featureticket
        feature_ticket.features = list(features.values_list('id', flat=True))
        feature_ticket.save()
        ticket.description = data['body']
        update_ticket_data(ticket, user, data)

amlit.api.SchedulerTemplate

Bases: Model

Scheduler template to create or update the recurring ticket Mostly used for schedule ticket ofr multi assets

amlit.api.User

Bases: AbstractUser

Users within the Django authentication system are represented by this model.

Username and password are required. Other fields are optional. We make username as email format

avatar_url property

avatar_url: str

return avatar url

communities property

communities

Return communities that user have access to

organisations property

organisations

Return organisations that user have access to

organisations_as_admin property

organisations_as_admin

Return organisation that has admin role or owner

amlit.api.UserOrganisation

Bases: Model

Model that link user with organisation with their role

delete

delete(using=None, keep_parents=False)

When user organisation deleted, we need to notify user

Source code in django_project/amlit/models/organisation.py
def delete(self, using=None, keep_parents=False):
    """
    When user organisation deleted, we need to notify user
    """
    super(UserOrganisation, self).delete(using, keep_parents)

amlit.api.UserOrganisationDetail

Bases: APIView

API for user organisation/access

delete

delete(request, pk)

Return data of features

Source code in django_project/amlit/api/organisation.py
def delete(self, request, pk):
    """ Return data of features """
    access = get_object_or_404(UserOrganisation, pk=pk)
    if not access.organisation.has_permission().assign_user(request.user):
        return HttpResponseForbidden()
    access.delete()
    return HttpResponse('OK')

put

put(request, pk)

Return data of features

Source code in django_project/amlit/api/organisation.py
def put(self, request, pk):
    """ Return data of features """
    access = get_object_or_404(UserOrganisation, pk=pk)
    if not access.organisation.has_permission().assign_user(request.user):
        return HttpResponseForbidden()
    try:
        access.role = UserRole.objects.get(
            id=request.data.get('role', 0))
        access.save()
        return HttpResponse('OK')
    except UserRole.DoesNotExist:
        return HttpResponseBadRequest()

amlit.api.UserOrganisationInvitation

Bases: Model

Model that have invitation of user to organisation

accept

accept(user)

Accept invitation by user The user needs to be same with email

Source code in django_project/amlit/models/organisation.py
def accept(self, user):
    """
    Accept invitation by user
    The user needs to be same with email
    :type user: User
    """
    if user.email == self.email:
        self.delete()
        UserOrganisation.objects.get_or_create(
            user=user,
            organisation=self.organisation,
            defaults={
                'role': self.role
            }
        )

reject

reject()

Reject invitation by user

Source code in django_project/amlit/models/organisation.py
def reject(self):
    """
    Reject invitation by user
    """
    self.delete()

send_invitation

send_invitation()

Send email for this notification

Source code in django_project/amlit/models/organisation.py
def send_invitation(self):
    """ Send email for this notification """
    send_mail(
        subject='{} You are invited to {}'.format(
            settings.EMAIL_SUBJECT_PREFIX, self.organisation.name),
        message=render_to_string(
            'pages/invitation/invitation_template.html', {
                'object': self
            }),
        from_email=settings.DEFAULT_FROM_EMAIL,
        recipient_list=[self.email],
        fail_silently=False,
    )

amlit.api.UserOrganisationInvitationAccept

Bases: APIView

Method to accept the invitation

amlit.api.UserOrganisationInvitationDetail

Bases: APIView

API for invitation

delete

delete(request, pk)

Return data of features

Source code in django_project/amlit/api/organisation.py
def delete(self, request, pk):
    """ Return data of features """
    invitation = get_object_or_404(UserOrganisationInvitation, pk=pk)
    if not invitation.organisation.has_permission().assign_user(request.user):
        return HttpResponseForbidden()
    invitation.delete()
    return HttpResponse('OK')

put

put(request, pk)

Return data of features

Source code in django_project/amlit/api/organisation.py
def put(self, request, pk):
    """ Return data of features """
    invitation = get_object_or_404(UserOrganisationInvitation, pk=pk)
    if not invitation.organisation.has_permission().assign_user(request.user):
        return HttpResponseForbidden()
    invitation.role = UserRole.objects.get(id=request.data.get('role', 0))
    invitation.save()
    return HttpResponse('OK')

amlit.api.UserOrganisationInvitationReject

Bases: APIView

Method to reject the invitation

amlit.api.UserRole

Bases: TermModel

Role for user in organisation

Forms

amlit.forms

Migrations

amlit.migrations

Models

amlit.models

amlit.models.Organisation

Bases: TermModel

Organisation that has management. Having users with their role. Also has the owner Organisation can just access specific community

community_name property

community_name

Return name of community

operators property

operators

Return the list of operators

scheduler_data property

scheduler_data: list

Return scheduler data in list

scheduler_templates property

scheduler_templates: list

Return scheduler data in list

check_user_access

check_user_access()

Check user access UserOrganisation and UserOrganisationInvitation are combined Delete UserOrganisationInvitation first if more than max user Delete older UserOrganisation if more than max user

Source code in django_project/amlit/models/organisation.py
def check_user_access(self):
    """
    Check user access
    UserOrganisation and UserOrganisationInvitation are combined
    Delete UserOrganisationInvitation first if more than max user
    Delete older UserOrganisation if more than max user
    """

    # check the owner is the one of user organisation
    UserOrganisation.objects.get_or_create(
        user=self.owner,
        organisation=self,
        defaults={
            'role': UserRole.objects.filter(
                permissions__name=RolePermission.ASSIGN_USER).first()
        }
    )

    access_counter = 1  # first is from the owner access
    user_org_set = self.userorganisation_set.exclude(
        user=self.owner).order_by('-pk')
    user_invitation_set = self.userorganisationinvitation_set.all().order_by(
        '-pk')
    for accesses in [user_org_set, user_invitation_set]:
        for access in accesses:
            access_counter += 1
            if access_counter > self.max_user:
                access.delete()

has_permission

has_permission()

Return the permissions interface

Source code in django_project/amlit/models/organisation.py
def has_permission(self):
    """ Return the permissions interface
    """
    return _OrganisationPermissionsInterface(self)

is_admin

is_admin(user)

Return user is admin role

Source code in django_project/amlit/models/organisation.py
def is_admin(self, user):
    """ Return user is admin role
    :type user: User
    """
    if self.is_owner(user):
        return True
    try:
        return UserRole.ADMIN in UserOrganisation.objects.get(
            user=user, organisation=self).role.name
    except UserOrganisation.DoesNotExist:
        return False

is_owner

is_owner(user)

Return user is owner role

Source code in django_project/amlit/models/organisation.py
def is_owner(self, user):
    """ Return user is owner role
    :type user: User
    """
    if self.owner == user:
        return True
    return False

role

role(user: User)

Return role of user

Source code in django_project/amlit/models/organisation.py
def role(self, user: User):
    """ Return role of user
    :type user: User
    """
    if self.is_owner(user):
        return UserRole.OWNER
    try:
        return UserOrganisation.objects.get(
            user=user, organisation=self).role.name
    except UserOrganisation.DoesNotExist:
        return UserRole.UNKNOWN

amlit.models.OrganisationByUser

Bases: Manager

admin_role

admin_role(user)

Return organisation that user has admin roles

Source code in django_project/amlit/models/organisation.py
def admin_role(self, user):
    """ Return organisation that user has admin roles
    :type user: User
    """
    organisations = list(UserOrganisation.objects.filter(
        user=user, role__name='Admin').values_list(
        'organisation_id', flat=True))
    return super().get_queryset().filter(
        Q(owner=user) | Q(id__in=organisations))

all_role

all_role(user)

Return organisation that user has every roles

Source code in django_project/amlit/models/organisation.py
def all_role(self, user):
    """ Return organisation that user has every roles
    :type user: User
    """
    organisations = list(UserOrganisation.objects.filter(
        user=user).values_list('organisation_id', flat=True))
    return super().get_queryset().filter(
        Q(owner=user) | Q(id__in=organisations))

amlit.models.OrganisationSubscriptionError

Bases: Exception

Raised when organisation subscription error

amlit.models.RolePermission

Bases: TermModel

Permissions for role

amlit.models.SitePreferences

Bases: SingletonModel

Setting specifically for amlit

amlit.models.User

Bases: AbstractUser

Users within the Django authentication system are represented by this model.

Username and password are required. Other fields are optional. We make username as email format

avatar_url property

avatar_url: str

return avatar url

communities property

communities

Return communities that user have access to

organisations property

organisations

Return organisations that user have access to

organisations_as_admin property

organisations_as_admin

Return organisation that has admin role or owner

amlit.models.UserByString

UserByString(username)
Source code in django_project/amlit/models/user.py
def __init__(self, username):
    self.username = username
    try:
        self.user = User.objects.get(**{'{}'.format(User.USERNAME_FIELD): username})
    except User.DoesNotExist:
        pass

avatar_url property

avatar_url: str

return avatar url

full_str

full_str()

return str

Source code in django_project/amlit/models/user.py
def full_str(self):
    """ return __str__ """
    return self.__str__()

amlit.models.UserManager

Bases: BaseUserManager

Define a model manager for User model with no username field.

create_superuser

create_superuser(email, password, **extra_fields)

Create and save a SuperUser with the given email and password.

Source code in django_project/amlit/models/user.py
def create_superuser(self, email, password, **extra_fields):
    """Create and save a SuperUser with the given email and password."""
    extra_fields.setdefault('is_staff', True)
    extra_fields.setdefault('is_superuser', True)

    if extra_fields.get('is_staff') is not True:
        raise ValueError('Superuser must have is_staff=True.')
    if extra_fields.get('is_superuser') is not True:
        raise ValueError('Superuser must have is_superuser=True.')

    return self._create_user(email, password, **extra_fields)

create_user

create_user(email, password=None, **extra_fields)

Create and save a regular User with the given email and password.

Source code in django_project/amlit/models/user.py
def create_user(self, email, password=None, **extra_fields):
    """Create and save a regular User with the given email and password."""
    extra_fields.setdefault('is_staff', False)
    extra_fields.setdefault('is_superuser', False)
    return self._create_user(email, password, **extra_fields)

amlit.models.UserOrganisation

Bases: Model

Model that link user with organisation with their role

delete

delete(using=None, keep_parents=False)

When user organisation deleted, we need to notify user

Source code in django_project/amlit/models/organisation.py
def delete(self, using=None, keep_parents=False):
    """
    When user organisation deleted, we need to notify user
    """
    super(UserOrganisation, self).delete(using, keep_parents)

amlit.models.UserOrganisationInvitation

Bases: Model

Model that have invitation of user to organisation

accept

accept(user)

Accept invitation by user The user needs to be same with email

Source code in django_project/amlit/models/organisation.py
def accept(self, user):
    """
    Accept invitation by user
    The user needs to be same with email
    :type user: User
    """
    if user.email == self.email:
        self.delete()
        UserOrganisation.objects.get_or_create(
            user=user,
            organisation=self.organisation,
            defaults={
                'role': self.role
            }
        )

reject

reject()

Reject invitation by user

Source code in django_project/amlit/models/organisation.py
def reject(self):
    """
    Reject invitation by user
    """
    self.delete()

send_invitation

send_invitation()

Send email for this notification

Source code in django_project/amlit/models/organisation.py
def send_invitation(self):
    """ Send email for this notification """
    send_mail(
        subject='{} You are invited to {}'.format(
            settings.EMAIL_SUBJECT_PREFIX, self.organisation.name),
        message=render_to_string(
            'pages/invitation/invitation_template.html', {
                'object': self
            }),
        from_email=settings.DEFAULT_FROM_EMAIL,
        recipient_list=[self.email],
        fail_silently=False,
    )

amlit.models.UserRole

Bases: TermModel

Role for user in organisation

amlit.models.UserTitle

Bases: TermModel

Contains title of an user specification

Serializers

amlit.serializer

Templatetags

amlit.templatetags

Views

amlit.views