FIX: prevents group show serializer to override basic group serializer (#10326)

This commit is contained in:
Joffrey JAFFEUX 2020-07-28 18:11:15 +02:00 committed by GitHub
parent 4e317e7aca
commit 11faec71ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 3 additions and 42 deletions

View File

@ -1,5 +1,5 @@
import Controller, { inject as controller } from "@ember/controller";
import { gt, readOnly } from "@ember/object/computed";
import { gt } from "@ember/object/computed";
import discourseComputed, { observes } from "discourse-common/utils/decorators";
import { popupAjaxError } from "discourse/lib/ajax-error";
import discourseDebounce from "discourse/lib/debounce";
@ -16,7 +16,6 @@ export default Controller.extend({
filterInput: null,
loading: false,
isOwner: readOnly("model.is_group_owner"),
showActions: false,
@observes("filterInput")

View File

@ -91,11 +91,6 @@ export default Controller.extend({
return isGroupUser || (this.currentUser && this.currentUser.admin);
},
@discourseComputed("model.is_group_owner", "model.automatic")
canEditGroup(isGroupOwner, automatic) {
return !automatic && isGroupOwner;
},
@discourseComputed("model.displayName", "model.full_name")
groupName(displayName, fullName) {
return (fullName || displayName).capitalize();

View File

@ -16,7 +16,7 @@ class GroupShowSerializer < BasicGroupSerializer
end
def is_group_owner
scope.is_admin? || fetch_group_user&.owner
fetch_group_user&.owner
end
def include_is_group_owner_display?

View File

@ -13,7 +13,7 @@ describe GroupShowSerializer do
it 'should return the right attributes' do
json = GroupShowSerializer.new(group, scope: Guardian.new(user)).as_json
expect(json[:group_show][:is_group_owner]).to eq(true)
expect(json[:group_show][:is_group_owner]).to eq(false)
expect(json[:group_show][:is_group_user]).to eq(true)
end
end

View File

@ -1,33 +0,0 @@
moduleFor("controller:group", {
needs: ["controller:application"]
});
QUnit.test("canEditGroup", function(assert) {
const GroupController = this.subject();
GroupController.setProperties({
model: { is_group_owner: true, automatic: true }
});
assert.equal(
GroupController.get("canEditGroup"),
false,
"automatic groups cannot be edited"
);
GroupController.set("model.automatic", false);
assert.equal(
GroupController.get("canEditGroup"),
true,
"owners can edit groups"
);
GroupController.set("model.is_group_owner", false);
assert.equal(
GroupController.get("canEditGroup"),
false,
"normal users cannot edit groups"
);
});