3 # Copyright 2008 the Melange authors.
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
17 """Role (Model) query functions.
21 '"Sverre Rabbelier" <sverre@rabbelier.nl>',
22 '"Lennard de Rijk" <ljvderijk@gmail.com>',
26 from soc
.cache
import sidebar
27 from soc
.logic
.models
import base
29 import soc
.models
.role
32 class Logic(base
.Logic
):
33 """Logic methods for the Role model.
36 def __init__(self
, model
=soc
.models
.role
.Role
,
37 base_model
=None, scope_logic
=None):
38 """Defines the name, key_name and model for this entity.
41 super(Logic
, self
).__init
__(model
, base_model
=base_model
,
42 scope_logic
=scope_logic
)
45 def getGroupEntityFromScopePath(self
, group_logic
, scope_path
):
46 """Returns a group entity by using the given scope_path.
49 group_logic: logic for the group which should be retrieved
50 scope_path : the scope path of the entity
52 group_key_fields
= scope_path
.rsplit('/', 1)
54 if len(group_key_fields
) == 1:
55 # there is only a link_id
56 fields
= {'link_id' : group_key_fields
[0]}
58 # there is a scope_path and link_id
59 fields
= {'scope_path' : group_key_fields
[0],
60 'link_id' : group_key_fields
[1]}
62 group
= group_logic
.getForFields(fields
, unique
=True)
66 def _updateField(self
, entity
, entity_properties
, name
):
67 """Special logic for role. If status changes to active we flush the sidebar.
70 value
= entity_properties
[name
]
72 if (name
== 'status') and (entity
.status
!= value
) and value
== 'active':
73 # in case the status of the role changes to active we flush the sidebar
74 # cache. Other changes will be visible after the retention time expires.
75 sidebar
.flush(entity
.user
.account
)
79 def _onCreate(self
, entity
):
80 """Flush the sidebar cache when a new active role entity has been created.
83 if entity
.status
== 'active':
84 sidebar
.flush(entity
.user
.account
)
86 super(Logic
, self
)._onCreate
(entity
)