Skip to content

Commit 3685be4

Browse files
committed
Switch collaboration permission checks to using User object
1 parent 544b7ee commit 3685be4

5 files changed

Lines changed: 39 additions & 41 deletions

File tree

binaryninjaapi.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5774,7 +5774,7 @@ namespace BinaryNinja {
57745774
void PerformDefineRelocation(Architecture* arch, BNRelocationInfo& info, Ref<Symbol> sym, uint64_t reloc);
57755775

57765776
/*! OnAfterSnapshotDataApplied is called when loading a view from a database, after snapshot data has been applied to it.
5777-
5777+
57785778
\note This method **may** be overridden by custom BinaryViews.
57795779

57805780
\warning This method **must not** be called directly.
@@ -23088,9 +23088,9 @@ namespace BinaryNinja::Collaboration
2308823088
Ref<CollabPermission> CreateUserPermission(const std::string& userId, BNCollaborationPermissionLevel level, ProgressFunction progress = {});
2308923089
void PushPermission(Ref<CollabPermission> permission, const std::vector<std::pair<std::string, std::string>>& extraFields = {});
2309023090
void DeletePermission(Ref<CollabPermission> permission);
23091-
bool CanUserView(const std::string& username);
23092-
bool CanUserEdit(const std::string& username);
23093-
bool CanUserAdmin(const std::string& username);
23091+
bool CanUserView(Ref<CollabUser> user);
23092+
bool CanUserEdit(Ref<CollabUser> user);
23093+
bool CanUserAdmin(Ref<CollabUser> user);
2309423094
};
2309523095

2309623096
class AnalysisMergeConflict : public CoreRefCountObject<BNAnalysisMergeConflict, BNNewAnalysisMergeConflictReference, BNFreeAnalysisMergeConflict>

binaryninjacore.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8667,9 +8667,9 @@ extern "C"
86678667
BINARYNINJACOREAPI BNCollaborationPermission* BNRemoteProjectCreateUserPermission(BNRemoteProject* project, const char* userId, BNCollaborationPermissionLevel level, BNProgressFunction progress, void* progressContext);
86688668
BINARYNINJACOREAPI bool BNRemoteProjectPushPermission(BNRemoteProject* project, BNCollaborationPermission* permission, const char** extraFieldKeys, const char** extraFieldValues, size_t extraFieldCount);
86698669
BINARYNINJACOREAPI bool BNRemoteProjectDeletePermission(BNRemoteProject* project, BNCollaborationPermission* permission);
8670-
BINARYNINJACOREAPI bool BNRemoteProjectCanUserView(BNRemoteProject* project, const char* username);
8671-
BINARYNINJACOREAPI bool BNRemoteProjectCanUserEdit(BNRemoteProject* project, const char* username);
8672-
BINARYNINJACOREAPI bool BNRemoteProjectCanUserAdmin(BNRemoteProject* project, const char* username);
8670+
BINARYNINJACOREAPI bool BNRemoteProjectCanUserView(BNRemoteProject* project, BNCollaborationUser* user);
8671+
BINARYNINJACOREAPI bool BNRemoteProjectCanUserEdit(BNRemoteProject* project, BNCollaborationUser* user);
8672+
BINARYNINJACOREAPI bool BNRemoteProjectCanUserAdmin(BNRemoteProject* project, BNCollaborationUser* user);
86738673

86748674
// RemoteFile
86758675
BINARYNINJACOREAPI BNRemoteFile* BNNewRemoteFileReference(BNRemoteFile* file);

collaboration.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1566,21 +1566,21 @@ void RemoteProject::DeletePermission(Ref<CollabPermission> permission)
15661566
}
15671567

15681568

1569-
bool RemoteProject::CanUserView(const std::string& username)
1569+
bool RemoteProject::CanUserView(Ref<CollabUser> user)
15701570
{
1571-
return BNRemoteProjectCanUserView(m_object, username.c_str());
1571+
return BNRemoteProjectCanUserView(m_object, user->m_object);
15721572
}
15731573

15741574

1575-
bool RemoteProject::CanUserEdit(const std::string& username)
1575+
bool RemoteProject::CanUserEdit(Ref<CollabUser> user)
15761576
{
1577-
return BNRemoteProjectCanUserEdit(m_object, username.c_str());
1577+
return BNRemoteProjectCanUserEdit(m_object, user->m_object);
15781578
}
15791579

15801580

1581-
bool RemoteProject::CanUserAdmin(const std::string& username)
1581+
bool RemoteProject::CanUserAdmin(Ref<CollabUser> user)
15821582
{
1583-
return BNRemoteProjectCanUserAdmin(m_object, username.c_str());
1583+
return BNRemoteProjectCanUserAdmin(m_object, user->m_object);
15841584
}
15851585

15861586

python/collaboration/project.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from ..database import Database
1212
from ..filemetadata import FileMetadata
1313
from ..project import Project
14-
from . import databasesync, file, folder, permission, remote, util
14+
from . import databasesync, file, folder, permission, remote, user, util
1515

1616

1717
def _nop(*args, **kwargs):
@@ -713,35 +713,35 @@ def delete_permission(self, permission: 'permission.Permission'):
713713
if not core.BNRemoteProjectDeletePermission(self._handle, permission._handle):
714714
raise RuntimeError(util._last_error())
715715

716-
def can_user_view(self, username: str) -> bool:
716+
def can_user_view(self, user: user.User) -> bool:
717717
"""
718718
Determine if a user is in any of the view/edit/admin groups
719719
720-
:param username: Username of user to check
721-
:return: True if they are in any of those groups
720+
:param user: User to check
721+
:return: True if the user has view permission (either directly or from a group)
722722
:raises: RuntimeError if there was an error
723723
"""
724-
return core.BNRemoteProjectCanUserView(self._handle, username)
724+
return core.BNRemoteProjectCanUserView(self._handle, user._handle)
725725

726-
def can_user_edit(self, username: str) -> bool:
726+
def can_user_edit(self, user: user.User) -> bool:
727727
"""
728728
Determine if a user is in any of the edit/admin groups
729729
730-
:param username: Username of user to check
731-
:return: True if they are in any of those groups
730+
:param user: User to check
731+
:return: True if the user has edit permission (either directly or from a group)
732732
:raises: RuntimeError if there was an error
733733
"""
734-
return core.BNRemoteProjectCanUserEdit(self._handle, username)
734+
return core.BNRemoteProjectCanUserEdit(self._handle, user._handle)
735735

736-
def can_user_admin(self, username: str) -> bool:
736+
def can_user_admin(self, user: user.User) -> bool:
737737
"""
738738
Determine if a user is in the admin group
739739
740-
:param username: Username of user to check
741-
:return: True if they are in any of those groups
740+
:param user: User to check
741+
:return: True if the user has admin permission (either directly or from a group)
742742
:raises: RuntimeError if there was an error
743743
"""
744-
return core.BNRemoteProjectCanUserAdmin(self._handle, username)
744+
return core.BNRemoteProjectCanUserAdmin(self._handle, user._handle)
745745

746746
def upload_new_file(
747747
self,

rust/src/collaboration/project.rs

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use super::{
1212
};
1313

1414
use crate::binary_view::{BinaryView, BinaryViewExt};
15+
use crate::collaboration::RemoteUser;
1516
use crate::database::Database;
1617
use crate::file_metadata::FileMetadata;
1718
use crate::progress::{NoProgressCallback, ProgressCallback};
@@ -761,34 +762,31 @@ impl RemoteProject {
761762
success.then_some(()).ok_or(())
762763
}
763764

764-
/// Determine if a user is in any of the view/edit/admin groups.
765+
/// Determine if a user has view permission (either directly or from a group)
765766
///
766767
/// # Arguments
767768
///
768-
/// * `username` - Username of user to check
769-
pub fn can_user_view(&self, username: &str) -> bool {
770-
let username = username.to_cstr();
771-
unsafe { BNRemoteProjectCanUserView(self.handle.as_ptr(), username.as_ptr()) }
769+
/// * `user` - User to check
770+
pub fn can_user_view(&self, user: Ref<RemoteUser>) -> bool {
771+
unsafe { BNRemoteProjectCanUserView(self.handle.as_ptr(), user.handle.as_ptr()) }
772772
}
773773

774-
/// Determine if a user is in any of the edit/admin groups.
774+
/// Determine if a user has edit permission (either directly or from a group)
775775
///
776776
/// # Arguments
777777
///
778-
/// * `username` - Username of user to check
779-
pub fn can_user_edit(&self, username: &str) -> bool {
780-
let username = username.to_cstr();
781-
unsafe { BNRemoteProjectCanUserEdit(self.handle.as_ptr(), username.as_ptr()) }
778+
/// * `user` - User to check
779+
pub fn can_user_edit(&self, user: Ref<RemoteUser>) -> bool {
780+
unsafe { BNRemoteProjectCanUserEdit(self.handle.as_ptr(), user.handle.as_ptr()) }
782781
}
783782

784-
/// Determine if a user is in the admin group.
783+
/// Determine if a user has admin permission (either directly or from a group)
785784
///
786785
/// # Arguments
787786
///
788-
/// * `username` - Username of user to check
789-
pub fn can_user_admin(&self, username: &str) -> bool {
790-
let username = username.to_cstr();
791-
unsafe { BNRemoteProjectCanUserAdmin(self.handle.as_ptr(), username.as_ptr()) }
787+
/// * `user` - User to check
788+
pub fn can_user_admin(&self, user: Ref<RemoteUser>) -> bool {
789+
unsafe { BNRemoteProjectCanUserAdmin(self.handle.as_ptr(), user.handle.as_ptr()) }
792790
}
793791

794792
/// Get the default directory path for a remote Project. This is based off

0 commit comments

Comments
 (0)