Add default clients #105
@ -65,7 +65,7 @@ pub struct UpdateUserQuery {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn users_route(
|
pub async fn users_route(
|
||||||
user: CurrentUser,
|
admin: CurrentUser,
|
||||||
users: web::Data<Addr<UsersActor>>,
|
users: web::Data<Addr<UsersActor>>,
|
||||||
update_query: Option<web::Form<UpdateUserQuery>>,
|
update_query: Option<web::Form<UpdateUserQuery>>,
|
||||||
logger: ActionLogger,
|
logger: ActionLogger,
|
||||||
@ -225,7 +225,7 @@ pub async fn users_route(
|
|||||||
|
|
||||||
HttpResponse::Ok().body(
|
HttpResponse::Ok().body(
|
||||||
UsersListTemplate {
|
UsersListTemplate {
|
||||||
_p: BaseSettingsPage::get("Users list", &user, danger, success),
|
_p: BaseSettingsPage::get("Users list", &admin, danger, success),
|
||||||
users,
|
users,
|
||||||
}
|
}
|
||||||
.render()
|
.render()
|
||||||
@ -233,11 +233,14 @@ pub async fn users_route(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn create_user(user: CurrentUser, clients: web::Data<ClientManager>) -> impl Responder {
|
pub async fn create_user(admin: CurrentUser, clients: web::Data<ClientManager>) -> impl Responder {
|
||||||
|
let mut user = User::default();
|
||||||
|
user.authorized_clients = Some(clients.get_default_clients().iter().map(|u| u.id.clone()).collect());
|
||||||
|
|
||||||
HttpResponse::Ok().body(
|
HttpResponse::Ok().body(
|
||||||
EditUserTemplate {
|
EditUserTemplate {
|
||||||
_p: BaseSettingsPage::get("Create a new user", user.deref(), None, None),
|
_p: BaseSettingsPage::get("Create a new user", admin.deref(), None, None),
|
||||||
u: Default::default(),
|
u: user,
|
||||||
clients: clients.cloned(),
|
clients: clients.cloned(),
|
||||||
}
|
}
|
||||||
.render()
|
.render()
|
||||||
@ -251,7 +254,7 @@ pub struct EditUserQuery {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn edit_user(
|
pub async fn edit_user(
|
||||||
user: CurrentUser,
|
admin: CurrentUser,
|
||||||
clients: web::Data<ClientManager>,
|
clients: web::Data<ClientManager>,
|
||||||
users: web::Data<Addr<UsersActor>>,
|
users: web::Data<Addr<UsersActor>>,
|
||||||
query: web::Query<EditUserQuery>,
|
query: web::Query<EditUserQuery>,
|
||||||
@ -266,7 +269,7 @@ pub async fn edit_user(
|
|||||||
EditUserTemplate {
|
EditUserTemplate {
|
||||||
_p: BaseSettingsPage::get(
|
_p: BaseSettingsPage::get(
|
||||||
"Edit user account",
|
"Edit user account",
|
||||||
user.deref(),
|
admin.deref(),
|
||||||
match edited_account.is_none() {
|
match edited_account.is_none() {
|
||||||
true => Some("Could not find requested user!".to_string()),
|
true => Some("Could not find requested user!".to_string()),
|
||||||
false => None,
|
false => None,
|
||||||
|
@ -6,11 +6,24 @@ pub struct ClientID(pub String);
|
|||||||
|
|
||||||
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
|
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct Client {
|
pub struct Client {
|
||||||
|
/// The ID of the client
|
||||||
pub id: ClientID,
|
pub id: ClientID,
|
||||||
|
|
||||||
|
/// The human-readable name of the client
|
||||||
pub name: String,
|
pub name: String,
|
||||||
|
|
||||||
|
/// A short description of the service provided by the client
|
||||||
pub description: String,
|
pub description: String,
|
||||||
|
|
||||||
|
/// The secret used by the client to retrieve authenticated users information
|
||||||
pub secret: String,
|
pub secret: String,
|
||||||
|
|
||||||
|
/// The URI where the users should be redirected once authenticated
|
||||||
pub redirect_uri: String,
|
pub redirect_uri: String,
|
||||||
|
|
||||||
|
/// Specify if the client must be allowed by default for new account
|
||||||
|
#[serde(default = "bool::default")]
|
||||||
|
pub default: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PartialEq for Client {
|
impl PartialEq for Client {
|
||||||
@ -33,6 +46,13 @@ impl EntityManager<Client> {
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the list of default clients.
|
||||||
|
///
|
||||||
|
/// i.e. the clients that are granted to new accounts by default
|
||||||
|
pub fn get_default_clients(&self) -> Vec<&Client> {
|
||||||
|
self.iter().filter(|u| u.default).collect()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn apply_environment_variables(&mut self) {
|
pub fn apply_environment_variables(&mut self) {
|
||||||
for c in self.iter_mut() {
|
for c in self.iter_mut() {
|
||||||
c.id = ClientID(apply_env_vars(&c.id.0));
|
c.id = ClientID(apply_env_vars(&c.id.0));
|
||||||
|
Loading…
Reference in New Issue
Block a user