FEATURE: default notification level for group messages
also fixes it so staff can amend other user's group notification level
This commit is contained in:
parent
05efa7ce68
commit
7a9eee1b71
|
@ -22,9 +22,9 @@ export default Ember.Controller.extend({
|
|||
];
|
||||
}.property(),
|
||||
|
||||
@computed('model.visible', 'model.public', 'model.alias_level')
|
||||
@computed('model.visible', 'model.public')
|
||||
disableMembershipRequestSetting(visible, publicGroup) {
|
||||
return !visible || publicGroup || !this.get('model.canEveryoneMention');
|
||||
return !visible || publicGroup;
|
||||
},
|
||||
|
||||
@computed('model.visible', 'model.allow_membership_requests')
|
||||
|
|
|
@ -83,6 +83,12 @@
|
|||
{{combo-box name="alias" valueAttribute="value" value=model.alias_level content=aliasLevelOptions}}
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label>{{i18n 'groups.notification_level'}}</label>
|
||||
{{notifications-button i18nPrefix='groups.notifications' notificationLevel=model.default_notification_level}}
|
||||
<div class='clearfix'></div>
|
||||
</div>
|
||||
|
||||
{{#unless model.automatic}}
|
||||
<div>
|
||||
<label for="automatic_membership">{{i18n 'admin.groups.automatic_membership_email_domains'}}</label>
|
||||
|
|
|
@ -6,6 +6,6 @@ export default NotificationsButton.extend({
|
|||
i18nPrefix: 'groups.notifications',
|
||||
|
||||
clicked(id) {
|
||||
this.get('group').setNotification(id);
|
||||
this.get('group').setNotification(id, this.get('user.id'));
|
||||
}
|
||||
});
|
||||
|
|
|
@ -43,7 +43,7 @@ export default DropdownButton.extend({
|
|||
}
|
||||
},
|
||||
|
||||
clicked(/* id */) {
|
||||
// sub-class needs to implement this
|
||||
clicked(id) {
|
||||
this.set("notificationLevel", id);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -139,7 +139,8 @@ const Group = RestModel.extend({
|
|||
bio_raw: this.get('bio_raw'),
|
||||
public: this.get('public'),
|
||||
allow_membership_requests: this.get('allow_membership_requests'),
|
||||
full_name: this.get('full_name')
|
||||
full_name: this.get('full_name'),
|
||||
default_notification_level: this.get('default_notification_level')
|
||||
};
|
||||
},
|
||||
|
||||
|
@ -191,10 +192,10 @@ const Group = RestModel.extend({
|
|||
});
|
||||
},
|
||||
|
||||
setNotification(notification_level) {
|
||||
setNotification(notification_level, userId) {
|
||||
this.set("group_user.notification_level", notification_level);
|
||||
return ajax(`/groups/${this.get("name")}/notifications`, {
|
||||
data: { notification_level },
|
||||
data: { notification_level, user_id: userId },
|
||||
type: "POST"
|
||||
});
|
||||
}
|
||||
|
|
|
@ -73,7 +73,7 @@
|
|||
{{/if}}
|
||||
|
||||
{{#if isGroup}}
|
||||
{{group-notifications-button group=group}}
|
||||
{{group-notifications-button group=group user=model}}
|
||||
{{/if}}
|
||||
</div>
|
||||
|
||||
|
|
|
@ -71,6 +71,10 @@ class Admin::GroupsController < Admin::AdminController
|
|||
group.bio_raw = group_params[:bio_raw] if group_params[:bio_raw]
|
||||
group.full_name = group_params[:full_name] if group_params[:full_name]
|
||||
|
||||
if group_params.key?(:default_notification_level)
|
||||
group.default_notification_level = group_params[:default_notification_level]
|
||||
end
|
||||
|
||||
if group_params[:allow_membership_requests]
|
||||
group.allow_membership_requests = group_params[:allow_membership_requests]
|
||||
end
|
||||
|
@ -150,7 +154,8 @@ class Admin::GroupsController < Admin::AdminController
|
|||
:name, :alias_level, :visible, :automatic_membership_email_domains,
|
||||
:automatic_membership_retroactive, :title, :primary_group,
|
||||
:grant_trust_level, :incoming_email, :flair_url, :flair_bg_color,
|
||||
:flair_color, :bio_raw, :public, :allow_membership_requests, :full_name
|
||||
:flair_color, :bio_raw, :public, :allow_membership_requests, :full_name,
|
||||
:default_notification_level
|
||||
)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -245,8 +245,13 @@ class GroupsController < ApplicationController
|
|||
group = find_group(:id)
|
||||
notification_level = params.require(:notification_level)
|
||||
|
||||
user_id = current_user.id
|
||||
if guardian.is_staff?
|
||||
user_id = params[:user_id] || user_id
|
||||
end
|
||||
|
||||
GroupUser.where(group_id: group.id)
|
||||
.where(user_id: current_user.id)
|
||||
.where(user_id: user_id)
|
||||
.update_all(notification_level: notification_level)
|
||||
|
||||
render json: success_json
|
||||
|
|
|
@ -194,4 +194,5 @@ end
|
|||
# updated_at :datetime not null
|
||||
# via_wizard :boolean default(FALSE), not null
|
||||
# base_scheme_id :string
|
||||
# theme_id :integer
|
||||
#
|
||||
|
|
|
@ -552,6 +552,7 @@ end
|
|||
# public :boolean default(FALSE), not null
|
||||
# allow_membership_requests :boolean default(FALSE), not null
|
||||
# full_name :string
|
||||
# default_notification_level :integer default(3), not null
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
|
|
|
@ -10,6 +10,7 @@ class GroupUser < ActiveRecord::Base
|
|||
after_save :set_primary_group
|
||||
after_destroy :remove_primary_group
|
||||
|
||||
before_create :set_notification_level
|
||||
after_save :grant_trust_level
|
||||
|
||||
def self.notification_levels
|
||||
|
@ -18,6 +19,10 @@ class GroupUser < ActiveRecord::Base
|
|||
|
||||
protected
|
||||
|
||||
def set_notification_level
|
||||
self.notification_level = group&.default_notification_level || 3
|
||||
end
|
||||
|
||||
def set_primary_group
|
||||
if group.primary_group
|
||||
self.class.exec_sql("UPDATE users
|
||||
|
|
|
@ -137,6 +137,7 @@ end
|
|||
# created_at :datetime
|
||||
# updated_at :datetime
|
||||
# compiler_version :integer default(0), not null
|
||||
# error :string
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
|
|
|
@ -6,7 +6,7 @@ end
|
|||
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: warnings
|
||||
# Table name: user_warnings
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# topic_id :integer not null
|
||||
|
@ -17,6 +17,6 @@ end
|
|||
#
|
||||
# Indexes
|
||||
#
|
||||
# index_warnings_on_topic_id (topic_id) UNIQUE
|
||||
# index_warnings_on_user_id (user_id)
|
||||
# index_user_warnings_on_topic_id (topic_id) UNIQUE
|
||||
# index_user_warnings_on_user_id (user_id)
|
||||
#
|
||||
|
|
|
@ -19,7 +19,8 @@ class BasicGroupSerializer < ApplicationSerializer
|
|||
:bio_cooked,
|
||||
:public,
|
||||
:allow_membership_requests,
|
||||
:full_name
|
||||
:full_name,
|
||||
:default_notification_level
|
||||
|
||||
def include_incoming_email?
|
||||
staff?
|
||||
|
|
|
@ -446,6 +446,7 @@ en:
|
|||
posts: "Posts"
|
||||
mentions: "Mentions"
|
||||
messages: "Messages"
|
||||
notification_level: "Default notification level for group messages"
|
||||
alias_levels:
|
||||
title: "Who can message and @mention this group?"
|
||||
nobody: "Nobody"
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
class AddDefaultNotificationLevelToGroup < ActiveRecord::Migration
|
||||
def up
|
||||
add_column :groups, :default_notification_level, :integer, default: 3, null: false
|
||||
# don't auto watch 'moderators' it is just way too loud
|
||||
execute 'UPDATE groups SET default_notification_level = 2 WHERE id = 2'
|
||||
end
|
||||
|
||||
def down
|
||||
remove_column :groups, :default_notification_level
|
||||
end
|
||||
end
|
|
@ -0,0 +1,33 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe GroupUser do
|
||||
|
||||
it 'correctly sets notification level' do
|
||||
moderator = Fabricate(:moderator)
|
||||
|
||||
Group.refresh_automatic_groups!(:moderators)
|
||||
gu = GroupUser.find_by(user_id: moderator.id, group_id: Group::AUTO_GROUPS[:moderators])
|
||||
|
||||
expect(gu.notification_level).to eq(NotificationLevels.all[:tracking])
|
||||
|
||||
group = Group.create!(name: 'bob')
|
||||
group.add(moderator)
|
||||
group.save
|
||||
|
||||
gu = GroupUser.find_by(user_id: moderator.id, group_id: group.id)
|
||||
expect(gu.notification_level).to eq(NotificationLevels.all[:watching])
|
||||
|
||||
group.remove(moderator)
|
||||
group.save
|
||||
|
||||
group.default_notification_level = 1
|
||||
group.save
|
||||
|
||||
group.add(moderator)
|
||||
group.save
|
||||
|
||||
gu = GroupUser.find_by(user_id: moderator.id, group_id: group.id)
|
||||
expect(gu.notification_level).to eq(NotificationLevels.all[:regular])
|
||||
end
|
||||
|
||||
end
|
Loading…
Reference in New Issue