Skip to content

Commit

Permalink
Allow querying users without being a principal known to the UserIndex (
Browse files Browse the repository at this point in the history
  • Loading branch information
hpeebles authored Sep 22, 2023
1 parent 12b4940 commit 079ee0c
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 14 deletions.
1 change: 1 addition & 0 deletions backend/canisters/user_index/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Changed

- Allow bots to register with display names ([#4377](https://github.com/open-chat-labs/open-chat/pull/4377))
- Allow querying users without being a known user principal ([#4426](https://github.com/open-chat-labs/open-chat/pull/4426))

## [[2.0.840](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.840-user_index)] - 2023-09-06

Expand Down
8 changes: 0 additions & 8 deletions backend/canisters/user_index/impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,6 @@ impl RuntimeState {
RuntimeState { env, data }
}

/// Traps if the caller is not an OpenChat user or an OpenChat user's canister
pub fn trap_if_caller_not_openchat_user(&self) {
if !self.is_caller_openchat_user() {
#[cfg(not(test))]
ic_cdk::trap("Not authorized");
}
}

pub fn is_caller_openchat_user(&self) -> bool {
let caller = self.env.caller();
self.data.users.get(&caller).is_some()
Expand Down
2 changes: 0 additions & 2 deletions backend/canisters/user_index/impl/src/queries/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ fn search(args: Args) -> Response {
}

fn search_impl(args: Args, state: &RuntimeState) -> Response {
state.trap_if_caller_not_openchat_user();

let caller = state.env.caller();
let now = state.env.now();
let users = &state.data.users;
Expand Down
2 changes: 0 additions & 2 deletions backend/canisters/user_index/impl/src/queries/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ fn user(args: Args) -> Response {
}

fn user_impl(args: Args, state: &RuntimeState) -> Response {
state.trap_if_caller_not_openchat_user();

let mut user = None;
if let Some(user_id) = args.user_id {
user = state.data.users.get_by_user_id(&user_id);
Expand Down
2 changes: 0 additions & 2 deletions backend/canisters/user_index/impl/src/queries/users.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ fn users_v2(args: Args) -> Response {
}

fn users_impl(args: Args, state: &RuntimeState) -> Response {
state.trap_if_caller_not_openchat_user();

let now = state.env.now();

let users = args
Expand Down

0 comments on commit 079ee0c

Please sign in to comment.