Start to build edit user form
This commit is contained in:
parent
af903de7c2
commit
91d71c7006
@ -18,12 +18,12 @@ pub struct User {
|
|||||||
|
|
||||||
/// None = all services
|
/// None = all services
|
||||||
/// Some([]) = no service
|
/// Some([]) = no service
|
||||||
pub authorized_services: Option<Vec<ClientID>>,
|
pub authorized_clients: Option<Vec<ClientID>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl User {
|
impl User {
|
||||||
pub fn can_access_app(&self, id: &ClientID) -> bool {
|
pub fn can_access_app(&self, id: &ClientID) -> bool {
|
||||||
match &self.authorized_services {
|
match &self.authorized_clients {
|
||||||
None => true,
|
None => true,
|
||||||
Some(c) => c.contains(id)
|
Some(c) => c.contains(id)
|
||||||
}
|
}
|
||||||
@ -54,7 +54,7 @@ impl Default for User {
|
|||||||
need_reset_password: false,
|
need_reset_password: false,
|
||||||
enabled: true,
|
enabled: true,
|
||||||
admin: false,
|
admin: false,
|
||||||
authorized_services: Some(Vec::new()),
|
authorized_clients: Some(Vec::new()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,7 @@ async fn main() -> std::io::Result<()> {
|
|||||||
username: DEFAULT_ADMIN_USERNAME.to_string(),
|
username: DEFAULT_ADMIN_USERNAME.to_string(),
|
||||||
password: hash_password(DEFAULT_ADMIN_PASSWORD).unwrap(),
|
password: hash_password(DEFAULT_ADMIN_PASSWORD).unwrap(),
|
||||||
need_reset_password: true,
|
need_reset_password: true,
|
||||||
authorized_services: None,
|
authorized_clients: None,
|
||||||
admin: true,
|
admin: true,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
@ -66,24 +66,25 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Granted services -->
|
<!-- Granted clients -->
|
||||||
<fieldset class="form-group">
|
<fieldset class="form-group">
|
||||||
<legend class="mt-4">Granted services</legend>
|
<legend class="mt-4">Granted clients</legend>
|
||||||
<div class="form-check">
|
<div class="form-check">
|
||||||
<label class="form-check-label">
|
<label class="form-check-label">
|
||||||
<input type="radio" class="form-check-input" name="granted_services"
|
<input type="radio" class="form-check-input" name="granted_clients"
|
||||||
value="all_services" {% if u.authorized_services== None %} checked="" {% endif %}>
|
value="all_clients" {% if u.authorized_clients== None %} checked="" {% endif %}>
|
||||||
Grant all services
|
Grant all clients
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-check">
|
<div class="form-check">
|
||||||
<label class="form-check-label">
|
<label class="form-check-label">
|
||||||
<input type="radio" class="form-check-input" name="granted_services"
|
<input type="radio" class="form-check-input" name="granted_clients"
|
||||||
value="custom_services" {% if u.authorized_services !=None %} checked="checked" {% endif %}>
|
value="custom_clients" {% if u.authorized_clients !=None %} checked="checked" {% endif %}>
|
||||||
Manually specify allowed services
|
Manually specify allowed clients
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div id="clients_target">
|
||||||
{% for c in clients %}
|
{% for c in clients %}
|
||||||
<div class="form-check">
|
<div class="form-check">
|
||||||
<input class="form-check-input" type="checkbox" class="authorize_client" data-id="{{ c.id.0 }}"
|
<input class="form-check-input" type="checkbox" class="authorize_client" data-id="{{ c.id.0 }}"
|
||||||
@ -93,7 +94,21 @@
|
|||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
// Clients granted
|
||||||
|
function refreshDisplayAuthorizedClients() {
|
||||||
|
const clientsSelectorEl = document.getElementById("clients_target");
|
||||||
|
const radioBtn = document.querySelector("input[name=granted_clients][value=custom_clients]");
|
||||||
|
clientsSelectorEl.style.display = radioBtn.checked ? "block" : "none";
|
||||||
|
}
|
||||||
|
refreshDisplayAuthorizedClients();
|
||||||
|
document.querySelectorAll("input[name=granted_clients]").forEach(el=> {
|
||||||
|
el.addEventListener("change", refreshDisplayAuthorizedClients)
|
||||||
|
})
|
||||||
|
|
||||||
|
</script>
|
||||||
{% endblock content %}
|
{% endblock content %}
|
||||||
|
Loading…
Reference in New Issue
Block a user