Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
Add fields to OAuth (#769)
Browse files Browse the repository at this point in the history
* Add url and description fields to OAuthClient
model

* Add OAuth client icon editing and deleting
endpoints

* updated query data

* fix missed queries

* sqlx prep

* update with tests builds
  • Loading branch information
darling authored Nov 26, 2023
1 parent bad350e commit 0efbbed
Show file tree
Hide file tree
Showing 8 changed files with 228 additions and 11 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions migrations/20231122230639_oauth_client_metadata.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- Add migration script here
ALTER TABLE
oauth_clients
ADD
COLUMN url text NULL,
ADD
COLUMN description text NULL;
14 changes: 12 additions & 2 deletions src/database/models/oauth_client_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ pub struct OAuthClient {
pub redirect_uris: Vec<OAuthRedirectUri>,
pub created: DateTime<Utc>,
pub created_by: UserId,
pub url: Option<String>,
pub description: Option<String>,
}

struct ClientQueryResult {
Expand All @@ -33,6 +35,8 @@ struct ClientQueryResult {
secret_hash: String,
created: DateTime<Utc>,
created_by: i64,
url: Option<String>,
description: Option<String>,
uri_ids: Option<Vec<i64>>,
uri_vals: Option<Vec<String>>,
}
Expand All @@ -53,6 +57,8 @@ macro_rules! select_clients_with_predicate {
clients.secret_hash as "secret_hash!",
clients.created as "created!",
clients.created_by as "created_by!",
clients.url as "url?",
clients.description as "description?",
uris.uri_ids as "uri_ids?",
uris.uri_vals as "uri_vals?"
FROM oauth_clients clients
Expand Down Expand Up @@ -155,12 +161,14 @@ impl OAuthClient {
sqlx::query!(
"
UPDATE oauth_clients
SET name = $1, icon_url = $2, max_scopes = $3
WHERE (id = $4)
SET name = $1, icon_url = $2, max_scopes = $3, url = $4, description = $5
WHERE (id = $6)
",
self.name,
self.icon_url,
self.max_scopes.to_postgres(),
self.url,
self.description,
self.id.0,
)
.execute(exec)
Expand Down Expand Up @@ -240,6 +248,8 @@ impl From<ClientQueryResult> for OAuthClient {
redirect_uris: redirects,
created: r.created,
created_by: UserId(r.created_by),
url: r.url,
description: r.description,
}
}
}
10 changes: 10 additions & 0 deletions src/models/v3/oauth_clients.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ pub struct OAuthClient {

// The user that created (and thus controls) this client
pub created_by: UserId,

// When this client was created
pub created: DateTime<Utc>,

// (optional) Metadata about the client
pub url: Option<String>,
pub description: Option<String>,
}

#[derive(Deserialize, Serialize)]
Expand Down Expand Up @@ -88,6 +95,9 @@ impl From<DBOAuthClient> for OAuthClient {
max_scopes: value.max_scopes,
redirect_uris: value.redirect_uris.into_iter().map(|r| r.into()).collect(),
created_by: value.created_by.into(),
created: value.created,
url: value.url,
description: value.description,
}
}
}
Expand Down
Loading

0 comments on commit 0efbbed

Please sign in to comment.