-
Notifications
You must be signed in to change notification settings - Fork 281
Expand file tree
/
Copy pathpermission.py
More file actions
159 lines (128 loc) · 3.65 KB
/
permission.py
File metadata and controls
159 lines (128 loc) · 3.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import ctypes
from typing import Optional
from .. import _binaryninjacore as core
from . import project, remote, util
from ..enums import CollaborationPermissionLevel
class Permission:
"""
Class representing a permission grant for a user or group on a project.
"""
def __init__(self, handle: core.BNCollaborationPermissionHandle):
self._handle = ctypes.cast(handle, core.BNCollaborationPermissionHandle)
def __del__(self):
if core is not None:
core.BNFreeCollaborationPermission(self._handle)
def __eq__(self, other):
if not isinstance(other, Permission):
return False
return other.id == self.id
@property
def remote(self) -> 'remote.Remote':
"""
Owning Remote
:return: Remote object
"""
value = core.BNCollaborationPermissionGetRemote(self._handle)
if value is None:
raise RuntimeError(util._last_error())
return remote.Remote(handle=value)
@property
def project(self) -> 'project.RemoteProject':
"""
Owning Project
:return: Project object
"""
value = core.BNCollaborationPermissionGetProject(self._handle)
if value is None:
raise RuntimeError(util._last_error())
return project.RemoteProject(handle=value)
@property
def url(self) -> str:
"""
Web api endpoint url
:return: URL string
"""
return core.BNCollaborationPermissionGetUrl(self._handle)
@property
def id(self) -> str:
"""
Unique id
:return: Id string
"""
return core.BNCollaborationPermissionGetId(self._handle)
@property
def level(self) -> CollaborationPermissionLevel:
"""
Level of permission
:return: Permission level
"""
return CollaborationPermissionLevel(core.BNCollaborationPermissionGetLevel(self._handle))
@level.setter
def level(self, value: CollaborationPermissionLevel):
"""
Change the level of the permission
You will need to push the group to update the Remote.
:param value: New value
"""
core.BNCollaborationPermissionSetLevel(self._handle, value)
@property
def group_id(self) -> Optional[int]:
"""
Id of affected group
:return: Group id, if this is a group permission. Else, None
"""
result = core.BNCollaborationPermissionGetGroupId(self._handle)
if result == 0:
return None
return result
@property
def group_name(self) -> Optional[str]:
"""
Name of affected group
:return: Group name, if this is a group permission. Else, None
"""
result = core.BNCollaborationPermissionGetGroupName(self._handle)
if result == "":
return None
return result
@property
def user_id(self) -> Optional[str]:
"""
Id of affected user
:return: User id, if this is a user permission. Else, None
"""
result = core.BNCollaborationPermissionGetUserId(self._handle)
if result == "":
return None
return result
@property
def username(self) -> Optional[str]:
"""
Name of affected user
:return: User name, if this is a user permission. Else, None
"""
result = core.BNCollaborationPermissionGetUsername(self._handle)
if result == "":
return None
return result
@property
def can_view(self) -> bool:
"""
If the permission grants the affect user/group the ability to read files in the project
:return: True if permission granted
"""
return core.BNCollaborationPermissionCanView(self._handle)
@property
def can_edit(self) -> bool:
"""
If the permission grants the affect user/group the ability to edit files in the project
:return: True if permission granted
"""
return core.BNCollaborationPermissionCanEdit(self._handle)
@property
def can_admin(self) -> bool:
"""
If the permission grants the affect user/group the ability to administer the project
:return: True if permission granted
"""
return core.BNCollaborationPermissionCanAdmin(self._handle)