Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow querying users without being a principal known to the UserIndex #4426

Merged
merged 4 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading