diff options
| author | Josh Ferrell <josh@vector35.com> | 2026-04-14 16:22:40 -0400 |
|---|---|---|
| committer | Josh Ferrell <josh@vector35.com> | 2026-05-05 14:46:15 -0400 |
| commit | af50b06082044fcbbf730deda985d0133ca98b88 (patch) | |
| tree | 6b1ae5a4678d8a39a88af4de2cd150663e1a9c8e /python | |
| parent | e4db4f0704ea6e6b381e9322a336661dc23c3b5f (diff) | |
Switch collaboration permission checks to using User objects
Diffstat (limited to 'python')
| -rw-r--r-- | python/collaboration/group.py | 43 | ||||
| -rw-r--r-- | python/collaboration/project.py | 26 | ||||
| -rw-r--r-- | python/collaboration/remote.py | 12 |
3 files changed, 39 insertions, 42 deletions
diff --git a/python/collaboration/group.py b/python/collaboration/group.py index d1fbd9d0..967e52f1 100644 --- a/python/collaboration/group.py +++ b/python/collaboration/group.py @@ -2,7 +2,7 @@ import ctypes from typing import List, Tuple from .. import _binaryninjacore as core -from . import remote, util +from . import remote, user, util class Group: @@ -70,43 +70,40 @@ class Group: core.BNCollaborationGroupSetName(self._handle, name) @property - def users(self) -> List[Tuple[str, str]]: + def users(self) -> List[user.User]: """ Get list of users in the group - :return: List of (userid, username) pairs + :return: List of users """ count = ctypes.c_size_t() - user_ids = ctypes.POINTER(ctypes.c_char_p)() - usernames = ctypes.POINTER(ctypes.c_char_p)() - if not core.BNCollaborationGroupGetUsers(self._handle, user_ids, usernames, count): + result = core.BNCollaborationGroupGetUsers(self._handle, count) + if not result: raise RuntimeError(util._last_error()) - result = [] + out = [] for i in range(count.value): - result.append((core.pyNativeStr(user_ids[i]), core.pyNativeStr(usernames[i]))) - core.BNFreeStringList(user_ids, count.value) - core.BNFreeStringList(usernames, count.value) - return result + out.append(user.User(result[i])) + return out @users.setter - def users(self, usernames: List[str]): + def users(self, users: List[user.User]): """ - Set the list of users in a group by their usernames. + Set the list of users in a group. You will need to push the group to update the Remote. - :param usernames: Usernames of new group members + :param users: New group members """ - array = (ctypes.c_char_p * len(usernames))() - for i in range(len(usernames)): - array[i] = core.cstr(usernames[i]) - if not core.BNCollaborationGroupSetUsernames(self._handle, array, len(usernames)): + array = ctypes.POINTER(core.BNCollaborationUserHandle)() + for i in range(len(users)): + array[i] = users[i]._handle + if not core.BNCollaborationGroupSetUsers(self._handle, array, len(users)): raise RuntimeError(util._last_error()) - def contains_user(self, username: str) -> bool: + def contains_user(self, user: user.User) -> bool: """ - Test if a group has a user with the given username + Test if a group contains a user - :param username: Username of user to check membership - :return: If the user is in the group + :param user: User to check membership of + :return: If the group contains the user """ - return core.BNCollaborationGroupContainsUser(self._handle, username) + return core.BNCollaborationGroupContainsUser(self._handle, user._handle) diff --git a/python/collaboration/project.py b/python/collaboration/project.py index a143e6d9..f78e488e 100644 --- a/python/collaboration/project.py +++ b/python/collaboration/project.py @@ -11,7 +11,7 @@ from ..binaryview import BinaryView, ProgressFuncType from ..database import Database from ..filemetadata import FileMetadata from ..project import Project -from . import databasesync, file, folder, permission, remote, util +from . import databasesync, file, folder, permission, remote, user, util def _nop(*args, **kwargs): @@ -713,35 +713,35 @@ class RemoteProject: if not core.BNRemoteProjectDeletePermission(self._handle, permission._handle): raise RuntimeError(util._last_error()) - def can_user_view(self, username: str) -> bool: + def can_user_view(self, user: user.User) -> bool: """ Determine if a user is in any of the view/edit/admin groups - :param username: Username of user to check - :return: True if they are in any of those groups + :param user: User to check + :return: True if the user has view permission (either directly or from a group) :raises: RuntimeError if there was an error """ - return core.BNRemoteProjectCanUserView(self._handle, username) + return core.BNRemoteProjectCanUserView(self._handle, user._handle) - def can_user_edit(self, username: str) -> bool: + def can_user_edit(self, user: user.User) -> bool: """ Determine if a user is in any of the edit/admin groups - :param username: Username of user to check - :return: True if they are in any of those groups + :param user: User to check + :return: True if the user has edit permission (either directly or from a group) :raises: RuntimeError if there was an error """ - return core.BNRemoteProjectCanUserEdit(self._handle, username) + return core.BNRemoteProjectCanUserEdit(self._handle, user._handle) - def can_user_admin(self, username: str) -> bool: + def can_user_admin(self, user: user.User) -> bool: """ Determine if a user is in the admin group - :param username: Username of user to check - :return: True if they are in any of those groups + :param user: User to check + :return: True if the user has admin permission (either directly or from a group) :raises: RuntimeError if there was an error """ - return core.BNRemoteProjectCanUserAdmin(self._handle, username) + return core.BNRemoteProjectCanUserAdmin(self._handle, user._handle) def upload_new_file( self, diff --git a/python/collaboration/remote.py b/python/collaboration/remote.py index 811fd33b..1cbdb424 100644 --- a/python/collaboration/remote.py +++ b/python/collaboration/remote.py @@ -520,22 +520,22 @@ class Remote: if not core.BNRemotePullGroups(self._handle, util.wrap_progress(progress), None): raise RuntimeError(util._last_error()) - def create_group(self, name: str, usernames: List[str]) -> 'group.Group': + def create_group(self, name: str, users: List[user.User]) -> 'group.Group': """ Create a new group on the remote (and pull it) .. note:: This function is only available to accounts with admin status on the Remote :param name: Group name - :param usernames: List of usernames of users in the group + :param users: List of users in the group :return: Reference to the created group :raises: RuntimeError if there was an error """ - c_usernames = (ctypes.c_char_p * len(usernames))() - for (i, username) in enumerate(usernames): - c_usernames[i] = core.cstr(username) + c_users = (core.BNCollaborationUserHandle * len(users))() + for (i, member) in enumerate(users): + c_users[i] = member._handle - value = core.BNRemoteCreateGroup(self._handle, name, c_usernames, len(usernames)) + value = core.BNRemoteCreateGroup(self._handle, name, c_users, len(users)) if value is None: raise RuntimeError(util._last_error()) return group.Group(value) |
