Passed
Push — 2.x ( 5ff915...047977 )
by Jordi
06:19
created

senaite.core.browser.sharing.sharing   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 7
eloc 27
dl 0
loc 43
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A SharingView.is_client() 0 4 1
A SharingView.can_edit_inherit() 0 2 1
A SharingView.__call__() 0 7 3
A SharingView.roles() 0 4 2
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