From 81e2a0099f37f85d6884ba6ed232398671246414 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Mon, 24 Oct 2016 10:53:31 +0200 Subject: [PATCH] FIX: ensure the group 'everyone' is never shown when using a different locale --- app/controllers/admin/groups_controller.rb | 5 ++--- app/models/group.rb | 9 +++------ spec/controllers/admin/groups_controller_spec.rb | 6 +++--- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/app/controllers/admin/groups_controller.rb b/app/controllers/admin/groups_controller.rb index 7bd066ddba5..94ef113634f 100644 --- a/app/controllers/admin/groups_controller.rb +++ b/app/controllers/admin/groups_controller.rb @@ -1,10 +1,9 @@ class Admin::GroupsController < Admin::AdminController def index - groups = Group.order(:name).where("name <> 'everyone'") + groups = Group.order(:name).where("id <> ?", Group::AUTO_GROUPS[:everyone]) - if search = params[:search] - search = search.to_s + if search = params[:search].to_s groups = groups.where("name ILIKE ?", "%#{search}%") end diff --git a/app/models/group.rb b/app/models/group.rb index 37eaa32410d..05c49801590 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -149,13 +149,10 @@ class Group < ActiveRecord::Base group.save! end - group.name = I18n.t("groups.default_names.#{name}") - # don't allow shoddy localization to break this - validator = UsernameValidator.new(group.name) - unless validator.valid_format? - group.name = name - end + localized_name = I18n.t("groups.default_names.#{name}") + validator = UsernameValidator.new(localized_name) + group.name = validator.valid_format? ? localized_name : name # the everyone group is special, it can include non-users so there is no # way to have the membership in a table diff --git a/spec/controllers/admin/groups_controller_spec.rb b/spec/controllers/admin/groups_controller_spec.rb index 5baa846b1f9..46f428400a3 100644 --- a/spec/controllers/admin/groups_controller_spec.rb +++ b/spec/controllers/admin/groups_controller_spec.rb @@ -19,7 +19,9 @@ describe Admin::GroupsController do xhr :get, :index expect(response.status).to eq(200) - expect(::JSON.parse(response.body).keep_if {|r| r["id"] == group.id }).to eq([{ + json = ::JSON.parse(response.body) + expect(json.select { |r| r["id"] == Group::AUTO_GROUPS[:everyone] }).to be_empty + expect(json.select { |r| r["id"] == group.id }).to eq([{ "id"=>group.id, "name"=>group.name, "user_count"=>1, @@ -135,6 +137,4 @@ describe Admin::GroupsController do end - - end