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