FEATURE: group can grant a trust level when a user is added
This commit is contained in:
parent
f2fa7a39be
commit
1bd0f5b015
|
@ -27,6 +27,13 @@ export default Ember.Controller.extend({
|
|||
];
|
||||
}.property(),
|
||||
|
||||
trustLevelOptions: function() {
|
||||
return [
|
||||
{ name: I18n.t("groups.trust_levels.none"), value: 0 },
|
||||
{ name: 1, value: 1 }, { name: 2, value: 2 }, { name: 3, value: 3 }, { name: 4, value: 4 }
|
||||
];
|
||||
}.property(),
|
||||
|
||||
actions: {
|
||||
next() {
|
||||
if (this.get("showingLast")) { return; }
|
||||
|
|
|
@ -70,6 +70,11 @@
|
|||
</label>
|
||||
{{input value=model.title}}
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label for="grant_trust_level">{{i18n 'groups.trust_levels.title'}}</label>
|
||||
{{combo-box name="grant_trust_level" valueAttribute="value" value=model.grant_trust_level content=trustLevelOptions}}
|
||||
</div>
|
||||
{{/unless}}
|
||||
|
||||
<div class='buttons'>
|
||||
|
|
|
@ -62,7 +62,8 @@ const Group = Discourse.Model.extend({
|
|||
automatic_membership_email_domains: this.get('emailDomains'),
|
||||
automatic_membership_retroactive: !!this.get('automatic_membership_retroactive'),
|
||||
title: this.get('title'),
|
||||
primary_group: !!this.get('primary_group')
|
||||
primary_group: !!this.get('primary_group'),
|
||||
grant_trust_level: this.get('grant_trust_level')
|
||||
};
|
||||
},
|
||||
|
||||
|
|
|
@ -37,6 +37,8 @@ class Admin::GroupsController < Admin::AdminController
|
|||
def save_group(group)
|
||||
group.alias_level = params[:alias_level].to_i if params[:alias_level].present?
|
||||
group.visible = params[:visible] == "true"
|
||||
grant_trust_level = params[:grant_trust_level].to_i
|
||||
group.grant_trust_level = (grant_trust_level > 0 && grant_trust_level <= 4) ? grant_trust_level : nil
|
||||
|
||||
group.automatic_membership_email_domains = params[:automatic_membership_email_domains] unless group.automatic
|
||||
group.automatic_membership_retroactive = params[:automatic_membership_retroactive] == "true" unless group.automatic
|
||||
|
|
|
@ -372,6 +372,7 @@ end
|
|||
# visible :boolean default(TRUE), not null
|
||||
# automatic_membership_email_domains :text
|
||||
# automatic_membership_retroactive :boolean default(FALSE)
|
||||
# grant_trust_level :integer
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
|
|
|
@ -8,6 +8,8 @@ class GroupUser < ActiveRecord::Base
|
|||
after_save :set_primary_group
|
||||
after_destroy :remove_primary_group
|
||||
|
||||
after_save :grant_trust_level
|
||||
|
||||
protected
|
||||
|
||||
def set_primary_group
|
||||
|
@ -44,6 +46,15 @@ class GroupUser < ActiveRecord::Base
|
|||
title: group.title)
|
||||
end
|
||||
end
|
||||
|
||||
def grant_trust_level
|
||||
return if group.grant_trust_level.nil?
|
||||
if user.trust_level < group.grant_trust_level
|
||||
user.change_trust_level!(group.grant_trust_level)
|
||||
user.trust_level_locked = true
|
||||
user.save
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# == Schema Information
|
||||
|
|
|
@ -8,5 +8,6 @@ class BasicGroupSerializer < ApplicationSerializer
|
|||
:automatic_membership_email_domains,
|
||||
:automatic_membership_retroactive,
|
||||
:primary_group,
|
||||
:title
|
||||
:title,
|
||||
:grant_trust_level
|
||||
end
|
||||
|
|
|
@ -343,6 +343,9 @@ en:
|
|||
mods_and_admins: "Only moderators and Admins"
|
||||
members_mods_and_admins: "Only group members, moderators and admins"
|
||||
everyone: "Everyone"
|
||||
trust_levels:
|
||||
title: "Trust level automatically granted to members when they're added:"
|
||||
none: "None"
|
||||
|
||||
user_action_groups:
|
||||
"1": "Likes Given"
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
class AddGrantTrustLevelToGroups < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :groups, :grant_trust_level, :integer
|
||||
end
|
||||
end
|
|
@ -29,7 +29,8 @@ describe Admin::GroupsController do
|
|||
"automatic_membership_email_domains"=>nil,
|
||||
"automatic_membership_retroactive"=>false,
|
||||
"title"=>nil,
|
||||
"primary_group"=>false
|
||||
"primary_group"=>false,
|
||||
"grant_trust_level"=>nil
|
||||
}])
|
||||
end
|
||||
|
||||
|
|
|
@ -311,4 +311,16 @@ describe Group do
|
|||
end
|
||||
end
|
||||
|
||||
it "correctly grants a trust level to members" do
|
||||
group = Fabricate(:group, grant_trust_level: 2)
|
||||
u0 = Fabricate(:user, trust_level: 0)
|
||||
u3 = Fabricate(:user, trust_level: 3)
|
||||
|
||||
group.add(u0)
|
||||
expect(u0.reload.trust_level).to eq(2)
|
||||
|
||||
group.add(u3)
|
||||
expect(u3.reload.trust_level).to eq(3)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue