auto-create default project for each team
This commit is contained in:
parent
bbb5550caf
commit
b3870cd48a
3 changed files with 11 additions and 1 deletions
|
@ -12,6 +12,8 @@ use crate::{
|
|||
teams::Team,
|
||||
};
|
||||
|
||||
pub const DEFAULT_PROJECT_NAME: &'static str = "default";
|
||||
|
||||
#[derive(Associations, Clone, Debug, Identifiable, Insertable, Queryable, Selectable)]
|
||||
#[diesel(table_name = projects)]
|
||||
#[diesel(belongs_to(Team))]
|
||||
|
|
|
@ -27,6 +27,7 @@ use crate::{
|
|||
email::{MailSender as _, Mailer},
|
||||
guards,
|
||||
nav_state::{Breadcrumb, NavState},
|
||||
projects::{Project, DEFAULT_PROJECT_NAME},
|
||||
schema::{self, channel_selections, channels},
|
||||
settings::Settings,
|
||||
team_memberships::TeamMembership,
|
||||
|
@ -220,6 +221,7 @@ async fn post_new_team(
|
|||
insert_into(schema::team_memberships::table)
|
||||
.values(&team_membership)
|
||||
.execute(conn)?;
|
||||
Project::insert_new(conn, &team.id, DEFAULT_PROJECT_NAME)?;
|
||||
Ok(())
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use std::sync::LazyLock;
|
||||
|
||||
use anyhow::Context;
|
||||
use axum::{
|
||||
extract::Query,
|
||||
|
@ -20,7 +21,7 @@ use crate::{
|
|||
app_state::{AppState, DbConn},
|
||||
channels::Channel,
|
||||
governors::Governor,
|
||||
projects::Project,
|
||||
projects::{Project, DEFAULT_PROJECT_NAME},
|
||||
schema::{api_keys, messages},
|
||||
};
|
||||
|
||||
|
@ -39,6 +40,7 @@ struct SayQuery {
|
|||
#[serde(alias = "k")]
|
||||
key: Uuid,
|
||||
#[serde(alias = "p")]
|
||||
#[serde(default = "default_project")]
|
||||
#[validate(regex(
|
||||
path = *RE_PROJECT_NAME,
|
||||
message = "may be no more than 100 characters and contain only alphanumerics, -, and _",
|
||||
|
@ -53,6 +55,10 @@ struct SayQuery {
|
|||
message: String,
|
||||
}
|
||||
|
||||
fn default_project() -> String {
|
||||
DEFAULT_PROJECT_NAME.to_string()
|
||||
}
|
||||
|
||||
async fn say_get(
|
||||
DbConn(db_conn): DbConn,
|
||||
Query(mut query): Query<SayQuery>,
|
||||
|
|
Loading…
Add table
Reference in a new issue