From b97d186cb50eb1d0eb8f06b0a96e690a86ff981e Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 17 Jun 2013 12:54:25 +1000 Subject: [PATCH] automatic groups should not allow you to muck with the listed users in the group --- .../admin/templates/groups.js.handlebars | 3 +- .../discourse/components/autocomplete.js | 3 +- .../discourse/views/user_selector_view.js | 2 ++ .../stylesheets/application/compose.css.scss | 13 +++++++-- app/controllers/admin/groups_controller.rb | 28 +++++++++++++------ app/controllers/application_controller.rb | 1 - config/locales/server.en.yml | 2 ++ 7 files changed, 38 insertions(+), 14 deletions(-) diff --git a/app/assets/javascripts/admin/templates/groups.js.handlebars b/app/assets/javascripts/admin/templates/groups.js.handlebars index 42969911470..e5ef8efa777 100644 --- a/app/assets/javascripts/admin/templates/groups.js.handlebars +++ b/app/assets/javascripts/admin/templates/groups.js.handlebars @@ -1,4 +1,3 @@ -

{{i18n admin.groups.edit}}

@@ -25,7 +24,7 @@ {{textField value=name placeholderKey="admin.groups.name_placeholder"}} {{/if}} - {{userSelector usernames=usernames id="group-users" placeholderKey="admin.groups.selector_placeholder" tabindex="1"}} + {{userSelector usernames=usernames id="group-users" placeholderKey="admin.groups.selector_placeholder" tabindex="1" disabledBinding="automatic"}}
{{#unless automatic}} diff --git a/app/assets/javascripts/discourse/components/autocomplete.js b/app/assets/javascripts/discourse/components/autocomplete.js index 842478b6c2c..516149ee58d 100644 --- a/app/assets/javascripts/discourse/components/autocomplete.js +++ b/app/assets/javascripts/discourse/components/autocomplete.js @@ -18,6 +18,7 @@ $.fn.autocomplete = function(options) { alert("only supporting one matcher at the moment"); } + var disabled = options && options.disabled; var wrap = null; var autocompleteOptions = null; var selectedOption = null; @@ -87,7 +88,7 @@ $.fn.autocomplete = function(options) { if (isInput) { var width = this.width(); var height = this.height(); - wrap = this.wrap("
").parent(); + wrap = this.wrap("
").parent(); wrap.width(width); this.width(150); this.attr('name', this.attr('name') + "-renamed"); diff --git a/app/assets/javascripts/discourse/views/user_selector_view.js b/app/assets/javascripts/discourse/views/user_selector_view.js index c530dfa5915..7ce26b25542 100644 --- a/app/assets/javascripts/discourse/views/user_selector_view.js +++ b/app/assets/javascripts/discourse/views/user_selector_view.js @@ -8,6 +8,8 @@ Discourse.UserSelector = Discourse.TextField.extend({ $(this.get('element')).val(this.get('usernames')).autocomplete({ template: Discourse.UserSelector.templateFunction(), + disabled: this.get('disabled'), + dataSource: function(term) { var exclude = selected; if (userSelectorView.get('excludeCurrentUser')){ diff --git a/app/assets/stylesheets/application/compose.css.scss b/app/assets/stylesheets/application/compose.css.scss index ffe634169c9..4d39911dc55 100644 --- a/app/assets/stylesheets/application/compose.css.scss +++ b/app/assets/stylesheets/application/compose.css.scss @@ -342,15 +342,24 @@ margin-bottom: 10px; } +div.ac-wrap.disabled { + input { + display:none; + } + .item a { + display:none; + } +} div.ac-wrap { background-color: $white; border: 1px solid #cccccc; - padding: 4px 10px; + padding: 5px 10px 0; @include border-radius-all(3px); div.item { float: left; margin-right: 10px; + margin-bottom: 5px; span { padding-left: 5px; height: 22px; @@ -519,4 +528,4 @@ div.ac-wrap { margin: 0; } } -} \ No newline at end of file +} diff --git a/app/controllers/admin/groups_controller.rb b/app/controllers/admin/groups_controller.rb index 7eb4a7195aa..06d9404c03e 100644 --- a/app/controllers/admin/groups_controller.rb +++ b/app/controllers/admin/groups_controller.rb @@ -16,11 +16,14 @@ class Admin::GroupsController < Admin::AdminController def update group = Group.find(params[:id].to_i) - render_json_error if group.automatic - group.usernames = params[:group][:usernames] - group.name = params[:group][:name] if params[:name] - group.save! - render json: "ok" + if group.automatic + can_not_modify_automatic + else + group.usernames = params[:group][:usernames] + group.name = params[:group][:name] if params[:name] + group.save! + render json: "ok" + end end def create @@ -33,8 +36,17 @@ class Admin::GroupsController < Admin::AdminController def destroy group = Group.find(params[:id].to_i) - render_json_error if group.automatic - group.destroy - render json: "ok" + if group.automatic + can_not_modify_automatic + else + group.destroy + render json: "ok" + end + end + + protected + + def can_not_modify_automatic + render json: {errors: I18n.t('groups.errors.can_not_modify_automatic')}, status: 422 end end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 4b5c5f74be6..3ca7dd5d0f6 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -195,7 +195,6 @@ class ApplicationController < ActionController::Base user end - private def render_json_error(obj) diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 274f17112dc..5a3649915a9 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -56,6 +56,8 @@ en: private_message_abbrev: "PM" groups: + errors: + can_not_modify_automatic: "You can not modify an automatic group" default_names: admins: "admins" moderators: "moderators"