diff --git a/migrations/20250719222019_remove_system_name.sql b/migrations/20250719222019_remove_system_name.sql new file mode 100644 index 0000000..b742b3f --- /dev/null +++ b/migrations/20250719222019_remove_system_name.sql @@ -0,0 +1,2 @@ +-- Add migration script here +ALTER TABLE systems DROP COLUMN name; diff --git a/migrations/20250719222145_remove_oauth_name.sql b/migrations/20250719222145_remove_oauth_name.sql new file mode 100644 index 0000000..3707f04 --- /dev/null +++ b/migrations/20250719222145_remove_oauth_name.sql @@ -0,0 +1,2 @@ +-- Add migration script here +ALTER TABLE system_oauth_process DROP COLUMN name; diff --git a/src/commands/system.rs b/src/commands/system.rs index 1ecd8a5..b621875 100755 --- a/src/commands/system.rs +++ b/src/commands/system.rs @@ -29,11 +29,6 @@ pub enum System { /// The name of your system name: String, }, - /// Edits your system name - Rename { - /// Your system's new name - name: String, - }, /// Re-authenticates your system with Slack Reauth, /// Get information about your or another user's system @@ -59,7 +54,6 @@ impl System { ) -> Result { match self { Self::Create { name } => Self::create_system(event, state, name).await, - Self::Rename { name } => Self::edit_system_name(event, state, name).await, Self::Info { user } => Self::get_system_info(event, client, state, user).await, Self::Reauth => Self::reauth(event, state).await, } @@ -92,10 +86,9 @@ impl System { sqlx::query!( r#" - INSERT INTO system_oauth_process (name, owner_id, csrf) - VALUES ($1, $2, $3) + INSERT INTO system_oauth_process (owner_id, csrf) + VALUES ($1, $2) "#, - system.name, system.owner_id, secret ) @@ -155,19 +148,13 @@ impl System { .change_context(CommandError::Sqlx)?; Ok(SlackCommandEventResponse::new( - SlackMessageContent::new().with_blocks(slack_blocks![ - some_into( - SlackSectionBlock::new() - .with_text(md!(format!("System name: {}", system.name))) - ), - some_into(SlackSectionBlock::new().with_text(md!(format!( - "Fronting member: {}", - fronting_member.map_or_else( - || "No fronting member".to_string(), - |m| m.display_name - ) - )))) - ]), + SlackMessageContent::new().with_blocks(slack_blocks![some_into( + SlackSectionBlock::new().with_text(md!(format!( + "Fronting member: {}", + fronting_member + .map_or_else(|| "No fronting member".to_string(), |m| m.display_name) + ))) + )]), )) } else { debug!("User does not have a system"); @@ -179,29 +166,6 @@ impl System { } } - #[tracing::instrument(skip(event, state), fields(system_id))] - async fn edit_system_name( - event: SlackCommandEvent, - state: SlackClientEventsUserState, - name: String, - ) -> Result { - trace!("Editing system name"); - - let states = state.read().await; - let user_state = states.get_user_state::().unwrap(); - - fetch_system!(event, user_state => system_id); - - system_id - .rename(&name, &user_state.db) - .await - .change_context(CommandError::Sqlx)?; - - Ok(SlackCommandEventResponse::new( - SlackMessageContent::new().with_text("Successfully updated system name!".into()), - )) - } - #[tracing::instrument(skip(event, state))] async fn create_system( event: SlackCommandEvent, @@ -239,10 +203,9 @@ impl System { sqlx::query!( r#" - INSERT INTO system_oauth_process (name, owner_id, csrf) - VALUES ($1, $2, $3) + INSERT INTO system_oauth_process (owner_id, csrf) + VALUES ($1, $2) "#, - name, user_id.id, secret ) diff --git a/src/interactions/message.rs b/src/interactions/message.rs index 3fd3c47..cf9f5f6 100644 --- a/src/interactions/message.rs +++ b/src/interactions/message.rs @@ -653,14 +653,13 @@ pub async fn info( some_into( SlackSectionBlock::new() .with_text(md!( - "*{}*\n{}{}\n*System*: {} ({})", + "*{}*\n{}{}\n*System*: {}", member.display_name, member.pronouns.unwrap_or_default(), member .name_pronunciation .map(|pronunciation| format!(" - {pronunciation}")) .unwrap_or_default(), - system.name, system.owner_id.to_slack_format() )) .opt_accessory(member.profile_picture_url.and_then(|url| Some( diff --git a/src/models/system.rs b/src/models/system.rs index 871c241..65625b9 100755 --- a/src/models/system.rs +++ b/src/models/system.rs @@ -30,19 +30,6 @@ impl Id { Trigger::fetch_by_system_id(self, db).await } - #[tracing::instrument(skip(db))] - pub async fn rename(self, new_name: &str, db: &SqlitePool) -> Result<(), sqlx::Error> { - sqlx::query!( - "UPDATE systems SET name = ? WHERE id = ?", - new_name, - self.id - ) - .execute(db) - .await?; - - Ok(()) - } - #[tracing::instrument(skip(db))] pub async fn change_fronting_member( self, @@ -112,7 +99,6 @@ impl Id { currently_fronting_member_id as "currently_fronting_member_id: member::Id", auto_switch_on_trigger, slack_oauth_token, - name, created_at as "created_at: time::PrimitiveDateTime" FROM systems WHERE id = $1 @@ -160,8 +146,6 @@ pub struct System { pub currently_fronting_member_id: Option>, /// Whether a [`trigger::Trigger`] activation changes the active member to the member the trigger is associated with pub auto_switch_on_trigger: bool, - /// The name of the system - pub name: String, /// The Slack OAuth token for the system pub slack_oauth_token: SlackOauthToken, pub created_at: time::PrimitiveDateTime, @@ -185,7 +169,6 @@ impl System { currently_fronting_member_id as "currently_fronting_member_id: member::Id", auto_switch_on_trigger, slack_oauth_token, - name, created_at as "created_at: time::PrimitiveDateTime" FROM systems diff --git a/src/oauth.rs b/src/oauth.rs index 22b0b67..2846665 100755 --- a/src/oauth.rs +++ b/src/oauth.rs @@ -89,8 +89,7 @@ pub async fn oauth_handler( let csrf = sqlx::query!( r#" SELECT - owner_id as "owner_id: user::Id", - name + owner_id as "owner_id: user::Id" FROM system_oauth_process WHERE csrf = $1 @@ -121,12 +120,10 @@ pub async fn oauth_handler( let user = sqlx::query!( r#" - INSERT INTO systems (name, owner_id, slack_oauth_token) - VALUES ($1, $2, $3) - ON CONFLICT (owner_id) DO UPDATE SET slack_oauth_token = $3 - RETURNING name + INSERT INTO systems (owner_id, slack_oauth_token) + VALUES ($1, $2) + ON CONFLICT (owner_id) DO UPDATE SET slack_oauth_token = $2 "#, - record.name, record.owner_id.id, user_token, ) @@ -134,7 +131,7 @@ pub async fn oauth_handler( .await; match user { - Ok(user) => { + Ok(_user) => { sqlx::query!( r#" DELETE FROM system_oauth_process @@ -146,7 +143,7 @@ pub async fn oauth_handler( .await .unwrap(); - let response = format!("System {} created!", user.name); + let response = format!("System for user {} authenticated!", record.owner_id.0); if let Err(e) = slack_client .post_webhook_message(