Skip to content

Commit

Permalink
Remove diamond only access to set display name (#6879)
Browse files Browse the repository at this point in the history
  • Loading branch information
megrogan authored Nov 22, 2024
1 parent 2247e37 commit ac0bb97
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 71 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 @@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Pass in `BotApiCanister` when installing a new LocalUserIndex ([#6828](https://github.com/open-chat-labs/open-chat/pull/6828))
- Simplify `inspect_message` ([#6847](https://github.com/open-chat-labs/open-chat/pull/6847))
- Allow bots to set a display name when registering ([#6850](https://github.com/open-chat-labs/open-chat/pull/6850))
- Remove diamond only access to set display name ([#6879](https://github.com/open-chat-labs/open-chat/pull/6879))

## [[2.0.1450](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.1450-user_index)] - 2024-11-14

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ pub struct Args {
#[derive(CandidType, Serialize, Deserialize, Debug)]
pub enum Response {
Success,
Unauthorized,
UserNotFound,
DisplayNameInvalid,
DisplayNameTooShort(u16),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ fn set_display_name_impl(args: Args, state: &mut RuntimeState) -> Response {
}

let now = state.env.now();
if !user.diamond_membership_details.is_active(now) && user.display_name.is_none() {
return Unauthorized;
}

let mut user_to_update = user.clone();
user_to_update.display_name.clone_from(&args.display_name);
let user_id = user.user_id;
Expand Down
26 changes: 0 additions & 26 deletions backend/integration_tests/src/update_profile_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,29 +63,3 @@ fn update_display_name_succeeds() {
let updates = client::user::happy_path::updates(env, &user, now - 1);
assert_eq!(updates.unwrap().display_name, OptionUpdate::SetToSome(display_name));
}

#[test]
fn update_display_name_unauthorized_if_not_diamond_member() {
let mut wrapper = ENV.deref().get();
let TestEnv { env, canister_ids, .. } = wrapper.env();

let user = client::register_user(env, canister_ids);

env.advance_time(Duration::from_secs(10));

let display_name = random_string();

let response = client::user_index::set_display_name(
env,
user.principal,
canister_ids.user_index,
&user_index_canister::set_display_name::Args {
display_name: Some(display_name.clone()),
},
);

assert!(matches!(
response,
user_index_canister::set_display_name::Response::Unauthorized
));
}
41 changes: 12 additions & 29 deletions frontend/app/src/components/DisplayNameInput.svelte
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
<script lang="ts">
import Input from "./Input.svelte";
import { createEventDispatcher, onMount } from "svelte";
import { onMount } from "svelte";
import { _ } from "svelte-i18n";
import type { OpenChat } from "openchat-client";
import { isDiamond } from "openchat-client";
import Button from "./Button.svelte";
import Translatable from "./Translatable.svelte";
import { i18nKey } from "../i18n/i18n";
const MIN_DISPLAY_NAME_LENGTH = 3;
const MAX_DISPLAY_NAME_LENGTH = 25;
const dispatch = createEventDispatcher();
export let client: OpenChat;
export let originalDisplayName: string | undefined;
Expand Down Expand Up @@ -38,27 +34,14 @@
}
</script>

{#if $isDiamond || originalDisplayName !== undefined}
<Input
on:change={onChange}
value={originalDisplayName ?? ""}
{disabled}
{invalid}
minlength={MIN_DISPLAY_NAME_LENGTH}
maxlength={MAX_DISPLAY_NAME_LENGTH}
countdown
placeholder={i18nKey("register.enterDisplayName")}>
<slot />
</Input>
{:else}
<div class="upgrade">
<Button fill on:click={() => dispatch("upgrade")}
><Translatable resourceKey={i18nKey("upgrade.forDisplayName")} /></Button>
</div>
{/if}

<style lang="scss">
.upgrade {
margin-bottom: $sp3;
}
</style>
<Input
on:change={onChange}
value={originalDisplayName ?? ""}
{disabled}
{invalid}
minlength={MIN_DISPLAY_NAME_LENGTH}
maxlength={MAX_DISPLAY_NAME_LENGTH}
countdown
placeholder={i18nKey("register.enterDisplayName")}>
<slot />
</Input>
10 changes: 0 additions & 10 deletions frontend/app/src/components/home/upgrade/Features.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -208,16 +208,6 @@
</div>
</Feature>

<Feature {landing}>
<div slot="title"><Translatable resourceKey={i18nKey("upgrade.displayNames")} /></div>
<div slot="free">
<Minus size={"1em"} color={"var(--menu-warn)"} />
</div>
<div slot="diamond">
<Check size={"1em"} color={"limegreen"} />
</div>
</Feature>

<Feature {landing} diamondInfo={i18nKey("upgrade.airdropsInfo")}>
<div slot="title"><Translatable resourceKey={i18nKey("upgrade.airdrops")} /></div>
<div slot="free">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.

export type UserIndexSetDisplayNameResponse = "Success" | "Unauthorized" | "UserNotFound" | "DisplayNameInvalid" | { "DisplayNameTooShort": number } | { "DisplayNameTooLong": number };
export type UserIndexSetDisplayNameResponse = "Success" | "UserNotFound" | "DisplayNameInvalid" | { "DisplayNameTooShort": number } | { "DisplayNameTooLong": number };

0 comments on commit ac0bb97

Please sign in to comment.