Calendar.related_object()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 3
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
# -*- coding: utf-8 -*-
0 ignored issues
show
Coding Style introduced by
This module should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
2
from tracim.models import User
3
from tracim.models.data import UserRoleInWorkspace
4
5
6
CALENDAR_PERMISSION_READ = 'r'
7
CALENDAR_PERMISSION_WRITE = 'w'
8
9
10
class Calendar(object):
0 ignored issues
show
Coding Style introduced by
This class should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
Unused Code introduced by
The variable __class__ seems to be unused.
Loading history...
11
    def __init__(self, related_object, path):
12
        self._related_object = related_object
13
        self._path = path
14
15
    @property
16
    def related_object(self):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
17
        return self._related_object
18
19
    def user_can_read(self, user: User) -> bool:
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
20
        raise NotImplementedError()
21
22
    def user_can_write(self, user: User) -> bool:
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
23
        raise NotImplementedError()
24
25
26
class UserCalendar(Calendar):
0 ignored issues
show
Coding Style introduced by
This class should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
Unused Code introduced by
The variable __class__ seems to be unused.
Loading history...
27
    def user_can_write(self, user: User) -> bool:
28
        return self._related_object.user_id == user.user_id
29
30
    def user_can_read(self, user: User) -> bool:
31
        return self._related_object.user_id == user.user_id
32
33
34
class WorkspaceCalendar(Calendar):
0 ignored issues
show
Coding Style introduced by
This class should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
Unused Code introduced by
The variable __class__ seems to be unused.
Loading history...
35
    _workspace_rights = {
36
        UserRoleInWorkspace.NOT_APPLICABLE:
37
            [],
38
        UserRoleInWorkspace.READER:
39
            [CALENDAR_PERMISSION_READ],
40
        UserRoleInWorkspace.CONTRIBUTOR:
41
            [CALENDAR_PERMISSION_READ, CALENDAR_PERMISSION_WRITE],
42
        UserRoleInWorkspace.CONTENT_MANAGER:
43
            [CALENDAR_PERMISSION_READ, CALENDAR_PERMISSION_WRITE],
44
        UserRoleInWorkspace.WORKSPACE_MANAGER:
45
            [CALENDAR_PERMISSION_READ, CALENDAR_PERMISSION_WRITE],
46
    }
47
48
    def user_can_write(self, user: User) -> bool:
49
        role = user.get_role(self._related_object)
50
        return CALENDAR_PERMISSION_WRITE in self._workspace_rights[role]
51
52
    def user_can_read(self, user: User) -> bool:
53
        role = user.get_role(self._related_object)
54
        return CALENDAR_PERMISSION_READ in self._workspace_rights[role]
55