Skip to content
Open
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: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ services:
/bin/sh -c "
fga_migrations apply &&
diesel migration run --locked-schema &&
editoast user add 'Example User' 'mock/mocked' &&
editoast user add --skip-if-exists 'Example User' 'mock/mocked' &&
editoast roles add 'mock/mocked' Admin &&
exec editoast runserver"
healthcheck:
Expand Down
19 changes: 18 additions & 1 deletion editoast/src/client/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ pub struct AddArgs {
name: Option<String>,
/// Identities of the user
identities: Vec<String>,
/// Skip if one of the identities already exists
#[arg(short, long)]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#[arg(short, long)]
#[arg(long)]

nit: -s for "skip" is unusual I think

skip_if_exists: bool,
}

#[derive(Debug, Args)]
Expand Down Expand Up @@ -130,13 +133,27 @@ pub async fn list_user(

/// Add a user
pub async fn add_user(
AddArgs { name, identities }: AddArgs,
AddArgs {
name,
identities,
skip_if_exists,
}: AddArgs,
pool: Arc<DbConnectionPoolV2>,
) -> anyhow::Result<()> {
if identities.is_empty() {
println!("No identities provided.");
return Ok(());
}
if skip_if_exists {
for identity in &identities {
let conn = pool.get().await?;
let user = editoast_models::User::retrieve_by_identity(identity, conn).await?;
if user.is_some() {
println!("Skipped: Identity '{identity}' already exists");
return Ok(());
}
}
}
let conn = pool.get().await?;
let created_user =
editoast_models::User::register(conn, identities, name.unwrap_or_default()).await?;
Expand Down