2019-05-20 11:39:53 +00:00
|
|
|
# coding: utf-8
|
|
|
|
#
|
|
|
|
from django.db import models
|
|
|
|
from django.utils.translation import ugettext_lazy as _
|
|
|
|
|
2020-05-11 04:35:33 +00:00
|
|
|
from common.utils import lazyproperty
|
2019-05-21 08:27:01 +00:00
|
|
|
from .base import BasePermission
|
2019-05-20 11:39:53 +00:00
|
|
|
|
|
|
|
__all__ = [
|
|
|
|
'RemoteAppPermission',
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2019-05-21 09:01:47 +00:00
|
|
|
class RemoteAppPermission(BasePermission):
|
2019-05-21 08:27:01 +00:00
|
|
|
remote_apps = models.ManyToManyField('applications.RemoteApp', related_name='granted_by_permissions', blank=True, verbose_name=_("RemoteApp"))
|
2019-09-12 10:25:22 +00:00
|
|
|
system_users = models.ManyToManyField('assets.SystemUser', related_name='granted_by_remote_app_permissions', verbose_name=_("System user"))
|
2019-05-20 11:39:53 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
unique_together = [('org_id', 'name')]
|
|
|
|
verbose_name = _('RemoteApp permission')
|
|
|
|
ordering = ('name',)
|
|
|
|
|
|
|
|
def get_all_remote_apps(self):
|
|
|
|
return set(self.remote_apps.all())
|
2020-05-11 04:35:33 +00:00
|
|
|
|
2020-05-28 09:00:42 +00:00
|
|
|
@property
|
|
|
|
def all_remote_apps(self):
|
|
|
|
return self.remote_apps.all()
|
|
|
|
|
2020-05-11 04:35:33 +00:00
|
|
|
@lazyproperty
|
|
|
|
def remote_apps_amount(self):
|
|
|
|
return self.remote_apps.count()
|
|
|
|
|
|
|
|
@lazyproperty
|
|
|
|
def system_users_amount(self):
|
|
|
|
return self.system_users.count()
|