Don't allow transfer site. (#551)

* Don't allow transfer site.

* Updating translations.

* Adding leave admin team.
This commit is contained in:
Dessalines 2022-02-14 12:27:43 -05:00 committed by GitHub
parent 055ed466d3
commit 399149b278
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 39 additions and 112 deletions

@ -1 +1 @@
Subproject commit b18bfc1a8d512d081056cf5aa1f422e4710ef683
Subproject commit 0d63b5affe2273bb88b3593cdc13e4bb0f4d2d5d

View file

@ -75,7 +75,7 @@
"husky": "^7.0.4",
"import-sort-style-module": "^6.0.0",
"iso-639-1": "^2.1.10",
"lemmy-js-client": "0.15.0",
"lemmy-js-client": "0.15.1-rc.1",
"lint-staged": "^12.1.2",
"mini-css-extract-plugin": "^2.4.5",
"node-fetch": "^2.6.1",

View file

@ -18,7 +18,6 @@ import {
RemoveComment,
SaveComment,
TransferCommunity,
TransferSite,
} from "lemmy-js-client";
import moment from "moment";
import { i18n } from "../../i18next";
@ -686,51 +685,6 @@ export class CommentNode extends Component<CommentNodeProps, CommentNodeState> {
))}
</>
)}
{/* Site Creator can transfer to another admin */}
{this.amSiteCreator &&
this.isAdmin &&
cv.creator.local &&
(!this.state.showConfirmTransferSite ? (
<button
class="btn btn-link btn-animate text-muted"
onClick={linkEvent(
this,
this.handleShowConfirmTransferSite
)}
aria-label={i18n.t("transfer_site")}
>
{i18n.t("transfer_site")}
</button>
) : (
<>
<button
class="btn btn-link btn-animate text-muted"
aria-label={i18n.t("are_you_sure")}
>
{i18n.t("are_you_sure")}
</button>
<button
class="btn btn-link btn-animate text-muted"
onClick={linkEvent(
this,
this.handleTransferSite
)}
aria-label={i18n.t("yes")}
>
{i18n.t("yes")}
</button>
<button
class="btn btn-link btn-animate text-muted"
onClick={linkEvent(
this,
this.handleCancelShowConfirmTransferSite
)}
aria-label={i18n.t("no")}
>
{i18n.t("no")}
</button>
</>
))}
</>
)}
</>
@ -1339,16 +1293,6 @@ export class CommentNode extends Component<CommentNodeProps, CommentNodeState> {
i.setState(i.state);
}
handleTransferSite(i: CommentNode) {
let form: TransferSite = {
person_id: i.props.node.comment_view.creator.id,
auth: authField(),
};
WebSocketService.Instance.send(wsClient.transferSite(form));
i.state.showConfirmTransferSite = false;
i.setState(i.state);
}
get isCommentNew(): boolean {
let now = moment.utc().subtract(10, "minutes");
let then = moment.utc(this.props.node.comment_view.comment.published);

View file

@ -39,6 +39,7 @@ interface AdminSettingsState {
loading: boolean;
banned: PersonViewSafe[];
siteConfigLoading: boolean;
leaveAdminTeamLoading: boolean;
}
export class AdminSettings extends Component<any, AdminSettingsState> {
@ -57,6 +58,7 @@ export class AdminSettings extends Component<any, AdminSettingsState> {
banned: [],
loading: true,
siteConfigLoading: null,
leaveAdminTeamLoading: null,
};
constructor(props: any, context: any) {
@ -159,10 +161,26 @@ export class AdminSettings extends Component<any, AdminSettingsState> {
</li>
))}
</ul>
{this.leaveAdmin()}
</>
);
}
leaveAdmin() {
return (
<button
onClick={linkEvent(this, this.handleLeaveAdminTeam)}
class="btn btn-danger mb-2"
>
{this.state.leaveAdminTeamLoading ? (
<Spinner />
) : (
i18n.t("leave_admin_team")
)}
</button>
);
}
bannedUsers() {
return (
<>
@ -230,6 +248,12 @@ export class AdminSettings extends Component<any, AdminSettingsState> {
i.setState(i.state);
}
handleLeaveAdminTeam(i: AdminSettings) {
i.state.leaveAdminTeamLoading = true;
WebSocketService.Instance.send(wsClient.leaveAdmin({ auth: authField() }));
i.setState(i.state);
}
parseMessage(msg: any) {
let op = wsUserOp(msg);
console.log(msg);
@ -257,6 +281,14 @@ export class AdminSettings extends Component<any, AdminSettingsState> {
this.setState(this.state);
var textarea: any = document.getElementById(this.siteConfigTextAreaId);
autosize(textarea);
} else if (op == UserOperation.LeaveAdmin) {
let data = wsJsonToRes<GetSiteResponse>(msg).data;
this.state.siteRes.site_view = data.site_view;
this.setState(this.state);
this.state.leaveAdminTeamLoading = false;
toast(i18n.t("left_admin_team"));
this.setState(this.state);
this.context.router.history.push("/");
} else if (op == UserOperation.SaveSiteConfig) {
let data = wsJsonToRes<GetSiteConfigResponse>(msg).data;
this.state.siteConfigRes = data;

View file

@ -18,7 +18,6 @@ import {
SavePost,
StickyPost,
TransferCommunity,
TransferSite,
} from "lemmy-js-client";
import { externalHost } from "../../env";
import { i18n } from "../../i18next";
@ -937,44 +936,6 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
)}
</>
)}
{/* Site Creator can transfer to another admin */}
{this.amSiteCreator &&
this.creatorIsAdmin &&
(!this.state.showConfirmTransferSite ? (
<button
class="btn btn-link btn-animate text-muted py-0"
onClick={linkEvent(this, this.handleShowConfirmTransferSite)}
aria-label={i18n.t("transfer_site")}
>
{i18n.t("transfer_site")}
</button>
) : (
<>
<button
class="btn btn-link btn-animate text-muted py-0 d-inline-block mr-1"
aria-label={i18n.t("are_you_sure")}
>
{i18n.t("are_you_sure")}
</button>
<button
class="btn btn-link btn-animate text-muted py-0 d-inline-block mr-1"
onClick={linkEvent(this, this.handleTransferSite)}
aria-label={i18n.t("yes")}
>
{i18n.t("yes")}
</button>
<button
class="btn btn-link btn-animate text-muted py-0 d-inline-block"
onClick={linkEvent(
this,
this.handleCancelShowConfirmTransferSite
)}
aria-label={i18n.t("no")}
>
{i18n.t("no")}
</button>
</>
))}
</>
)
);
@ -1617,16 +1578,6 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
i.setState(i.state);
}
handleTransferSite(i: PostListing) {
let form: TransferSite = {
person_id: i.props.post_view.creator.id,
auth: authField(),
};
WebSocketService.Instance.send(wsClient.transferSite(form));
i.state.showConfirmTransferSite = false;
i.setState(i.state);
}
handleImageExpandClick(i: PostListing, event: any) {
event.preventDefault();
i.state.imageExpanded = !i.state.imageExpanded;

View file

@ -645,7 +645,7 @@ export class Post extends Component<any, PostState> {
p => p.post.id != Number(this.props.match.params.id)
);
this.setState(this.state);
} else if (op == UserOperation.TransferSite) {
} else if (op == UserOperation.LeaveAdmin) {
let data = wsJsonToRes<GetSiteResponse>(msg).data;
this.state.siteRes = data;
this.setState(this.state);

View file

@ -4629,10 +4629,10 @@ lcid@^1.0.0:
dependencies:
invert-kv "^1.0.0"
lemmy-js-client@0.15.0:
version "0.15.0"
resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.15.0.tgz#984aadbfb2c8e7cebb61d429f0cf576245876a0b"
integrity sha512-BWeI0cQOdjxDLHShyNGjYCMxdZf08sJnKKg2DNe9Js/sgMpv9OY9ZDiDOvV8R1QatqdAbwPv8HOgVQRAV6SYDQ==
lemmy-js-client@0.15.1-rc.1:
version "0.15.1-rc.1"
resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.15.1-rc.1.tgz#9d914098eefc25834f077c4690d4e3e2ab4f2c57"
integrity sha512-rs80HTzwayt2EpjQ+ruQM82bZydjk9kZUUjZidYzwmy1FBkWpG5+OBnW3X6YQ5ebswiobL8HraNfnWMm0zqvjQ==
levn@^0.4.1:
version "0.4.1"