diff --git a/crates/app/src/main.rs b/crates/app/src/main.rs index 1793bc2..8bc2d6f 100644 --- a/crates/app/src/main.rs +++ b/crates/app/src/main.rs @@ -56,7 +56,7 @@ async fn main() { .await .unwrap(); - info!("🐐 tetratto."); + info!("🐇 tetratto."); info!("listening on http://0.0.0.0:{}", config.port); axum::serve(listener, app).await.unwrap(); } diff --git a/crates/app/src/public/html/communities/settings.html b/crates/app/src/public/html/communities/settings.html index 16973b5..ec34065 100644 --- a/crates/app/src/public/html/communities/settings.html +++ b/crates/app/src/public/html/communities/settings.html @@ -324,14 +324,108 @@ return; } + // permissions manager + const permissions = { + // https://trisuaso.github.io/tetratto/tetratto/model/communities_permissions/struct.CommunityPermission.html + DEFAULT: 1 << 0, + ADMINISTRATOR: 1 << 1, + MEMBER: 1 << 2, + MANAGE_POSTS: 1 << 3, + MANAGE_ROLES: 1 << 4, + BANNED: 1 << 5, + REQUESTED: 1 << 6, + MANAGE_PINS: 1 << 7, + }; + + function all_matching_permissions(role) { + const matching = []; + const not_matching = []; + + for (permission of Object.entries(permissions)) { + if ((role & permission[1]) === permission[1]) { + matching.push(permission[0]); + } else { + not_matching.push(permission[0]); + } + } + + return [matching, not_matching]; + } + + function rebuild_role(matching) { + let role = 0; + + for (const permission of matching) { + role = role | permissions[permission]; + } + + document.getElementById("role").value = role; + return role; + } + + function get_permissions_html(role, id) { + const [matching, not_matching] = + all_matching_permissions(role); + + globalThis.remove_permission_from_role = ( + permission, + ) => { + matching.splice(matching.indexOf(permission), 1); + not_matching.push(permission); + + document.getElementById(id).innerHTML = + get_permissions_html( + rebuild_role(matching), + id, + ); + }; + + globalThis.add_permission_to_role = (permission) => { + not_matching.splice( + not_matching.indexOf(permission), + 1, + ); + matching.push(permission); + + document.getElementById(id).innerHTML = + get_permissions_html( + rebuild_role(matching), + id, + ); + }; + + let permissions_html = ""; + + for (const match of matching) { + permissions_html += `
${permissions[match]}
+
+ ${permissions[match]}
+
+