Apps

We have the following models:

_images/app-apps-models.png

Models

App

The App model contains the properties of the apps in a project e.g. name, icon

Tip

The user_apps method is used to display a list of apps for a user. e.g. AppListView

_images/app-apps-list-view.png

Useful methods include:

  • admin_apps: List of apps where the user is an administrator.

  • admin_app_groups: List of apps where the user is a group administrator.

  • app_menu: Can be used to control the main menu in the project

    • current_app_admin can be used to enable menu options for a user who is an administrator for the current app.

    • show_app_menu will tell you if the user has access to just one app i.e. no need to show the app menu unless they have access to several apps.

  • app_perms: Check the source code for documentation.

  • create_app: Create a new app…

  • is_administrator: Is the user an administrator for this app?

  • is_administrator_for_any_app: Is the user an administrator for any app?

  • user_apps: Apps available to this user.

  • user_dash_url: Dashboard URL for this user. Checks to see if they have access to one (or more) apps.

This model includes a slug, name, menu caption and icon for the app.

  • administrators (many to many): Users who can administer the app.

  • app_group (many to many): Users belonging to these groups (AppGroup) have permission to access the app.

  • global_group (many to many): Users belonging to these groups (Django Group) have permission to access the app.

  • hide_app_groups (boolean): Does the app use app_group (or not)?

  • url_name_contact_edit and url_name_dash are Django URLs.

AppSettings

  • app_superusers (many to many): Users who can set the administrator for an app.

  • contact_administrators (many to many): Users who can create / update / delete users (or contacts).

AppGroup and AppGroupUser

List of groups for an application. These are different to the Django Group.

Views

Base

You can add the following to your base.html template:

{% block menu %}
  {% if user.is_authenticated %}
    {% if app_menu.show_app_menu %}
      <li class="pure-menu-item{% if 'apps' in path %} pure-menu-selected{% endif %}">
        <a href="{% url 'apps.list' %}" class="pure-menu-link">
          <i class="fa fa-bullseye fa-fw"></i>
          Apps
        </a>
      </li>
    {% endif %}
    {% if app_menu and app_menu.current_app %}
      <li class="pure-menu-item{% if app_menu.current_app.url_name_dash == request.resolver_match.url_name %} pure-menu-selected{% endif %}">
        <a href="{% url app_menu.current_app.url_name_dash %}" class="pure-menu-link">
          <i class="fa fa-dashboard fa-fw"></i>
          Dashboard
        </a>
      </li>
    {% endif %}
    {% if app_menu and app_menu.show_settings %}
      <li class="pure-menu-item{% if 'settings' in path %} pure-menu-selected{% endif %}">
        <a href="{% url 'project.settings' %}" class="pure-menu-link">
          <i class="fa fa-cog fa-fw"></i>
          Settings
        </a>
      </li>
    {% endif %}
  {% endif %}
{% endblock menu %}

Settings

The Settings view needs access to various permissions:

from braces.views import LoginRequiredMixin, UserPassesTestMixin
from django.views.generic import DetailView

from apps.views import is_contact_or_app_admin, SettingsBaseMixin

class SettingsView(
    LoginRequiredMixin, UserPassesTestMixin, SettingsBaseMixin, TemplateView
):
    template_name = "example/settings.html"

    def test_func(self, user):
        return is_contact_or_app_admin(user)

The permissions returned by SettingsBaseMixin will work with the following:

{% block content %}
  <div class="pure-g">
    {% include 'apps/_settings_apps.html' %}
    {% include 'apps/_settings_groups.html' %}
  </div>
{% endblock content %}