From 9db5d5b6a79a367bb2663a54b1334fe233c64230 Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Tue, 20 Dec 2016 15:44:22 +0800 Subject: [PATCH] FIX: Incorrect serializer for groups page. --- .../components/group-membership-button.hbs | 16 ++++++++++++---- app/controllers/groups_controller.rb | 2 +- config/locales/client.en.yml | 1 + spec/integration/groups_spec.rb | 2 ++ 4 files changed, 16 insertions(+), 5 deletions(-) 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 a3353050c69..f6294badaec 100644 --- a/app/assets/javascripts/discourse/templates/components/group-membership-button.hbs +++ b/app/assets/javascripts/discourse/templates/components/group-membership-button.hbs @@ -13,10 +13,18 @@ disabled=updatingMembership}} {{/if}} {{else if canRequestMembership}} - {{d-button action="requestMembership" - class="group-index-request" - icon="envelope" - label="groups.request"}} + {{#if model.is_group_user}} + {{d-button + class="btn-primary" + icon="user" + label="groups.is_group_user" + disabled=model.is_group_user}} + {{else}} + {{d-button action="requestMembership" + class="group-index-request" + icon="envelope" + label="groups.request"}} + {{/if}} {{else}} {{yield}} {{/if}} diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb index 3f339f0d317..92950b43f2b 100644 --- a/app/controllers/groups_controller.rb +++ b/app/controllers/groups_controller.rb @@ -24,7 +24,7 @@ class GroupsController < ApplicationController groups = groups.offset(page * page_size).limit(page_size) render json: { - groups: serialize_data(groups, BasicGroupSerializer), + groups: serialize_data(groups, GroupShowSerializer), total_rows_groups: count, load_more_groups: groups_path(page: page + 1) } diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 230f5c62398..3e42afcc4d2 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -417,6 +417,7 @@ en: request: "Request to Join Group" automatic_group: Automatic Group closed_group: Closed Group + is_group_user: "You are a member of this group" allow_membership_requests: "Allow users to send membership requests to group owners (Requires everyone to be able to mention the group)" membership: "Membership" name: "Name" diff --git a/spec/integration/groups_spec.rb b/spec/integration/groups_spec.rb index a38d556768e..ae88d609d23 100644 --- a/spec/integration/groups_spec.rb +++ b/spec/integration/groups_spec.rb @@ -23,6 +23,7 @@ describe "Groups" do group_ids = response_body["groups"].map { |g| g["id"] } + expect(response_body["groups"].map { |g| g['is_group_user'] }).to eq([nil]) expect(group_ids).to include(other_group.id) expect(group_ids).to_not include(group.id) expect(response_body["load_more_groups"]).to eq("/groups?page=1") @@ -41,6 +42,7 @@ describe "Groups" do group_ids = response_body["groups"].map { |g| g["id"] } + expect(response_body["groups"].first['is_group_user']).to eq(false) expect(group_ids).to include(group.id, other_group.id) expect(response_body["load_more_groups"]).to eq("/groups?page=1") expect(response_body["total_rows_groups"]).to eq(10)