Skip to content

Commit

Permalink
feat(auth): return has_access_to_beta in endpoint used by console
Browse files Browse the repository at this point in the history
  • Loading branch information
Kazy committed May 23, 2024
1 parent 57a36a1 commit 824f4fc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
10 changes: 8 additions & 2 deletions auth/src/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,16 @@ where
P: PermissionsDal + Send + Sync,
{
async fn create_user(&self, account_name: String, tier: AccountTier) -> Result<User, Error> {
let user = User::new(account_name, ApiKey::generate(), tier, vec![]);
let user = User::new(account_name, ApiKey::generate(), tier, vec![], false);

query(
"INSERT INTO users (account_name, key, account_tier, user_id) VALUES ($1, $2, $3, $4)",
"INSERT INTO users (account_name, key, account_tier, user_id, has_access_to_beta) VALUES ($1, $2, $3, $4, $5)",
)
.bind(&user.name)
.bind(user.key.expose())
.bind(user.account_tier.to_string())
.bind(&user.id)
.bind(false)
.execute(&self.pool)
.await?;

Expand Down Expand Up @@ -278,6 +279,7 @@ pub struct User {
pub key: Secret<ApiKey>,
pub account_tier: AccountTier,
pub subscriptions: Vec<Subscription>,
pub has_access_to_beta: bool,
}

#[derive(Clone, Debug)]
Expand Down Expand Up @@ -310,13 +312,15 @@ impl User {
key: ApiKey,
account_tier: AccountTier,
subscriptions: Vec<Subscription>,
has_access_to_beta: bool,
) -> Self {
Self {
name,
id: Self::new_user_id(),
key: Secret::new(key),
account_tier,
subscriptions,
has_access_to_beta,
}
}

Expand Down Expand Up @@ -390,6 +394,7 @@ impl FromRow<'_, PgRow> for User {
},
)?,
subscriptions: vec![],
has_access_to_beta: row.try_get("has_access_to_beta").unwrap(),
})
}
}
Expand Down Expand Up @@ -465,6 +470,7 @@ impl From<User> for models::user::Response {
key: user.key.expose().as_ref().to_owned(),
account_tier: user.account_tier.to_string(),
subscriptions: user.subscriptions.into_iter().map(Into::into).collect(),
has_access_to_beta: user.has_access_to_beta,
}
}
}
Expand Down
1 change: 1 addition & 0 deletions common/src/models/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub struct Response {
pub key: String,
pub account_tier: String,
pub subscriptions: Vec<Subscription>,
pub has_access_to_beta: bool
}

#[derive(Deserialize, Serialize, Debug)]
Expand Down

0 comments on commit 824f4fc

Please sign in to comment.