DEV: Assign allowed groups are sent alongside suggestions. After the migration happens, we'll need to still have access to the allowed group names so we can search users.

This commit is contained in:
romanrizzi 2019-07-19 14:45:28 -03:00
parent 64324ce9db
commit 8792cf51bd
5 changed files with 14 additions and 19 deletions

View File

@ -23,8 +23,10 @@ module DiscourseAssign
.order('X.last_assigned DESC')
.limit(6)
render json: ActiveModel::ArraySerializer.new(users,
scope: guardian, each_serializer: BasicUserSerializer)
render json: {
assign_allowed_on_groups: Group.assign_allowed_groups.pluck(:name),
suggestions: ActiveModel::ArraySerializer.new(users, scope: guardian, each_serializer: BasicUserSerializer)
}
end
def claim

View File

@ -3,14 +3,16 @@ import { popupAjaxError } from "discourse/lib/ajax-error";
export default Ember.Controller.extend({
assignSuggestions: null,
allowedGroups: [],
taskActions: Ember.inject.service(),
init() {
this._super(...arguments);
ajax("/assign/suggestions").then(users =>
this.set("assignSuggestions", users)
);
ajax("/assign/suggestions").then(data => {
this.set("assignSuggestions", data.suggestions);
this.set("allowedGroups", data.assign_allowed_on_groups);
});
},
onClose() {

View File

@ -3,14 +3,6 @@ import showModal from "discourse/lib/show-modal";
import { getOwner } from "discourse-common/lib/get-owner";
export default Ember.Service.extend({
init() {
this._super(...arguments);
this.allowedGroups = getOwner(this)
.lookup("site-settings:main")
.assign_allowed_on_groups.split("|");
},
unassign(topicId) {
return ajax("/assign/unassign", {
type: "PUT",
@ -22,8 +14,7 @@ export default Ember.Service.extend({
return showModal("assign-user", {
model: {
topic,
username: topic.get("assigned_to_user.username"),
allowedGroups: this.allowedGroups
username: topic.get("assigned_to_user.username")
}
});
}

View File

@ -4,7 +4,7 @@
single=true
allowAny=false
group="staff"
groupMembersOf=model.allowedGroups
groupMembersOf=allowedGroups
excludeCurrentUser=false
includeMentionableGroups=false
hasGroups=false

View File

@ -48,7 +48,7 @@ RSpec.describe DiscourseAssign::AssignController do
TopicAssigner.new(post.topic, user).assign(user2)
get '/assign/suggestions.json'
suggestions = JSON.parse(response.body).map { |u| u['username'] }
suggestions = JSON.parse(response.body)['suggestions'].map { |u| u['username'] }
expect(suggestions).to contain_exactly(user2.username, user.username)
end
@ -60,7 +60,7 @@ RSpec.describe DiscourseAssign::AssignController do
TopicAssigner.new(post.topic, user).assign(user2)
get '/assign/suggestions.json'
suggestions = JSON.parse(response.body).map { |u| u['username'] }
suggestions = JSON.parse(response.body)['suggestions'].map { |u| u['username'] }
expect(suggestions).to contain_exactly(user.username)
end
@ -78,7 +78,7 @@ RSpec.describe DiscourseAssign::AssignController do
TopicAssigner.new(post.topic, user).assign(another_admin)
get '/assign/suggestions.json'
suggestions = JSON.parse(response.body).map { |u| u['username'] }
suggestions = JSON.parse(response.body)['suggestions'].map { |u| u['username'] }
expect(suggestions).to contain_exactly(user.username)
end