From 6ec0932119266624b6635d44758bbccc46b3eec5 Mon Sep 17 00:00:00 2001 From: Hamish Peebles Date: Mon, 9 Oct 2023 10:39:57 +0100 Subject: [PATCH] Remove `add_governance_canister` since it is now automated (#4532) --- backend/canisters/proposals_bot/CHANGELOG.md | 4 + .../src/updates/add_governance_canister.rs | 43 ------ .../proposals_bot/api/src/updates/mod.rs | 2 - .../src/updates/remove_governance_canister.rs | 34 ----- .../impl/src/model/nervous_systems.rs | 4 - .../src/updates/add_governance_canister.rs | 141 ------------------ .../proposals_bot/impl/src/updates/mod.rs | 2 - .../src/updates/remove_governance_canister.rs | 37 ----- scripts/proposals/add_governance_canister.sh | 20 --- .../proposals/remove_governance_canister.sh | 0 ....proposals_bot.add_governance_canister.ini | 3 - ...oposals_bot.remove_governance_canister.ini | 3 - 12 files changed, 4 insertions(+), 289 deletions(-) delete mode 100644 backend/canisters/proposals_bot/api/src/updates/add_governance_canister.rs delete mode 100644 backend/canisters/proposals_bot/api/src/updates/remove_governance_canister.rs delete mode 100644 backend/canisters/proposals_bot/impl/src/updates/add_governance_canister.rs delete mode 100644 backend/canisters/proposals_bot/impl/src/updates/remove_governance_canister.rs delete mode 100755 scripts/proposals/add_governance_canister.sh delete mode 100755 scripts/proposals/remove_governance_canister.sh delete mode 100644 sns/scripts/proposals/create_custom_sns_functions/4000.proposals_bot.add_governance_canister.ini delete mode 100644 sns/scripts/proposals/create_custom_sns_functions/4001.proposals_bot.remove_governance_canister.ini diff --git a/backend/canisters/proposals_bot/CHANGELOG.md b/backend/canisters/proposals_bot/CHANGELOG.md index d1fc6e9802..e5146cf29f 100644 --- a/backend/canisters/proposals_bot/CHANGELOG.md +++ b/backend/canisters/proposals_bot/CHANGELOG.md @@ -9,6 +9,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Automatically create proposals groups for new SNSes ([#4528](https://github.com/open-chat-labs/open-chat/pull/4528)) +### Removed + +- Remove `add_governance_canister` since it is now automated ([#4532](https://github.com/open-chat-labs/open-chat/pull/4532)) + ## [[2.0.876](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.876-proposals_bot)] - 2023-10-09 ### Added diff --git a/backend/canisters/proposals_bot/api/src/updates/add_governance_canister.rs b/backend/canisters/proposals_bot/api/src/updates/add_governance_canister.rs deleted file mode 100644 index 0ed8ae7382..0000000000 --- a/backend/canisters/proposals_bot/api/src/updates/add_governance_canister.rs +++ /dev/null @@ -1,43 +0,0 @@ -use candid::CandidType; -use human_readable::{HumanReadablePrincipal, ToHumanReadable}; -use serde::{Deserialize, Serialize}; -use types::{CanisterId, CommunityId, Document}; - -#[derive(CandidType, Serialize, Deserialize, Debug)] -pub struct Args { - pub governance_canister_id: CanisterId, - pub community_id: Option, - pub name: String, - pub description: Option, - pub avatar: Option, -} - -#[derive(CandidType, Serialize, Deserialize, Debug)] -pub enum Response { - Success, - AlreadyAdded, - InternalError(String), -} - -#[derive(Serialize)] -pub struct HumanReadableArgs { - governance_canister_id: HumanReadablePrincipal, - community_id: Option, - name: String, - description: Option, - avatar: Option, -} - -impl ToHumanReadable for Args { - type Target = HumanReadableArgs; - - fn to_human_readable(&self) -> Self::Target { - HumanReadableArgs { - governance_canister_id: self.governance_canister_id.into(), - community_id: self.community_id.map(|c| CanisterId::from(c).into()), - name: self.name.clone(), - description: self.description.clone(), - avatar: self.avatar.as_ref().map(|a| format!("{a:?}")), - } - } -} diff --git a/backend/canisters/proposals_bot/api/src/updates/mod.rs b/backend/canisters/proposals_bot/api/src/updates/mod.rs index 391d1ab998..d5bd506bc1 100644 --- a/backend/canisters/proposals_bot/api/src/updates/mod.rs +++ b/backend/canisters/proposals_bot/api/src/updates/mod.rs @@ -1,6 +1,4 @@ -pub mod add_governance_canister; pub mod appoint_admins; pub mod c2c_submit_proposal; pub mod import_proposals_group_into_community; -pub mod remove_governance_canister; pub mod stake_neuron_for_submitting_proposals; diff --git a/backend/canisters/proposals_bot/api/src/updates/remove_governance_canister.rs b/backend/canisters/proposals_bot/api/src/updates/remove_governance_canister.rs deleted file mode 100644 index 75101e0804..0000000000 --- a/backend/canisters/proposals_bot/api/src/updates/remove_governance_canister.rs +++ /dev/null @@ -1,34 +0,0 @@ -use candid::CandidType; -use human_readable::{HumanReadablePrincipal, ToHumanReadable}; -use serde::{Deserialize, Serialize}; -use types::CanisterId; - -#[derive(CandidType, Serialize, Deserialize, Debug)] -pub struct Args { - pub governance_canister_id: CanisterId, - pub delete_group: bool, -} - -#[derive(CandidType, Serialize, Deserialize, Debug)] -pub enum Response { - Success, - NotFound, - InternalError(String), -} - -#[derive(Serialize)] -pub struct HumanReadableArgs { - governance_canister_id: HumanReadablePrincipal, - delete_group: bool, -} - -impl ToHumanReadable for Args { - type Target = HumanReadableArgs; - - fn to_human_readable(&self) -> Self::Target { - HumanReadableArgs { - governance_canister_id: self.governance_canister_id.into(), - delete_group: self.delete_group, - } - } -} diff --git a/backend/canisters/proposals_bot/impl/src/model/nervous_systems.rs b/backend/canisters/proposals_bot/impl/src/model/nervous_systems.rs index 5ff7d060cf..a5443158da 100644 --- a/backend/canisters/proposals_bot/impl/src/model/nervous_systems.rs +++ b/backend/canisters/proposals_bot/impl/src/model/nervous_systems.rs @@ -44,10 +44,6 @@ impl NervousSystems { } } - pub fn remove(&mut self, governance_canister_id: &CanisterId) -> bool { - self.nervous_systems.remove(governance_canister_id).is_some() - } - pub fn exists(&self, governance_canister_id: &CanisterId) -> bool { self.nervous_systems.contains_key(governance_canister_id) } diff --git a/backend/canisters/proposals_bot/impl/src/updates/add_governance_canister.rs b/backend/canisters/proposals_bot/impl/src/updates/add_governance_canister.rs deleted file mode 100644 index 0ffa35b14c..0000000000 --- a/backend/canisters/proposals_bot/impl/src/updates/add_governance_canister.rs +++ /dev/null @@ -1,141 +0,0 @@ -use crate::guards::caller_is_governance_principal; -use crate::{mutate_state, read_state, RuntimeState}; -use canister_api_macros::proposal; -use canister_tracing_macros::trace; -use proposals_bot_canister::add_governance_canister::{Response::*, *}; -use std::fmt::Write; -use types::{GovernanceProposalsSubtype, GroupPermissionRole, GroupPermissions, GroupSubtype, MultiUserChat, Rules}; - -// dfx --identity openchat canister --network ic call proposals_bot add_governance_canister '(record { governance_canister_id=principal "rrkah-fqaaa-aaaaa-aaaaq-cai"; name="NNS" })' -#[proposal(guard = "caller_is_governance_principal")] -#[trace] -async fn add_governance_canister(args: Args) -> Response { - let PrepareResult { is_nns } = match read_state(|state| prepare(&args, state)) { - Ok(ok) => ok, - Err(response) => return response, - }; - - let chat_id = match create_group_or_channel(&args, is_nns).await { - Ok(id) => id, - Err(response) => return response, - }; - - mutate_state(|state| { - state.data.nervous_systems.add(args.governance_canister_id, chat_id); - }); - - Success -} - -struct PrepareResult { - is_nns: bool, -} - -fn prepare(args: &Args, state: &RuntimeState) -> Result { - if state.data.nervous_systems.exists(&args.governance_canister_id) { - Err(AlreadyAdded) - } else { - Ok(PrepareResult { - is_nns: args.governance_canister_id == state.data.nns_governance_canister_id, - }) - } -} - -async fn create_group_or_channel(args: &Args, is_nns: bool) -> Result { - if args.community_id.is_some() { - create_channel(args, is_nns).await - } else { - create_group(args, is_nns).await - } -} - -async fn create_group(args: &Args, is_nns: bool) -> Result { - let group_index_canister_id = read_state(|state| state.data.group_index_canister_id); - - let create_group_args = group_index_canister::c2c_create_group::Args { - is_public: true, - name: format!("{} Proposals", &args.name), - description: args - .description - .clone() - .unwrap_or_else(|| default_description(&args.name, false)), - rules: Rules::default(), - subtype: Some(GroupSubtype::GovernanceProposals(GovernanceProposalsSubtype { - governance_canister_id: args.governance_canister_id, - is_nns, - })), - avatar: args.avatar.clone(), - history_visible_to_new_joiners: true, - permissions: Some(GroupPermissions { - create_polls: GroupPermissionRole::Admins, - send_messages: GroupPermissionRole::Admins, - ..Default::default() - }), - events_ttl: None, - gate: None, - }; - - match group_index_canister_c2c_client::c2c_create_group(group_index_canister_id, &create_group_args).await { - Ok(group_index_canister::c2c_create_group::Response::Success(result)) => Ok(MultiUserChat::Group(result.chat_id)), - Ok(response) => Err(InternalError(format!("Unable to create group: {response:?}"))), - Err(error) => Err(InternalError(format!( - "Error calling 'c2c_create_group' on group_index: {error:?}", - ))), - } -} - -async fn create_channel(args: &Args, is_nns: bool) -> Result { - let create_channel_args = community_canister::c2c_create_proposals_channel::Args { - is_public: true, - name: format!("{} Proposals", &args.name), - description: args - .description - .clone() - .unwrap_or_else(|| default_description(&args.name, true)), - rules: Rules::default(), - subtype: Some(GroupSubtype::GovernanceProposals(GovernanceProposalsSubtype { - governance_canister_id: args.governance_canister_id, - is_nns, - })), - avatar: args.avatar.clone(), - history_visible_to_new_joiners: true, - permissions: Some(GroupPermissions { - create_polls: GroupPermissionRole::Admins, - send_messages: GroupPermissionRole::Admins, - ..Default::default() - }), - events_ttl: None, - gate: None, - }; - - let community_id = args.community_id.unwrap(); - - match community_canister_c2c_client::c2c_create_proposals_channel(community_id.into(), &create_channel_args).await { - Ok(community_canister::c2c_create_proposals_channel::Response::Success(result)) => { - Ok(MultiUserChat::Channel(community_id, result.channel_id)) - } - Ok(response) => Err(InternalError(format!("Unable to create channel: {response:?}"))), - Err(error) => Err(InternalError(format!( - "Error calling 'create_channel' on community: {error:?}", - ))), - } -} - -fn default_description(name: &str, is_channel: bool) -> String { - let chat_type = if is_channel { "channel" } else { "group" }; - let mut description = String::new(); - writeln!( - &mut description, - "Join this {chat_type} to view and vote on {name} proposals." - ) - .unwrap(); - writeln!(&mut description).unwrap(); - writeln!( - &mut description, - "To vote on proposals you must add your user id as a hotkey to any {name} neurons you wish to vote with." - ) - .unwrap(); - writeln!(&mut description).unwrap(); - writeln!(&mut description, "Your OpenChat user id is {{userId}}.").unwrap(); - description -} diff --git a/backend/canisters/proposals_bot/impl/src/updates/mod.rs b/backend/canisters/proposals_bot/impl/src/updates/mod.rs index a2f8cb5542..7465ff1baf 100644 --- a/backend/canisters/proposals_bot/impl/src/updates/mod.rs +++ b/backend/canisters/proposals_bot/impl/src/updates/mod.rs @@ -1,7 +1,5 @@ -pub mod add_governance_canister; pub mod appoint_admins; pub mod c2c_submit_proposal; pub mod import_proposals_group_into_community; -pub mod remove_governance_canister; pub mod stake_neuron_for_submitting_proposals; pub mod wallet_receive; diff --git a/backend/canisters/proposals_bot/impl/src/updates/remove_governance_canister.rs b/backend/canisters/proposals_bot/impl/src/updates/remove_governance_canister.rs deleted file mode 100644 index 26cf3eeb16..0000000000 --- a/backend/canisters/proposals_bot/impl/src/updates/remove_governance_canister.rs +++ /dev/null @@ -1,37 +0,0 @@ -use crate::guards::caller_is_governance_principal; -use crate::{mutate_state, read_state}; -use canister_api_macros::proposal; -use canister_tracing_macros::trace; -use proposals_bot_canister::remove_governance_canister::{Response::*, *}; -use types::MultiUserChat; - -// dfx --identity openchat canister --network ic call proposals_bot remove_governance_canister '(record { governance_canister_id=principal "rrkah-fqaaa-aaaaa-aaaaq-cai"; delete_group=true })' -#[proposal(guard = "caller_is_governance_principal")] -#[trace] -async fn remove_governance_canister(args: Args) -> Response { - if let Some(chat_id) = read_state(|state| state.data.nervous_systems.get_chat_id(&args.governance_canister_id)) { - if args.delete_group { - match chat_id { - MultiUserChat::Group(group_id) => { - let delete_group_args = group_canister::c2c_delete_group::Args {}; - if let Err(error) = group_canister_c2c_client::c2c_delete_group(group_id.into(), &delete_group_args).await { - return InternalError(format!("{error:?}")); - } - } - MultiUserChat::Channel(community_id, channel_id) => { - let delete_channel_args = community_canister::delete_channel::Args { channel_id }; - if let Err(error) = - community_canister_c2c_client::delete_channel(community_id.into(), &delete_channel_args).await - { - return InternalError(format!("{error:?}")); - } - } - } - } - - mutate_state(|state| state.data.nervous_systems.remove(&args.governance_canister_id)); - Success - } else { - NotFound - } -} diff --git a/scripts/proposals/add_governance_canister.sh b/scripts/proposals/add_governance_canister.sh deleted file mode 100755 index 70fe0d4ff3..0000000000 --- a/scripts/proposals/add_governance_canister.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/sh - -# Extract the args or use defaults -GOVERNANCE_CANISTER_ID=$1 -NAME=$2 -TITLE=$3 -SUMMARY=$4 -URL=$5 - -# Set current directory to the scripts root -SCRIPT=$(readlink -f "$0") -SCRIPT_DIR=$(dirname "$SCRIPT") -cd $SCRIPT_DIR/.. - -# add_platform_operator args -ARGS="(record { governance_canister_id=principal \"$GOVERNANCE_CANISTER_ID\"; name=\"$NAME\"; })" -FUNCTION_ID=4000 - -# Submit the proposal -./make_custom_function_proposal.sh $FUNCTION_ID "$TITLE" "$SUMMARY" "$URL" "$ARGS" diff --git a/scripts/proposals/remove_governance_canister.sh b/scripts/proposals/remove_governance_canister.sh deleted file mode 100755 index e69de29bb2..0000000000 diff --git a/sns/scripts/proposals/create_custom_sns_functions/4000.proposals_bot.add_governance_canister.ini b/sns/scripts/proposals/create_custom_sns_functions/4000.proposals_bot.add_governance_canister.ini deleted file mode 100644 index 77271035a7..0000000000 --- a/sns/scripts/proposals/create_custom_sns_functions/4000.proposals_bot.add_governance_canister.ini +++ /dev/null @@ -1,3 +0,0 @@ -FUNCTION_NAME="Add SNS proposals group" -FUNCTION_DESC="This will create a new proposals group with the given details and sync it with proposals from the given SNS governance canister." -URL="https://github.com/open-chat-labs/open-chat/blob/8a4aecfeebffc2c7fd49fb1233448eef7296f51e/backend/canisters/proposals_bot/impl/src/updates/add_governance_canister.rs" \ No newline at end of file diff --git a/sns/scripts/proposals/create_custom_sns_functions/4001.proposals_bot.remove_governance_canister.ini b/sns/scripts/proposals/create_custom_sns_functions/4001.proposals_bot.remove_governance_canister.ini deleted file mode 100644 index 0e6320a55d..0000000000 --- a/sns/scripts/proposals/create_custom_sns_functions/4001.proposals_bot.remove_governance_canister.ini +++ /dev/null @@ -1,3 +0,0 @@ -FUNCTION_NAME="Remove SNS proposals group" -FUNCTION_DESC="This will remove a proposals group linked to the given SNS governance canister id." -URL="https://github.com/open-chat-labs/open-chat/blob/8a4aecfeebffc2c7fd49fb1233448eef7296f51e/backend/canisters/proposals_bot/impl/src/updates/remove_governance_canister.rs" \ No newline at end of file