Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(auth): add has_access_to_beta column #1779

Merged
merged 2 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions auth/migrations/0005_add_beta_access.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE users
ADD COLUMN has_access_to_beta BOOL DEFAULT false;
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