mirror of
https://github.com/discourse/discourse.git
synced 2025-04-09 10:10:49 +08:00
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(),
|
}.property(),
|
||||||
|
|
||||||
@computed('model.visible', 'model.public', 'model.alias_level')
|
@computed('model.visible', 'model.public')
|
||||||
disableMembershipRequestSetting(visible, publicGroup) {
|
disableMembershipRequestSetting(visible, publicGroup) {
|
||||||
return !visible || publicGroup || !this.get('model.canEveryoneMention');
|
return !visible || publicGroup;
|
||||||
},
|
},
|
||||||
|
|
||||||
@computed('model.visible', 'model.allow_membership_requests')
|
@computed('model.visible', 'model.allow_membership_requests')
|
||||||
|
@ -83,6 +83,12 @@
|
|||||||
{{combo-box name="alias" valueAttribute="value" value=model.alias_level content=aliasLevelOptions}}
|
{{combo-box name="alias" valueAttribute="value" value=model.alias_level content=aliasLevelOptions}}
|
||||||
</div>
|
</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}}
|
{{#unless model.automatic}}
|
||||||
<div>
|
<div>
|
||||||
<label for="automatic_membership">{{i18n 'admin.groups.automatic_membership_email_domains'}}</label>
|
<label for="automatic_membership">{{i18n 'admin.groups.automatic_membership_email_domains'}}</label>
|
||||||
|
@ -6,6 +6,6 @@ export default NotificationsButton.extend({
|
|||||||
i18nPrefix: 'groups.notifications',
|
i18nPrefix: 'groups.notifications',
|
||||||
|
|
||||||
clicked(id) {
|
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 */) {
|
clicked(id) {
|
||||||
// sub-class needs to implement this
|
this.set("notificationLevel", id);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -139,7 +139,8 @@ const Group = RestModel.extend({
|
|||||||
bio_raw: this.get('bio_raw'),
|
bio_raw: this.get('bio_raw'),
|
||||||
public: this.get('public'),
|
public: this.get('public'),
|
||||||
allow_membership_requests: this.get('allow_membership_requests'),
|
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);
|
this.set("group_user.notification_level", notification_level);
|
||||||
return ajax(`/groups/${this.get("name")}/notifications`, {
|
return ajax(`/groups/${this.get("name")}/notifications`, {
|
||||||
data: { notification_level },
|
data: { notification_level, user_id: userId },
|
||||||
type: "POST"
|
type: "POST"
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -73,7 +73,7 @@
|
|||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
{{#if isGroup}}
|
{{#if isGroup}}
|
||||||
{{group-notifications-button group=group}}
|
{{group-notifications-button group=group user=model}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -71,6 +71,10 @@ class Admin::GroupsController < Admin::AdminController
|
|||||||
group.bio_raw = group_params[:bio_raw] if group_params[:bio_raw]
|
group.bio_raw = group_params[:bio_raw] if group_params[:bio_raw]
|
||||||
group.full_name = group_params[:full_name] if group_params[:full_name]
|
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]
|
if group_params[:allow_membership_requests]
|
||||||
group.allow_membership_requests = group_params[:allow_membership_requests]
|
group.allow_membership_requests = group_params[:allow_membership_requests]
|
||||||
end
|
end
|
||||||
@ -150,7 +154,8 @@ class Admin::GroupsController < Admin::AdminController
|
|||||||
:name, :alias_level, :visible, :automatic_membership_email_domains,
|
:name, :alias_level, :visible, :automatic_membership_email_domains,
|
||||||
:automatic_membership_retroactive, :title, :primary_group,
|
:automatic_membership_retroactive, :title, :primary_group,
|
||||||
:grant_trust_level, :incoming_email, :flair_url, :flair_bg_color,
|
: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
|
||||||
end
|
end
|
||||||
|
@ -245,8 +245,13 @@ class GroupsController < ApplicationController
|
|||||||
group = find_group(:id)
|
group = find_group(:id)
|
||||||
notification_level = params.require(:notification_level)
|
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)
|
GroupUser.where(group_id: group.id)
|
||||||
.where(user_id: current_user.id)
|
.where(user_id: user_id)
|
||||||
.update_all(notification_level: notification_level)
|
.update_all(notification_level: notification_level)
|
||||||
|
|
||||||
render json: success_json
|
render json: success_json
|
||||||
|
@ -194,4 +194,5 @@ end
|
|||||||
# updated_at :datetime not null
|
# updated_at :datetime not null
|
||||||
# via_wizard :boolean default(FALSE), not null
|
# via_wizard :boolean default(FALSE), not null
|
||||||
# base_scheme_id :string
|
# base_scheme_id :string
|
||||||
|
# theme_id :integer
|
||||||
#
|
#
|
||||||
|
@ -552,6 +552,7 @@ end
|
|||||||
# public :boolean default(FALSE), not null
|
# public :boolean default(FALSE), not null
|
||||||
# allow_membership_requests :boolean default(FALSE), not null
|
# allow_membership_requests :boolean default(FALSE), not null
|
||||||
# full_name :string
|
# full_name :string
|
||||||
|
# default_notification_level :integer default(3), not null
|
||||||
#
|
#
|
||||||
# Indexes
|
# Indexes
|
||||||
#
|
#
|
||||||
|
@ -10,6 +10,7 @@ class GroupUser < ActiveRecord::Base
|
|||||||
after_save :set_primary_group
|
after_save :set_primary_group
|
||||||
after_destroy :remove_primary_group
|
after_destroy :remove_primary_group
|
||||||
|
|
||||||
|
before_create :set_notification_level
|
||||||
after_save :grant_trust_level
|
after_save :grant_trust_level
|
||||||
|
|
||||||
def self.notification_levels
|
def self.notification_levels
|
||||||
@ -18,6 +19,10 @@ class GroupUser < ActiveRecord::Base
|
|||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
|
def set_notification_level
|
||||||
|
self.notification_level = group&.default_notification_level || 3
|
||||||
|
end
|
||||||
|
|
||||||
def set_primary_group
|
def set_primary_group
|
||||||
if group.primary_group
|
if group.primary_group
|
||||||
self.class.exec_sql("UPDATE users
|
self.class.exec_sql("UPDATE users
|
||||||
|
@ -137,6 +137,7 @@ end
|
|||||||
# created_at :datetime
|
# created_at :datetime
|
||||||
# updated_at :datetime
|
# updated_at :datetime
|
||||||
# compiler_version :integer default(0), not null
|
# compiler_version :integer default(0), not null
|
||||||
|
# error :string
|
||||||
#
|
#
|
||||||
# Indexes
|
# Indexes
|
||||||
#
|
#
|
||||||
|
@ -6,7 +6,7 @@ end
|
|||||||
|
|
||||||
# == Schema Information
|
# == Schema Information
|
||||||
#
|
#
|
||||||
# Table name: warnings
|
# Table name: user_warnings
|
||||||
#
|
#
|
||||||
# id :integer not null, primary key
|
# id :integer not null, primary key
|
||||||
# topic_id :integer not null
|
# topic_id :integer not null
|
||||||
@ -17,6 +17,6 @@ end
|
|||||||
#
|
#
|
||||||
# Indexes
|
# Indexes
|
||||||
#
|
#
|
||||||
# index_warnings_on_topic_id (topic_id) UNIQUE
|
# index_user_warnings_on_topic_id (topic_id) UNIQUE
|
||||||
# index_warnings_on_user_id (user_id)
|
# index_user_warnings_on_user_id (user_id)
|
||||||
#
|
#
|
||||||
|
@ -19,7 +19,8 @@ class BasicGroupSerializer < ApplicationSerializer
|
|||||||
:bio_cooked,
|
:bio_cooked,
|
||||||
:public,
|
:public,
|
||||||
:allow_membership_requests,
|
:allow_membership_requests,
|
||||||
:full_name
|
:full_name,
|
||||||
|
:default_notification_level
|
||||||
|
|
||||||
def include_incoming_email?
|
def include_incoming_email?
|
||||||
staff?
|
staff?
|
||||||
|
@ -446,6 +446,7 @@ en:
|
|||||||
posts: "Posts"
|
posts: "Posts"
|
||||||
mentions: "Mentions"
|
mentions: "Mentions"
|
||||||
messages: "Messages"
|
messages: "Messages"
|
||||||
|
notification_level: "Default notification level for group messages"
|
||||||
alias_levels:
|
alias_levels:
|
||||||
title: "Who can message and @mention this group?"
|
title: "Who can message and @mention this group?"
|
||||||
nobody: "Nobody"
|
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
|
33
spec/models/group_user_spec.rb
Normal file
33
spec/models/group_user_spec.rb
Normal file
@ -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…
x
Reference in New Issue
Block a user