@@ -39,7 +44,7 @@
{{/with}}
diff --git a/app/assets/javascripts/discourse/models/group.js b/app/assets/javascripts/discourse/models/group.js
index e9a94188f33..3502c92fea0 100644
--- a/app/assets/javascripts/discourse/models/group.js
+++ b/app/assets/javascripts/discourse/models/group.js
@@ -83,17 +83,19 @@ Discourse.Group = Discourse.Model.extend({
});
},
+ asJSON: function() {
+ return { group: {
+ name: this.get('name'),
+ alias_level: this.get('alias_level'),
+ visible: !!this.get('visible'),
+ usernames: this.get('usernames') } };
+ },
+
create: function(){
var self = this;
self.set('disableSave', true);
- return Discourse.ajax("/admin/groups", {type: "POST", data: {
- group: {
- name: this.get('name'),
- alias_level: this.get('alias_level'),
- usernames: this.get('usernames')
- }
- }}).then(function(resp) {
+ return Discourse.ajax("/admin/groups", {type: "POST", data: this.asJSON()}).then(function(resp) {
self.set('disableSave', false);
self.set('id', resp.id);
}, function (error) {
@@ -113,13 +115,7 @@ Discourse.Group = Discourse.Model.extend({
return Discourse.ajax("/admin/groups/" + this.get('id'), {
type: "PUT",
- data: {
- group: {
- name: this.get('name'),
- alias_level: this.get('alias_level'),
- usernames: this.get('usernames')
- }
- }
+ data: this.asJSON()
}).then(function(){
self.set('disableSave', false);
}, function(e){
diff --git a/app/controllers/admin/groups_controller.rb b/app/controllers/admin/groups_controller.rb
index 232310e71f9..fcf92d29496 100644
--- a/app/controllers/admin/groups_controller.rb
+++ b/app/controllers/admin/groups_controller.rb
@@ -20,6 +20,7 @@ class Admin::GroupsController < Admin::AdminController
group.alias_level = params[:group][:alias_level]
group.name = params[:group][:name] if params[:group][:name]
end
+ group.visible = params[:group][:visible] == "true"
if group.save
render json: success_json
@@ -32,6 +33,7 @@ class Admin::GroupsController < Admin::AdminController
group = Group.new
group.name = params[:group][:name].strip
group.usernames = params[:group][:usernames] if params[:group][:usernames]
+ group.visible = params[:group][:visible] == "true"
if group.save
render_serialized(group, BasicGroupSerializer)
else
diff --git a/app/models/user.rb b/app/models/user.rb
index 8bda6da5520..c10f36b4513 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -109,7 +109,7 @@ class User < ActiveRecord::Base
end
def custom_groups
- groups.where(automatic: false)
+ groups.where(automatic: false, visible: true)
end
def self.username_available?(username)
diff --git a/app/serializers/basic_group_serializer.rb b/app/serializers/basic_group_serializer.rb
index 7c56bee4c6f..8f1574cb97b 100644
--- a/app/serializers/basic_group_serializer.rb
+++ b/app/serializers/basic_group_serializer.rb
@@ -1,3 +1,3 @@
class BasicGroupSerializer < ApplicationSerializer
- attributes :id, :automatic, :name, :user_count, :alias_level
+ attributes :id, :automatic, :name, :user_count, :alias_level, :visible
end
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index 54a483880fe..5e286ea2ff4 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -177,6 +177,7 @@ en:
sent_by_you: "Sent by
you"
groups:
+ visible: "Group is visible to all users"
title:
one: "group"
other: "groups"
diff --git a/db/migrate/20140422195623_add_visibile_to_groups.rb b/db/migrate/20140422195623_add_visibile_to_groups.rb
new file mode 100644
index 00000000000..58f65f6cb9d
--- /dev/null
+++ b/db/migrate/20140422195623_add_visibile_to_groups.rb
@@ -0,0 +1,5 @@
+class AddVisibileToGroups < ActiveRecord::Migration
+ def change
+ add_column :groups, :visible, :boolean, default: true, null: false
+ end
+end
diff --git a/lib/guardian.rb b/lib/guardian.rb
index 8a6648baadd..b223540ed1f 100644
--- a/lib/guardian.rb
+++ b/lib/guardian.rb
@@ -109,6 +109,10 @@ class Guardian
alias :can_send_activation_email? :can_moderate?
alias :can_grant_badges? :can_moderate?
+ def can_see_group?(group)
+ group.present? && group.visible?
+ end
+
# Can we impersonate this user?
diff --git a/spec/components/guardian_spec.rb b/spec/components/guardian_spec.rb
index ec83c27bd14..9cf9177341b 100644
--- a/spec/components/guardian_spec.rb
+++ b/spec/components/guardian_spec.rb
@@ -238,6 +238,16 @@ describe Guardian do
Guardian.new.can_see?(nil).should be_false
end
+ describe 'a Group' do
+ it "returns true when the group is visible" do
+ Guardian.new.can_see?(Group.new).should be_true
+ end
+
+ it "returns false when the group is invisible" do
+ Guardian.new.can_see?(Group.new(visible: false)).should be_false
+ end
+ end
+
describe 'a Topic' do
it 'allows non logged in users to view topics' do
Guardian.new.can_see?(topic).should be_true
diff --git a/spec/controllers/admin/groups_controller_spec.rb b/spec/controllers/admin/groups_controller_spec.rb
index f3f130e4666..9ab5f2e0976 100644
--- a/spec/controllers/admin/groups_controller_spec.rb
+++ b/spec/controllers/admin/groups_controller_spec.rb
@@ -22,7 +22,8 @@ describe Admin::GroupsController do
"name"=>group.name,
"user_count"=>1,
"automatic"=>false,
- "alias_level"=>0
+ "alias_level"=>0,
+ "visible"=>true
}]
end