app/soc/logic/models/role.py
author Lennard de Rijk <ljvderijk@gmail.com>
Fri, 24 Jul 2009 20:56:08 +0200
changeset 2676 a7fabd1534f8
parent 2672 7bc9d3b962af
child 3052 6907a33ca0a2
permissions -rw-r--r--
Added sendNewRequestNotification to the Notifications helper. This method will send out a notification upon arrival of a new Request to all users who have an active role for the Request's scope and the roles as specified by the getRoleLogicsToNotifyUponNewRequest. Also renamed getRoleLogicsToNotifyUponeNewRequest to getRoleLogicsToNotifyUponNewRequest.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
19
f2a5ec8fb780 Initial definition of the Host Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
f2a5ec8fb780 Initial definition of the Host Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     2
#
1308
35b75ffcbb37 Partially reverted "Update the copyright notice for 2009."
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1307
diff changeset
     3
# Copyright 2008 the Melange authors.
19
f2a5ec8fb780 Initial definition of the Host Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     4
#
f2a5ec8fb780 Initial definition of the Host Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
f2a5ec8fb780 Initial definition of the Host Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
f2a5ec8fb780 Initial definition of the Host Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
404
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 244
diff changeset
     8
#
19
f2a5ec8fb780 Initial definition of the Host Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
404
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 244
diff changeset
    10
#
19
f2a5ec8fb780 Initial definition of the Host Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
f2a5ec8fb780 Initial definition of the Host Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
f2a5ec8fb780 Initial definition of the Host Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
f2a5ec8fb780 Initial definition of the Host Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
f2a5ec8fb780 Initial definition of the Host Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    15
# limitations under the License.
f2a5ec8fb780 Initial definition of the Host Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    16
535
9045b8888772 Refactor classes in soc/logic/models to make more use of inheritance. Add
Todd Larsen <tlarsen@google.com>
parents: 530
diff changeset
    17
"""Role (Model) query functions.
404
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 244
diff changeset
    18
"""
19
f2a5ec8fb780 Initial definition of the Host Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    19
f2a5ec8fb780 Initial definition of the Host Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    20
__authors__ = [
429
e50e18936f06 Fixed typo in e-mail address
Sverre Rabbelier <srabbelier@gmail.com>
parents: 410
diff changeset
    21
  '"Sverre Rabbelier" <sverre@rabbelier.nl>',
715
51703b18ef2e Adds the removal of requests from the datastore when a new role entity is created.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 671
diff changeset
    22
  '"Lennard de Rijk" <ljvderijk@gmail.com>',
404
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 244
diff changeset
    23
  ]
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 244
diff changeset
    24
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 244
diff changeset
    25
991
becede26c37f Added cache flush for the user who creates a group and the user whose role has been activated.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 978
diff changeset
    26
from soc.cache import sidebar
404
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 244
diff changeset
    27
from soc.logic.models import base
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 244
diff changeset
    28
481
94834a1e6c01 Attempt to rename User.id to User.account, in preparation for making User be
Todd Larsen <tlarsen@google.com>
parents: 444
diff changeset
    29
import soc.models.role
19
f2a5ec8fb780 Initial definition of the Host Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    30
207
8ecc2e4198cd Take advantage of the Model inheritance provided by polymodel.PolyModel to
Todd Larsen <tlarsen@google.com>
parents: 181
diff changeset
    31
1955
06ed84dbb1ed Moved canResign check to role logic so subclasses can override.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1625
diff changeset
    32
DEF_LAST_RESIGN_ERROR_FMT = "This user can't be " \
06ed84dbb1ed Moved canResign check to role logic so subclasses can override.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1625
diff changeset
    33
    "resigned, please make sure it's not the last %(name)s."
06ed84dbb1ed Moved canResign check to role logic so subclasses can override.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1625
diff changeset
    34
06ed84dbb1ed Moved canResign check to role logic so subclasses can override.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1625
diff changeset
    35
2664
06d4f4d06f64 Added registerRole to Role Logic where all roles are registered.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2072
diff changeset
    36
ROLE_LOGICS = {}
06d4f4d06f64 Added registerRole to Role Logic where all roles are registered.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2072
diff changeset
    37
06d4f4d06f64 Added registerRole to Role Logic where all roles are registered.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2072
diff changeset
    38
06d4f4d06f64 Added registerRole to Role Logic where all roles are registered.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2072
diff changeset
    39
def registerRoleLogic(role_logic):
06d4f4d06f64 Added registerRole to Role Logic where all roles are registered.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2072
diff changeset
    40
  """Adds the specified Role Logic to the known ones.
06d4f4d06f64 Added registerRole to Role Logic where all roles are registered.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2072
diff changeset
    41
06d4f4d06f64 Added registerRole to Role Logic where all roles are registered.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2072
diff changeset
    42
  Args:
06d4f4d06f64 Added registerRole to Role Logic where all roles are registered.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2072
diff changeset
    43
    role_logic: Instance of or subclass from Role Logic
06d4f4d06f64 Added registerRole to Role Logic where all roles are registered.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2072
diff changeset
    44
  """
06d4f4d06f64 Added registerRole to Role Logic where all roles are registered.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2072
diff changeset
    45
06d4f4d06f64 Added registerRole to Role Logic where all roles are registered.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2072
diff changeset
    46
  global ROLE_LOGICS
06d4f4d06f64 Added registerRole to Role Logic where all roles are registered.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2072
diff changeset
    47
  name = role_logic.role_name
06d4f4d06f64 Added registerRole to Role Logic where all roles are registered.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2072
diff changeset
    48
  ROLE_LOGICS[name] = role_logic
06d4f4d06f64 Added registerRole to Role Logic where all roles are registered.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2072
diff changeset
    49
06d4f4d06f64 Added registerRole to Role Logic where all roles are registered.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2072
diff changeset
    50
404
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 244
diff changeset
    51
class Logic(base.Logic):
535
9045b8888772 Refactor classes in soc/logic/models to make more use of inheritance. Add
Todd Larsen <tlarsen@google.com>
parents: 530
diff changeset
    52
  """Logic methods for the Role model.
404
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 244
diff changeset
    53
  """
19
f2a5ec8fb780 Initial definition of the Host Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    54
671
2c02178037ff Apply DI on the scope logic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 655
diff changeset
    55
  def __init__(self, model=soc.models.role.Role,
2664
06d4f4d06f64 Added registerRole to Role Logic where all roles are registered.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2072
diff changeset
    56
               base_model=None, scope_logic=None, role_name=None,
06d4f4d06f64 Added registerRole to Role Logic where all roles are registered.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2072
diff changeset
    57
               disallow_last_resign=False):
404
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 244
diff changeset
    58
    """Defines the name, key_name and model for this entity.
2664
06d4f4d06f64 Added registerRole to Role Logic where all roles are registered.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2072
diff changeset
    59
06d4f4d06f64 Added registerRole to Role Logic where all roles are registered.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2072
diff changeset
    60
    Args:
06d4f4d06f64 Added registerRole to Role Logic where all roles are registered.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2072
diff changeset
    61
      role_name: The name of this role used for instance for Requests
06d4f4d06f64 Added registerRole to Role Logic where all roles are registered.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2072
diff changeset
    62
      dissallow_last_resign: Iff True and a given role entity is the last of
06d4f4d06f64 Added registerRole to Role Logic where all roles are registered.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2072
diff changeset
    63
        its kind in its scope then this role can not be resigned.
404
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 244
diff changeset
    64
    """
655
9635cbaa2dcd Cleanups to the logic module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 535
diff changeset
    65
671
2c02178037ff Apply DI on the scope logic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 655
diff changeset
    66
    super(Logic, self).__init__(model, base_model=base_model,
2c02178037ff Apply DI on the scope logic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 655
diff changeset
    67
                                scope_logic=scope_logic)
410
2af7f84f4fc7 Moved all key_name related things to the logic modules
Sverre Rabbelier <srabbelier@gmail.com>
parents: 409
diff changeset
    68
2664
06d4f4d06f64 Added registerRole to Role Logic where all roles are registered.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2072
diff changeset
    69
    self.role_name = role_name
06d4f4d06f64 Added registerRole to Role Logic where all roles are registered.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2072
diff changeset
    70
    registerRoleLogic(self)
06d4f4d06f64 Added registerRole to Role Logic where all roles are registered.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2072
diff changeset
    71
1976
be994529deee Fixed typo in variable name.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1956
diff changeset
    72
    self.disallow_last_resign = disallow_last_resign
1955
06ed84dbb1ed Moved canResign check to role logic so subclasses can override.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1625
diff changeset
    73
19
f2a5ec8fb780 Initial definition of the Host Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    74
978
e05b09b53486 Moved getGroupEntityFromScopePath to logic/models/role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 916
diff changeset
    75
  def getGroupEntityFromScopePath(self, group_logic, scope_path):
e05b09b53486 Moved getGroupEntityFromScopePath to logic/models/role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 916
diff changeset
    76
    """Returns a group entity by using the given scope_path.
2664
06d4f4d06f64 Added registerRole to Role Logic where all roles are registered.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2072
diff changeset
    77
978
e05b09b53486 Moved getGroupEntityFromScopePath to logic/models/role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 916
diff changeset
    78
    Args:
e05b09b53486 Moved getGroupEntityFromScopePath to logic/models/role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 916
diff changeset
    79
      group_logic: logic for the group which should be retrieved
e05b09b53486 Moved getGroupEntityFromScopePath to logic/models/role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 916
diff changeset
    80
      scope_path : the scope path of the entity
e05b09b53486 Moved getGroupEntityFromScopePath to logic/models/role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 916
diff changeset
    81
    """
1625
cd7174032b56 Add missing whitespace in soc.logic.models.role module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1517
diff changeset
    82
    group_key_fields = scope_path.rsplit('/', 1)
978
e05b09b53486 Moved getGroupEntityFromScopePath to logic/models/role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 916
diff changeset
    83
e05b09b53486 Moved getGroupEntityFromScopePath to logic/models/role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 916
diff changeset
    84
    if len(group_key_fields) == 1:
e05b09b53486 Moved getGroupEntityFromScopePath to logic/models/role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 916
diff changeset
    85
      # there is only a link_id
e05b09b53486 Moved getGroupEntityFromScopePath to logic/models/role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 916
diff changeset
    86
      fields = {'link_id' : group_key_fields[0]}
e05b09b53486 Moved getGroupEntityFromScopePath to logic/models/role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 916
diff changeset
    87
    else:
e05b09b53486 Moved getGroupEntityFromScopePath to logic/models/role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 916
diff changeset
    88
      # there is a scope_path and link_id
e05b09b53486 Moved getGroupEntityFromScopePath to logic/models/role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 916
diff changeset
    89
      fields = {'scope_path' : group_key_fields[0],
e05b09b53486 Moved getGroupEntityFromScopePath to logic/models/role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 916
diff changeset
    90
                'link_id' : group_key_fields[1]}
e05b09b53486 Moved getGroupEntityFromScopePath to logic/models/role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 916
diff changeset
    91
e05b09b53486 Moved getGroupEntityFromScopePath to logic/models/role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 916
diff changeset
    92
    group = group_logic.getForFields(fields, unique=True)
e05b09b53486 Moved getGroupEntityFromScopePath to logic/models/role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 916
diff changeset
    93
e05b09b53486 Moved getGroupEntityFromScopePath to logic/models/role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 916
diff changeset
    94
    return group
e05b09b53486 Moved getGroupEntityFromScopePath to logic/models/role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 916
diff changeset
    95
1517
a467d13e34ea Pass _updateField the entity_properties dict instead of just the value
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1308
diff changeset
    96
  def _updateField(self, entity, entity_properties, name):
1085
0afbdd0905ef Renamed state to status where appropriate.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1001
diff changeset
    97
    """Special logic for role. If status changes to active we flush the sidebar.
991
becede26c37f Added cache flush for the user who creates a group and the user whose role has been activated.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 978
diff changeset
    98
    """
becede26c37f Added cache flush for the user who creates a group and the user whose role has been activated.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 978
diff changeset
    99
1517
a467d13e34ea Pass _updateField the entity_properties dict instead of just the value
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1308
diff changeset
   100
    value = entity_properties[name]
a467d13e34ea Pass _updateField the entity_properties dict instead of just the value
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1308
diff changeset
   101
1085
0afbdd0905ef Renamed state to status where appropriate.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1001
diff changeset
   102
    if (name == 'status') and (entity.status != value) and value == 'active':
0afbdd0905ef Renamed state to status where appropriate.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1001
diff changeset
   103
      # in case the status of the role changes to active we flush the sidebar
991
becede26c37f Added cache flush for the user who creates a group and the user whose role has been activated.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 978
diff changeset
   104
      # cache. Other changes will be visible after the retention time expires.
becede26c37f Added cache flush for the user who creates a group and the user whose role has been activated.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 978
diff changeset
   105
      sidebar.flush(entity.user.account)
becede26c37f Added cache flush for the user who creates a group and the user whose role has been activated.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 978
diff changeset
   106
becede26c37f Added cache flush for the user who creates a group and the user whose role has been activated.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 978
diff changeset
   107
    return True
1955
06ed84dbb1ed Moved canResign check to role logic so subclasses can override.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1625
diff changeset
   108
1001
2faa7f80e8b2 Flush the sidebar cache when a new active role entity has been created.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 991
diff changeset
   109
  def _onCreate(self, entity):
2faa7f80e8b2 Flush the sidebar cache when a new active role entity has been created.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 991
diff changeset
   110
    """Flush the sidebar cache when a new active role entity has been created.
2faa7f80e8b2 Flush the sidebar cache when a new active role entity has been created.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 991
diff changeset
   111
    """
2faa7f80e8b2 Flush the sidebar cache when a new active role entity has been created.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 991
diff changeset
   112
1085
0afbdd0905ef Renamed state to status where appropriate.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1001
diff changeset
   113
    if entity.status == 'active':
1001
2faa7f80e8b2 Flush the sidebar cache when a new active role entity has been created.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 991
diff changeset
   114
      sidebar.flush(entity.user.account)
991
becede26c37f Added cache flush for the user who creates a group and the user whose role has been activated.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 978
diff changeset
   115
1117
5785d9af5c5d Fixed a bug in role.py that made it call the wrong superclass.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1106
diff changeset
   116
    super(Logic, self)._onCreate(entity)
1106
e14b0995cf29 Flush sidebar when creating a new entity
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1085
diff changeset
   117
1955
06ed84dbb1ed Moved canResign check to role logic so subclasses can override.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1625
diff changeset
   118
  def canResign(self, entity):
06ed84dbb1ed Moved canResign check to role logic so subclasses can override.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1625
diff changeset
   119
    """Checks if the current entity is allowed to be resigned.
06ed84dbb1ed Moved canResign check to role logic so subclasses can override.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1625
diff changeset
   120
1956
1fcddf90eccc Fixed docstring for canResign method.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1955
diff changeset
   121
    Args:
1fcddf90eccc Fixed docstring for canResign method.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1955
diff changeset
   122
      entity: a Role entity
1fcddf90eccc Fixed docstring for canResign method.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1955
diff changeset
   123
1955
06ed84dbb1ed Moved canResign check to role logic so subclasses can override.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1625
diff changeset
   124
    Returns:
06ed84dbb1ed Moved canResign check to role logic so subclasses can override.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1625
diff changeset
   125
      - None if the entity is allowed to resign.
06ed84dbb1ed Moved canResign check to role logic so subclasses can override.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1625
diff changeset
   126
      - Error message otherwise.
06ed84dbb1ed Moved canResign check to role logic so subclasses can override.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1625
diff changeset
   127
    """
06ed84dbb1ed Moved canResign check to role logic so subclasses can override.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1625
diff changeset
   128
1976
be994529deee Fixed typo in variable name.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1956
diff changeset
   129
    if self.disallow_last_resign:
2072
eb4565a8e5b4 Style fixes and removal of unused imports in soc.logic.models modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1976
diff changeset
   130
      # check if this is the last active role for it's scope
eb4565a8e5b4 Style fixes and removal of unused imports in soc.logic.models modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1976
diff changeset
   131
      fields = {'scope': entity.scope,
1955
06ed84dbb1ed Moved canResign check to role logic so subclasses can override.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1625
diff changeset
   132
          'status': 'active'}
2072
eb4565a8e5b4 Style fixes and removal of unused imports in soc.logic.models modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1976
diff changeset
   133
      roles = self.getForFields(fields, limit=2)
1955
06ed84dbb1ed Moved canResign check to role logic so subclasses can override.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1625
diff changeset
   134
2072
eb4565a8e5b4 Style fixes and removal of unused imports in soc.logic.models modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1976
diff changeset
   135
      # if this it the last one return error message
eb4565a8e5b4 Style fixes and removal of unused imports in soc.logic.models modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1976
diff changeset
   136
      if len(roles) <= 1:
eb4565a8e5b4 Style fixes and removal of unused imports in soc.logic.models modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1976
diff changeset
   137
        return DEF_LAST_RESIGN_ERROR_FMT
1955
06ed84dbb1ed Moved canResign check to role logic so subclasses can override.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1625
diff changeset
   138
06ed84dbb1ed Moved canResign check to role logic so subclasses can override.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1625
diff changeset
   139
    # resignation is possible
06ed84dbb1ed Moved canResign check to role logic so subclasses can override.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1625
diff changeset
   140
    return None
978
e05b09b53486 Moved getGroupEntityFromScopePath to logic/models/role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 916
diff changeset
   141
2676
a7fabd1534f8 Added sendNewRequestNotification to the Notifications helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2672
diff changeset
   142
  def getRoleLogicsToNotifyUponNewRequest(self):
2672
7bc9d3b962af Added getRoleLogicsToNotifyUponeNewRequest for use with notifications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2664
diff changeset
   143
    """Returns a list with subclasses of Role Logic which should be notified
7bc9d3b962af Added getRoleLogicsToNotifyUponeNewRequest for use with notifications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2664
diff changeset
   144
    when a new request to obtain this Role arrives.
7bc9d3b962af Added getRoleLogicsToNotifyUponeNewRequest for use with notifications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2664
diff changeset
   145
7bc9d3b962af Added getRoleLogicsToNotifyUponeNewRequest for use with notifications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2664
diff changeset
   146
    Returns:
7bc9d3b962af Added getRoleLogicsToNotifyUponeNewRequest for use with notifications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2664
diff changeset
   147
      A list with all Role Logics to notify
7bc9d3b962af Added getRoleLogicsToNotifyUponeNewRequest for use with notifications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2664
diff changeset
   148
    """
7bc9d3b962af Added getRoleLogicsToNotifyUponeNewRequest for use with notifications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2664
diff changeset
   149
7bc9d3b962af Added getRoleLogicsToNotifyUponeNewRequest for use with notifications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2664
diff changeset
   150
    return []
7bc9d3b962af Added getRoleLogicsToNotifyUponeNewRequest for use with notifications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2664
diff changeset
   151
7bc9d3b962af Added getRoleLogicsToNotifyUponeNewRequest for use with notifications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2664
diff changeset
   152
404
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 244
diff changeset
   153
logic = Logic()