Total Complexity | 7 |
Total Lines | 43 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | # -*- coding: utf-8 -*- |
||
2 | |||
3 | from plone.app.workflow.browser.sharing import SharingView as BaseView |
||
4 | from plone.memoize.instance import memoize |
||
5 | from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile |
||
6 | from bika.lims.interfaces import IClient |
||
7 | |||
8 | # Ignore default Plone roles |
||
9 | IGNORE_ROLES = [ |
||
10 | "Reader", |
||
11 | "Editor", |
||
12 | "Contributor", |
||
13 | "Reviewer", |
||
14 | ] |
||
15 | |||
16 | |||
17 | class SharingView(BaseView): |
||
18 | """Custom Sharing View especially for client context |
||
19 | """ |
||
20 | STICKY = () |
||
21 | template = ViewPageTemplateFile("templates/client_sharing.pt") |
||
22 | |||
23 | def __call__(self): |
||
24 | # always ensure the client group is visible |
||
25 | if self.is_client(): |
||
26 | group = self.context.get_group() |
||
27 | if group: |
||
28 | self.STICKY += (group.getId(), ) |
||
29 | return super(SharingView, self).__call__() |
||
30 | |||
31 | def is_client(self): |
||
32 | """Checks if the current context is a client |
||
33 | """ |
||
34 | return IClient.providedBy(self.context) |
||
35 | |||
36 | @memoize |
||
37 | def roles(self): |
||
38 | pairs = super(SharingView, self).roles() |
||
39 | return filter(lambda pair: pair.get("id") not in IGNORE_ROLES, pairs) |
||
40 | |||
41 | def can_edit_inherit(self): |
||
42 | return False |
||
43 |