Add legal information (fixes #652)

This commit is contained in:
Felix Ableitner 2022-05-20 14:17:55 +02:00
parent b77689ebd1
commit 39379eb786
6 changed files with 57 additions and 11 deletions

@ -1 +1 @@
Subproject commit 2e9f6291c91a9c97fa7f7740f90ee3146515e03c Subproject commit f6140fee78e9b9f495072eeb0707f972d51aefad

View file

@ -74,7 +74,7 @@
"eslint-plugin-prettier": "^4.0.0", "eslint-plugin-prettier": "^4.0.0",
"husky": "^7.0.4", "husky": "^7.0.4",
"import-sort-style-module": "^6.0.0", "import-sort-style-module": "^6.0.0",
"lemmy-js-client": "0.16.4-rc.1", "lemmy-js-client": "git+https://github.com/LemmyNet/lemmy-js-client.git#legal-info",
"lint-staged": "^12.4.1", "lint-staged": "^12.4.1",
"mini-css-extract-plugin": "^2.6.0", "mini-css-extract-plugin": "^2.6.0",
"node-fetch": "^2.6.1", "node-fetch": "^2.6.1",

View file

@ -32,6 +32,13 @@ export class Footer extends Component<FooterProps, any> {
{i18n.t("modlog")} {i18n.t("modlog")}
</NavLink> </NavLink>
</li> </li>
{this.props.site.site_view.site.legal_information && (
<li className="nav-item">
<NavLink className="nav-link" to="/legal">
{i18n.t("legal_information")}
</NavLink>
</li>
)}
{this.props.site.federated_instances && ( {this.props.site.federated_instances && (
<li class="nav-item"> <li class="nav-item">
<NavLink className="nav-link" to="/instances"> <NavLink className="nav-link" to="/instances">

View file

@ -2,6 +2,7 @@ import autosize from "autosize";
import { Component, linkEvent } from "inferno"; import { Component, linkEvent } from "inferno";
import { import {
BannedPersonsResponse, BannedPersonsResponse,
EditSite,
GetBannedPersons, GetBannedPersons,
GetSiteConfig, GetSiteConfig,
GetSiteConfigResponse, GetSiteConfigResponse,
@ -36,6 +37,7 @@ interface AdminSettingsState {
siteRes: GetSiteResponse; siteRes: GetSiteResponse;
siteConfigRes: GetSiteConfigResponse; siteConfigRes: GetSiteConfigResponse;
siteConfigHjson: string; siteConfigHjson: string;
legalInfo: string;
loading: boolean; loading: boolean;
banned: PersonViewSafe[]; banned: PersonViewSafe[];
siteConfigLoading: boolean; siteConfigLoading: boolean;
@ -44,11 +46,13 @@ interface AdminSettingsState {
export class AdminSettings extends Component<any, AdminSettingsState> { export class AdminSettings extends Component<any, AdminSettingsState> {
private siteConfigTextAreaId = `site-config-${randomStr()}`; private siteConfigTextAreaId = `site-config-${randomStr()}`;
private legalInfoTextAreaId = `legal-info-${randomStr()}`;
private isoData = setIsoData(this.context); private isoData = setIsoData(this.context);
private subscription: Subscription; private subscription: Subscription;
private emptyState: AdminSettingsState = { private emptyState: AdminSettingsState = {
siteRes: this.isoData.site_res, siteRes: this.isoData.site_res,
siteConfigHjson: null, siteConfigHjson: null,
legalInfo: null,
siteConfigRes: { siteConfigRes: {
config_hjson: null, config_hjson: null,
}, },
@ -70,6 +74,8 @@ export class AdminSettings extends Component<any, AdminSettingsState> {
if (this.isoData.path == this.context.router.route.match.url) { if (this.isoData.path == this.context.router.route.match.url) {
this.state.siteConfigRes = this.isoData.routeData[0]; this.state.siteConfigRes = this.isoData.routeData[0];
this.state.siteConfigHjson = this.state.siteConfigRes.config_hjson; this.state.siteConfigHjson = this.state.siteConfigRes.config_hjson;
this.state.legalInfo =
this.state.siteRes.site_view.site.legal_information;
this.state.banned = this.isoData.routeData[1].banned; this.state.banned = this.isoData.routeData[1].banned;
this.state.siteConfigLoading = false; this.state.siteConfigLoading = false;
this.state.loading = false; this.state.loading = false;
@ -195,7 +201,7 @@ export class AdminSettings extends Component<any, AdminSettingsState> {
return ( return (
<div> <div>
<h5>{i18n.t("admin_settings")}</h5> <h5>{i18n.t("admin_settings")}</h5>
<form onSubmit={linkEvent(this, this.handleSiteConfigSubmit)}> <form onSubmit={linkEvent(this, this.handleAdminSettingsSubmit)}>
<div class="form-group row"> <div class="form-group row">
<label <label
class="col-12 col-form-label" class="col-12 col-form-label"
@ -213,6 +219,23 @@ export class AdminSettings extends Component<any, AdminSettingsState> {
/> />
</div> </div>
</div> </div>
<div class="form-group row">
<label
class="col-12 col-form-label"
htmlFor={this.legalInfoTextAreaId}
>
{i18n.t("legal_information")}
</label>
<div class="col-12">
<textarea
id={this.legalInfoTextAreaId}
value={this.state.legalInfo}
onInput={linkEvent(this, this.handleLegalInfoChange)}
class="form-control text-monospace"
rows={3}
/>
</div>
</div>
<div class="form-group row"> <div class="form-group row">
<div class="col-12"> <div class="col-12">
<button type="submit" class="btn btn-secondary mr-2"> <button type="submit" class="btn btn-secondary mr-2">
@ -229,14 +252,24 @@ export class AdminSettings extends Component<any, AdminSettingsState> {
); );
} }
handleSiteConfigSubmit(i: AdminSettings, event: any) { handleAdminSettingsSubmit(i: AdminSettings, event: any) {
event.preventDefault(); event.preventDefault();
i.state.siteConfigLoading = true; i.state.siteConfigLoading = true;
let form: SaveSiteConfig = {
config_hjson: this.state.siteConfigHjson, // save config
let form1: SaveSiteConfig = {
config_hjson: i.state.siteConfigHjson,
auth: authField(), auth: authField(),
}; };
WebSocketService.Instance.send(wsClient.saveSiteConfig(form)); WebSocketService.Instance.send(wsClient.saveSiteConfig(form1));
// save legal info
let form2: EditSite = {
legal_information: i.state.legalInfo,
auth: authField(),
};
WebSocketService.Instance.send(wsClient.editSite(form2));
i.setState(i.state); i.setState(i.state);
} }
@ -245,6 +278,11 @@ export class AdminSettings extends Component<any, AdminSettingsState> {
i.setState(i.state); i.setState(i.state);
} }
handleLegalInfoChange(i: AdminSettings, event: any) {
i.state.legalInfo = event.target.value;
i.setState(i.state);
}
handleLeaveAdminTeam(i: AdminSettings) { handleLeaveAdminTeam(i: AdminSettings) {
i.state.leaveAdminTeamLoading = true; i.state.leaveAdminTeamLoading = true;
WebSocketService.Instance.send(wsClient.leaveAdmin({ auth: authField() })); WebSocketService.Instance.send(wsClient.leaveAdmin({ auth: authField() }));

View file

@ -5,6 +5,7 @@ import { CreateCommunity } from "./components/community/create-community";
import { AdminSettings } from "./components/home/admin-settings"; import { AdminSettings } from "./components/home/admin-settings";
import { Home } from "./components/home/home"; import { Home } from "./components/home/home";
import { Instances } from "./components/home/instances"; import { Instances } from "./components/home/instances";
import { Legal } from "./components/home/legal";
import { Login } from "./components/home/login"; import { Login } from "./components/home/login";
import { Setup } from "./components/home/setup"; import { Setup } from "./components/home/setup";
import { Signup } from "./components/home/signup"; import { Signup } from "./components/home/signup";
@ -154,4 +155,5 @@ export const routes: IRoutePropsWithFetch[] = [
component: VerifyEmail, component: VerifyEmail,
}, },
{ path: `/instances`, component: Instances }, { path: `/instances`, component: Instances },
{ path: `/legal`, component: Legal },
]; ];

View file

@ -4813,10 +4813,9 @@ lcid@^1.0.0:
dependencies: dependencies:
invert-kv "^1.0.0" invert-kv "^1.0.0"
lemmy-js-client@0.16.4-rc.1: "lemmy-js-client@git+https://github.com/LemmyNet/lemmy-js-client.git#legal-info":
version "0.16.4-rc.1" version "0.17.0-rc.9"
resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.16.4-rc.1.tgz#dfa94a152a7abe75f50f2599a8d9b40c143f37ff" resolved "git+https://github.com/LemmyNet/lemmy-js-client.git#43def4db22e9068ddcee558f4cd5c1b3bd407f31"
integrity sha512-94Xh7A/WDywRaJ0GPXPaXZhyXqMzK0gAISNSB8m++2mC1WJalOqfjR72q/7PmLGxfjYO88/aWSz4Sk0SXWJjCw==
levn@^0.4.1: levn@^0.4.1:
version "0.4.1" version "0.4.1"