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 += `
+ ${match} ${permissions[match]} + +
`; + } + + for (const match of not_matching) { + permissions_html += `
+ ${match} ${permissions[match]} + +
`; + } + + return permissions_html; + } + + // ... element.innerHTML = `
Open user profile ${res.payload.role !== 33 ? `` : ``} ${res.payload.role !== 65 ? `` : ``} +
+ +
+ ${get_permissions_html(res.payload.role, "permissions")}
`; - ui.refresh_container(element, ["actions"]); + ui.refresh_container(element, ["actions", "permissions"]); ui.generate_settings_ui( element, [ diff --git a/crates/core/src/database/memberships.rs b/crates/core/src/database/memberships.rs index 38d1832..2c183e2 100644 --- a/crates/core/src/database/memberships.rs +++ b/crates/core/src/database/memberships.rs @@ -226,7 +226,7 @@ impl DataManager { let res = execute!( &conn, "UPDATE memberships SET role = $1 WHERE id = $2", - params![&(new_role.bits() as i64), &(id as i64)] + params![&(new_role.bits() as i32), &(id as i64)] ); if let Err(e) = res {