From 399149b2784d6d281fd8017b2b09bcb57a77d924 Mon Sep 17 00:00:00 2001
From: Dessalines <dessalines@users.noreply.github.com>
Date: Mon, 14 Feb 2022 12:27:43 -0500
Subject: [PATCH] Don't allow transfer site. (#551)

* Don't allow transfer site.

* Updating translations.

* Adding leave admin team.
---
 lemmy-translations                            |  2 +-
 package.json                                  |  2 +-
 .../components/comment/comment-node.tsx       | 56 -------------------
 src/shared/components/home/admin-settings.tsx | 32 +++++++++++
 src/shared/components/post/post-listing.tsx   | 49 ----------------
 src/shared/components/post/post.tsx           |  2 +-
 yarn.lock                                     |  8 +--
 7 files changed, 39 insertions(+), 112 deletions(-)

diff --git a/lemmy-translations b/lemmy-translations
index b18bfc1..0d63b5a 160000
--- a/lemmy-translations
+++ b/lemmy-translations
@@ -1 +1 @@
-Subproject commit b18bfc1a8d512d081056cf5aa1f422e4710ef683
+Subproject commit 0d63b5affe2273bb88b3593cdc13e4bb0f4d2d5d
diff --git a/package.json b/package.json
index 4a20581..63ddad7 100644
--- a/package.json
+++ b/package.json
@@ -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",
diff --git a/src/shared/components/comment/comment-node.tsx b/src/shared/components/comment/comment-node.tsx
index f40aa0a..1af8e11 100644
--- a/src/shared/components/comment/comment-node.tsx
+++ b/src/shared/components/comment/comment-node.tsx
@@ -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);
diff --git a/src/shared/components/home/admin-settings.tsx b/src/shared/components/home/admin-settings.tsx
index ed56e15..284805b 100644
--- a/src/shared/components/home/admin-settings.tsx
+++ b/src/shared/components/home/admin-settings.tsx
@@ -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;
diff --git a/src/shared/components/post/post-listing.tsx b/src/shared/components/post/post-listing.tsx
index 61a0930..1608d41 100644
--- a/src/shared/components/post/post-listing.tsx
+++ b/src/shared/components/post/post-listing.tsx
@@ -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;
diff --git a/src/shared/components/post/post.tsx b/src/shared/components/post/post.tsx
index dcc9871..4ae1cc5 100644
--- a/src/shared/components/post/post.tsx
+++ b/src/shared/components/post/post.tsx
@@ -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);
diff --git a/yarn.lock b/yarn.lock
index 1e7fd8d..824c1a8 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -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"
-- 
2.44.1