Browse Source

FEA: automatically add user to default role on creation

develop
Keanu D?lle 2 months ago
parent
commit
2d3b0998db
  1. 1
      config/default.toml
  2. 1
      config/development.toml
  3. 6
      src/database/controller/create_member.rs
  4. 2
      src/database/controller/member_qualifications.rs
  5. 13
      src/database/controller/roles.rs
  6. 1
      src/helper/settings.rs

1
config/default.toml

@ -17,6 +17,7 @@ login_lock_duration = 1800
#How long does it take until tokens expire?
reset_password_token_valid_duration = 3600
user_support_email = "support@einsatz.online"
new_member_default_role = "member"
[mail]
from = "No Reply <noreply@localhost>"

1
config/development.toml

@ -17,6 +17,7 @@ login_lock_duration = 1800
#How long does it take until tokens expire?
reset_password_token_valid_duration = 3600
user_support_email = "support@einsatz.online"
new_member_default_role = "member"
[mail]
from = "No Reply <noreply@localhost>"

6
src/database/controller/create_member.rs

@ -12,7 +12,7 @@ use chrono::NaiveDate;
use crate::database::controller::members_groups::add_member_to_group;
use crate::database::controller::entities::generate_entity;
use rocket::futures::future::err;
use crate::database::controller::roles::add_member_to_role;
pub fn create_member(settings: &State<Settings>, form: CreateMemberForm) -> Result<uuid::Uuid, diesel::result::Error>{
let connection = establish_connection(settings);
@ -74,6 +74,10 @@ pub fn create_member(settings: &State<Settings>, form: CreateMemberForm) -> Resu
}
}
if settings.application.new_member_default_role != "" {
add_member_to_role(settings, entity_id2, settings.application.new_member_default_role.clone());
}
match diesel::insert_into(members).values(member).execute(&connection){
Ok(_) => Ok(entity_id2),
Err(e) => {

2
src/database/controller/member_qualifications.rs

@ -189,9 +189,7 @@ pub fn get_qualifications(settings: &State<Settings>) -> Result<Vec<Qualificatio
}
pub fn check_qualification_for_member(settings: &State<Settings>, qualification: uuid::Uuid, member: uuid::Uuid) -> Result<bool, diesel::result::Error>{
use crate::schema::qualification_categories::dsl::*;
use diesel::dsl::count;
use crate::diesel::OptionalExtension;
let connection = establish_connection(settings);

13
src/database/controller/roles.rs

@ -88,3 +88,16 @@ pub fn add_permission_context(
}
}
}
pub fn add_member_to_role(settings: &State<Settings>, member_uuid: uuid::Uuid, role: String) -> Result<(), diesel::result::Error>{
use crate::schema::members_roles::dsl::*;
let connection = establish_connection(settings);
match diesel::insert_into(members_roles).values((member_id.eq(member_uuid), role_id.eq(role))).execute(&connection){
Ok(_) => Ok(()),
Err(e) => {
error!("Couldn't add member to role: {}", e);
Err(e)
}
}
}

1
src/helper/settings.rs

@ -19,6 +19,7 @@ pub struct Application {
pub name: String,
pub reset_password_token_valid_duration: i64,
pub user_support_email: String,
pub new_member_default_role: String,
}
#[derive(Debug, Deserialize, Default)]

Loading…
Cancel
Save