diff --git a/crates/app/src/assets.rs b/crates/app/src/assets.rs index 36ef889..225c842 100644 --- a/crates/app/src/assets.rs +++ b/crates/app/src/assets.rs @@ -54,6 +54,10 @@ pub const COMMUNITIES_SETTINGS: &str = include_str!("./public/html/communities/s pub const TIMELINES_HOME: &str = include_str!("./public/html/timelines/home.html"); pub const TIMELINES_POPULAR: &str = include_str!("./public/html/timelines/popular.html"); +pub const MOD_AUDIT_LOG: &str = include_str!("./public/html/mod/audit_log.html"); +pub const MOD_REPORTS: &str = include_str!("./public/html/mod/reports.html"); +pub const MOD_FILE_REPORT: &str = include_str!("./public/html/mod/file_report.html"); + // langs pub const LANG_EN_US: &str = include_str!("./langs/en-US.toml"); @@ -173,6 +177,10 @@ pub(crate) async fn write_assets(config: &Config) -> PathBufD { write_template!(html_path->"timelines/home.html"(crate::assets::TIMELINES_HOME) -d "timelines" --config=config); write_template!(html_path->"timelines/popular.html"(crate::assets::TIMELINES_POPULAR) --config=config); + write_template!(html_path->"mod/audit_log.html"(crate::assets::MOD_AUDIT_LOG) -d "mod" --config=config); + write_template!(html_path->"mod/reports.html"(crate::assets::MOD_REPORTS) --config=config); + write_template!(html_path->"mod/file_report.html"(crate::assets::MOD_FILE_REPORT) --config=config); + html_path } diff --git a/crates/app/src/langs/en-US.toml b/crates/app/src/langs/en-US.toml index be21778..5af0496 100644 --- a/crates/app/src/langs/en-US.toml +++ b/crates/app/src/langs/en-US.toml @@ -7,9 +7,18 @@ version = "1.0.0" "general:link.communities" = "Communities" "general:link.next" = "Next" "general:link.previous" = "Previous" +"general:link.source_code" = "Source code" +"general:link.audit_log" = "Audit log" +"general:link.reports" = "Reports" "general:action.save" = "Save" "general:action.delete" = "Delete" "general:action.back" = "Back" +"general:action.report" = "Report" +"general:action.manage" = "Manage" +"general:label.mod" = "Mod" +"general:label.file_report" = "File report" +"general:label.account_banned" = "Account banned" +"general:label.account_banned_body" = "Your account has been banned for violating our policies." "dialog:action.okay" = "Ok" "dialog:action.continue" = "Continue" @@ -72,3 +81,5 @@ version = "1.0.0" "settings:label.new_username" = "New username" "settings:label.change_avatar" = "Change avatar" "settings:label.change_banner" = "Change banner" + +"mod_panel:label.open_reported_content" = "Open reported content" diff --git a/crates/app/src/macros.rs b/crates/app/src/macros.rs index 94c5404..5966377 100644 --- a/crates/app/src/macros.rs +++ b/crates/app/src/macros.rs @@ -63,7 +63,13 @@ macro_rules! get_user_from_token { )) .await { - Ok(ua) => Some(ua), + Ok(ua) => { + if ua.permissions.check_banned() { + Some(tetratto_core::model::auth::User::banned()) + } else { + Some(ua) + } + } Err(_) => None, } } else { diff --git a/crates/app/src/public/html/communities/base.html b/crates/app/src/public/html/communities/base.html index 10e08b4..838ca69 100644 --- a/crates/app/src/public/html/communities/base.html +++ b/crates/app/src/public/html/communities/base.html @@ -15,14 +15,42 @@ {{ components::community_avatar(id=community.id, community=community, size="72px") }}
- -

- {% if community.context.display_name %} - {{ community.context.display_name }} - {% else %} - {{ community.title }} - {% endif %} -

+
+

+ + {% if community.context.display_name %} + {{ community.context.display_name }} + {% else %} + {{ community.title }} + {% endif %} +

+ + {% if user %} {% if user.id != community.owner + %} + + {% endif %} {% endif %} +
{{ community.title }}
diff --git a/crates/app/src/public/html/communities/settings.html b/crates/app/src/public/html/communities/settings.html index fa2b6d6..f471c2f 100644 --- a/crates/app/src/public/html/communities/settings.html +++ b/crates/app/src/public/html/communities/settings.html @@ -227,66 +227,6 @@ document.getElementById("uid").value = uid; } - globalThis.ban_user = async (uid) => { - if ( - !(await trigger("atto::confirm", [ - "Are you sure you would like to do this?", - ])) - ) { - return; - } - - fetch( - `/api/v1/communities/{{ community.id }}/memberships/${uid}/role`, - { - method: "POST", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify({ - role: 33, - }), - }, - ) - .then((res) => res.json()) - .then((res) => { - trigger("atto::toast", [ - res.ok ? "success" : "error", - res.message, - ]); - }); - }; - - globalThis.unban_user = async (uid) => { - if ( - !(await trigger("atto::confirm", [ - "Are you sure you would like to do this?", - ])) - ) { - return; - } - - fetch( - `/api/v1/communities/{{ community.id }}/memberships/${uid}/role`, - { - method: "POST", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify({ - role: 5, - }), - }, - ) - .then((res) => res.json()) - .then((res) => { - trigger("atto::toast", [ - res.ok ? "success" : "error", - res.message, - ]); - }); - }; - globalThis.update_user_role = async (uid, new_role) => { if ( !(await trigger("atto::confirm", [ @@ -356,7 +296,7 @@ element.innerHTML = `
Open user profile - ${res.payload.role !== 33 ? `` : ``} + ${res.payload.role !== 33 ? `` : ``} ${res.payload.role !== 65 ? `` : ``}
`; diff --git a/crates/app/src/public/html/components.html b/crates/app/src/public/html/components.html index 14df025..128a76d 100644 --- a/crates/app/src/public/html/components.html +++ b/crates/app/src/public/html/components.html @@ -161,7 +161,7 @@ show_community=true) -%} {% if community and show_community %} {{ icon "external-link" }} - {% if user %} {% if (user.id == post.owner) or is_helper %} + {% if user %} - {% endif %} {% endif %} + {% endif %} diff --git a/crates/app/src/public/html/macros.html b/crates/app/src/public/html/macros.html index b9febff..f9c7412 100644 --- a/crates/app/src/public/html/macros.html +++ b/crates/app/src/public/html/macros.html @@ -75,17 +75,30 @@ show_lhs=true) -%} {{ text "auth:link.settings" }} + + {{ icon "code" }} + {{ text "general:link.source_code" }} + + + {% if is_helper %} + {{ text "general:label.mod" }} + + + {{ icon "scroll-text" }} + {{ text "general:link.audit_log" }} + + + + {{ icon "flag" }} + {{ text "general:link.reports" }} + + {% endif %} +
- -
- - {{ icon "code" }} - View source - {% else %} diff --git a/crates/app/src/public/html/mod/audit_log.html b/crates/app/src/public/html/mod/audit_log.html new file mode 100644 index 0000000..e9cf026 --- /dev/null +++ b/crates/app/src/public/html/mod/audit_log.html @@ -0,0 +1,36 @@ +{% import "macros.html" as macros %} {% extends "root.html" %} {% block head %} +Audit log - {{ config.name }} +{% endblock %} {% block body %} {{ macros::nav(selected="notifications") }} +
+
+
+ {{ icon "scroll" }} + {{ text "general:link.audit_log" }} +
+ +
+ + {% for item in items %} + + {% endfor %} + + + {{ components::pagination(page=page, items=items|length) }} +
+
+
+{% endblock %} diff --git a/crates/app/src/public/html/mod/file_report.html b/crates/app/src/public/html/mod/file_report.html new file mode 100644 index 0000000..c13721b --- /dev/null +++ b/crates/app/src/public/html/mod/file_report.html @@ -0,0 +1,65 @@ +{% import "macros.html" as macros %} {% extends "root.html" %} {% block head %} +File report - {{ config.name }} +{% endblock %} {% block body %} {{ macros::nav(selected="notifications") }} +
+
+
+ {{ icon "flag" }} + {{ text "general:label.file_report" }} +
+ +
+
+ + +
+ + +
+
+
+ + +{% endblock %} diff --git a/crates/app/src/public/html/mod/reports.html b/crates/app/src/public/html/mod/reports.html new file mode 100644 index 0000000..b6c99ad --- /dev/null +++ b/crates/app/src/public/html/mod/reports.html @@ -0,0 +1,79 @@ +{% import "macros.html" as macros %} {% extends "root.html" %} {% block head %} +Reports - {{ config.name }} +{% endblock %} {% block body %} {{ macros::nav(selected="notifications") }} +
+
+
+ {{ icon "flag" }} + {{ text "general:link.reports" }} +
+ +
+ + {% for item in items %} +
+ + + {{ components::avatar(username=item.owner, selector_type="id") }} + {{ item.owner }} + {{ item.created }} + + +
+ {{ item.content|markdown|safe }} + +
+ + + +
+
+
+ {% endfor %} + + + {{ components::pagination(page=page, items=items|length) }} +
+
+
+ + +{% endblock %} diff --git a/crates/app/src/public/html/profile/base.html b/crates/app/src/public/html/profile/base.html index c73bb07..f82603b 100644 --- a/crates/app/src/public/html/profile/base.html +++ b/crates/app/src/public/html/profile/base.html @@ -209,6 +209,22 @@ }} + + {% if profile.permissions != 131073 %} + + {% else %} + + {% endif %} @@ -286,25 +302,77 @@ }); }; - ui.refresh_container(element, ["actions"]); - ui.generate_settings_ui( - element, - [ - [ - ["is_verified", "Is verified"], - "{{ profile.is_verified }}", - "checkbox", - ], - ], - null, - { - is_verified: (value) => { - profile_request(false, "verified", { - is_verified: value, - }); + globalThis.update_user_role = async ( + new_role, + ) => { + if ( + !(await trigger("atto::confirm", [ + "Are you sure you would like to do this?", + ])) + ) { + return; + } + + fetch( + `/api/v1/auth/profile/{{ profile.id }}/role`, + { + method: "POST", + headers: { + "Content-Type": + "application/json", + }, + body: JSON.stringify({ + role: Number.parseInt(new_role), + }), }, - }, - ); + ) + .then((res) => res.json()) + .then((res) => { + trigger("atto::toast", [ + res.ok ? "success" : "error", + res.message, + ]); + }); + }; + + ui.refresh_container(element, ["actions"]); + + setTimeout(() => { + ui.refresh_container(element, ["actions"]); + + ui.generate_settings_ui( + element, + [ + [ + ["is_verified", "Is verified"], + "{{ profile.is_verified }}", + "checkbox", + ], + [ + ["role", "Permission level"], + "{{ profile.permissions }}", + "input", + ], + ], + null, + { + is_verified: (value) => { + profile_request( + false, + "verified", + { + is_verified: value, + }, + ); + }, + role: (new_role) => { + return update_user_role( + new_role, + ); + }, + }, + ); + }, 100); }, 150); diff --git a/crates/app/src/public/html/profile/settings.html b/crates/app/src/public/html/profile/settings.html index 83a7eb6..f275647 100644 --- a/crates/app/src/public/html/profile/settings.html +++ b/crates/app/src/public/html/profile/settings.html @@ -142,6 +142,37 @@