-
Notifications
You must be signed in to change notification settings - Fork 35
DRAFT: Add priorities to assignment #317
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,18 @@ | ||
import Controller, { inject as controller } from "@ember/controller"; | ||
import { action } from "@ember/object"; | ||
import { not, or } from "@ember/object/computed"; | ||
import { inject as service } from "@ember/service"; | ||
import { isEmpty } from "@ember/utils"; | ||
import { ajax } from "discourse/lib/ajax"; | ||
import { popupAjaxError } from "discourse/lib/ajax-error"; | ||
import { not, or } from "@ember/object/computed"; | ||
import { isEmpty } from "@ember/utils"; | ||
import { action } from "@ember/object"; | ||
import I18n from "I18n"; | ||
|
||
const PRIORITIES = [ | ||
{ name: I18n.t("discourse_assign.priorities.low"), value: 4 }, | ||
{ name: I18n.t("discourse_assign.priorities.medium"), value: 3 }, | ||
{ name: I18n.t("discourse_assign.priorities.high"), value: 2 }, | ||
{ name: I18n.t("discourse_assign.priorities.urgent"), value: 1 }, | ||
]; | ||
|
||
export default Controller.extend({ | ||
topicBulkActions: controller(), | ||
|
@@ -13,6 +21,7 @@ export default Controller.extend({ | |
taskActions: service(), | ||
autofocus: not("capabilities.touch"), | ||
assigneeName: or("model.username", "model.group_name"), | ||
priorities: PRIORITIES, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you should set this in init, and have it as |
||
|
||
init() { | ||
this._super(...arguments); | ||
|
@@ -63,14 +72,14 @@ export default Controller.extend({ | |
} | ||
|
||
this.send("closeModal"); | ||
|
||
return ajax(path, { | ||
type: "PUT", | ||
data: { | ||
username: this.get("model.username"), | ||
group_name: this.get("model.group_name"), | ||
target_id: this.get("model.target.id"), | ||
target_type: this.get("model.targetType"), | ||
priority: this.get("model.priority"), | ||
}, | ||
}) | ||
.then(() => { | ||
|
@@ -99,14 +108,15 @@ export default Controller.extend({ | |
"model.allowedGroups": this.taskActions.allowedGroups, | ||
}); | ||
} | ||
|
||
if (name) { | ||
return this.assign(); | ||
} | ||
}, | ||
|
||
@action | ||
assignUsername(selected) { | ||
this.assignUser(selected.firstObject); | ||
}, | ||
|
||
@action | ||
assignPriority(priority) { | ||
this.set("model.priority", priority); | ||
}, | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
class AddPriorityToAssignments < ActiveRecord::Migration[6.1] | ||
def change | ||
add_column :assignments, :priority, :integer, null: true | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
require_relative '../support/assign_allowed_group' | ||
|
||
RSpec.describe DiscourseAssign::AssignController do | ||
|
@@ -116,6 +115,15 @@ | |
expect(post.topic.reload.assignment.assigned_to_id).to eq(user2.id) | ||
end | ||
|
||
it 'assigns topic with priority to a user' do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we also add a test case which passes in an invalid priority like a random string or an invalid number? My hunch is that this is not handled right now and might result in us writing invalid values into the DB. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The activerecord actually is smart about it because of the enums declared. Let me see if I can get you an error... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
🪄 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do not think we have any special rescues for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Your concern that we're writing invalid values to the DB is addressed... But for this one where it results in 500, I'm not sure if we have to care: the only consumer for this endpoint is our frontend, and the frontend only ever passes 1-4. I'd like to avoid testing the framework if possible since this is a built-in enum feature. |
||
put '/assign/assign.json', params: { | ||
target_id: post.topic_id, target_type: 'Topic', username: user2.username, priority: 4 | ||
} | ||
|
||
topicPriority = post.topic.reload.assignment.priority | ||
expect(Assignment.priorities[topicPriority]).to eq(4) | ||
end | ||
|
||
it 'assigns topic to a group' do | ||
put '/assign/assign.json', params: { | ||
target_id: post.topic_id, target_type: 'Topic', group_name: assign_allowed_group.name | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative '../support/assign_allowed_group' | ||
|
||
RSpec.describe TopicViewSerializer do | ||
fab!(:user) { Fabricate(:user) } | ||
fab!(:topic) { Fabricate(:topic) } | ||
fab!(:post) { Fabricate(:post, topic: topic) } | ||
let(:guardian) { Guardian.new(user) } | ||
|
||
include_context 'A group that is allowed to assign' | ||
|
||
before do | ||
SiteSetting.assign_enabled = true | ||
add_to_assign_allowed_group(user) | ||
end | ||
|
||
it "includes assigned user in serializer" do | ||
Assigner.new(topic, user).assign(user) | ||
serializer = TopicViewSerializer.new(TopicView.new(topic), scope: guardian) | ||
expect(serializer.as_json[:topic_view][:assigned_to_user][:username]).to eq(user.username) | ||
expect(serializer.as_json[:topic_view][:assigned_to_group]).to be nil | ||
end | ||
|
||
it "includes assigned group in serializer" do | ||
Assigner.new(topic, user).assign(assign_allowed_group) | ||
serializer = TopicViewSerializer.new(TopicView.new(topic), scope: guardian) | ||
expect(serializer.as_json[:topic_view][:assigned_to_group][:name]).to eq(assign_allowed_group.name) | ||
expect(serializer.as_json[:topic_view][:assigned_to_user]).to be nil | ||
end | ||
|
||
it "includes priority in serializer" do | ||
Assigner.new(topic, user).assign(user, priority: 1) | ||
serializer = TopicViewSerializer.new(TopicView.new(topic), scope: guardian) | ||
expect(serializer.as_json[:topic_view][:assignment_priority]).to eq(1) | ||
end | ||
end |
Uh oh!
There was an error while loading. Please reload this page.