-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add admin roles and new RPC (add_admin)
- Loading branch information
Showing
8 changed files
with
151 additions
and
28 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
ALTER TABLE token ADD COLUMN allowed_methods TEXT NOT NULL DEFAULT '[]'; | ||
|
||
DROP TRIGGER token_updated_at; | ||
|
||
CREATE TRIGGER token_updated_at UPDATE OF user_id, secret, allowed_methods, created_at, deleted_at ON token | ||
BEGIN | ||
UPDATE token SET updated_at = strftime('%Y-%m-%dT%H:%M:%fZ') WHERE id = old.id; | ||
END; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
use crate::{auth::Token, discord, Result}; | ||
use deadpool_sqlite::Pool; | ||
use jsonrpc_v2::{Data, Params}; | ||
use serde::{Deserialize, Serialize}; | ||
use std::sync::Arc; | ||
use tracing::info; | ||
use uuid::Uuid; | ||
|
||
#[derive(Deserialize)] | ||
#[allow(dead_code)] | ||
pub struct Args { | ||
pub token: String, | ||
pub new_admin_name: String, | ||
pub new_admin_token: String, | ||
pub new_admin_allowed_methods: Vec<String>, | ||
} | ||
|
||
#[derive(Serialize)] | ||
pub struct Res { | ||
pub name: String, | ||
pub token: String, | ||
pub allowed_methods: Vec<String>, | ||
} | ||
|
||
pub async fn run(Params(args): Params<Args>, pool: Data<Arc<Pool>>) -> Result<Res> { | ||
let token = pool | ||
.get() | ||
.await? | ||
.interact(move |conn| Token::select_by_secret(&args.token, conn)) | ||
.await?? | ||
.unwrap(); | ||
let new_token = pool | ||
.get() | ||
.await? | ||
.interact(move |conn| { | ||
Token::insert( | ||
&args.new_admin_name, | ||
&Uuid::new_v4().to_string(), | ||
args.new_admin_allowed_methods, | ||
conn, | ||
) | ||
}) | ||
.await?? | ||
.unwrap(); | ||
let log_message = format!( | ||
"{} added new admin user {} with the following allowed methods: {}", | ||
token.owner, | ||
new_token.owner, | ||
serde_json::to_string(&new_token.allowed_methods)?, | ||
); | ||
info!(log_message); | ||
discord::send_message_to_channel(&log_message, discord::CHANNEL_API).await; | ||
Ok(Res { | ||
name: new_token.owner, | ||
token: new_token.secret, | ||
allowed_methods: new_token.allowed_methods, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod add_admin; | ||
pub mod add_area; | ||
pub mod add_element_comment; | ||
pub mod boost_element; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters