mirror of
https://github.com/System-End/plura.git
synced 2026-04-19 15:18:23 +00:00
feat: remove system name
It didn't make much sense to have it tbh
This commit is contained in:
parent
0c6c89d53e
commit
1185763ea0
6 changed files with 22 additions and 76 deletions
2
migrations/20250719222019_remove_system_name.sql
Normal file
2
migrations/20250719222019_remove_system_name.sql
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
-- Add migration script here
|
||||
ALTER TABLE systems DROP COLUMN name;
|
||||
2
migrations/20250719222145_remove_oauth_name.sql
Normal file
2
migrations/20250719222145_remove_oauth_name.sql
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
-- Add migration script here
|
||||
ALTER TABLE system_oauth_process DROP COLUMN name;
|
||||
|
|
@ -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<SlackCommandEventResponse, CommandError> {
|
||||
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<SlackCommandEventResponse, CommandError> {
|
||||
trace!("Editing system name");
|
||||
|
||||
let states = state.read().await;
|
||||
let user_state = states.get_user_state::<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
|
||||
)
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -30,19 +30,6 @@ impl Id<Trusted> {
|
|||
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<Trusted> {
|
|||
currently_fronting_member_id as "currently_fronting_member_id: member::Id<Trusted>",
|
||||
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<member::Id<Trusted>>,
|
||||
/// 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<Trusted>",
|
||||
auto_switch_on_trigger,
|
||||
slack_oauth_token,
|
||||
name,
|
||||
created_at as "created_at: time::PrimitiveDateTime"
|
||||
FROM
|
||||
systems
|
||||
|
|
|
|||
15
src/oauth.rs
15
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<Trusted>",
|
||||
name
|
||||
owner_id as "owner_id: user::Id<Trusted>"
|
||||
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(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue