FIX: Hide group membership request button for existing members

FIX: Hide group membership request button for existing members
diff --git a/app/assets/javascripts/discourse/components/group-membership-button.js.es6 b/app/assets/javascripts/discourse/components/group-membership-button.js.es6
index b9559d3..d816b32 100644
--- a/app/assets/javascripts/discourse/components/group-membership-button.js.es6
+++ b/app/assets/javascripts/discourse/components/group-membership-button.js.es6
@@ -15,6 +15,11 @@ export default Ember.Component.extend({
     return publicExit && userIsGroupUser;
   },
 
+  @computed("model.allow_membership_requests", "userIsGroupUser")
+  canRequestMembership(allowMembershipRequests, userIsGroupUser) {
+    return allowMembershipRequests && !userIsGroupUser;
+  },
+
   @computed("model.is_group_user")
   userIsGroupUser(isGroupUser) {
     return !!isGroupUser;
diff --git a/app/assets/javascripts/discourse/templates/components/group-membership-button.hbs b/app/assets/javascripts/discourse/templates/components/group-membership-button.hbs
index 2bd1956..a76aeb2 100644
--- a/app/assets/javascripts/discourse/templates/components/group-membership-button.hbs
+++ b/app/assets/javascripts/discourse/templates/components/group-membership-button.hbs
@@ -10,7 +10,7 @@
       icon="user-times"
       label="groups.leave"
       disabled=updatingMembership}}
-{{else if model.allow_membership_requests}}
+{{else if canRequestMembership}}
   {{d-button action="showRequestMembershipForm"
       class="group-index-request"
       disabled=loading
diff --git a/test/javascripts/components/group-membership-button-test.js.es6 b/test/javascripts/components/group-membership-button-test.js.es6
index 1c46855..2304990 100644
--- a/test/javascripts/components/group-membership-button-test.js.es6
+++ b/test/javascripts/components/group-membership-button-test.js.es6
@@ -56,6 +56,26 @@ QUnit.test("canLeaveGroup", function(assert) {
   );
 });
 
+QUnit.test("canRequestMembership", function(assert) {
+  this.subject().setProperties({
+    model: { allow_membership_requests: true, is_group_user: true }
+  });
+
+  assert.equal(
+    this.subject().get("canRequestMembership"),
+    false,
+    "can't request for membership if user is already in the group"
+  );
+
+  this.subject().set("model.is_group_user", false);
+
+  assert.equal(
+    this.subject().get("canRequestMembership"),
+    true,
+    "allowed to request for group membership"
+  );
+});
+
 QUnit.test("userIsGroupUser", function(assert) {
   this.subject().setProperties({
     model: { is_group_user: true }

GitHub
sha: b3df4bee

2 Likes

This commit has been mentioned on Discourse Meta. There might be relevant details there: