Add metrics for legacy mark unread
closes VICE-2879 flag=none Test Plan: - spces make sense and pass - will be validated post merge Change-Id: I77a40e2fa192d42a1fc3ecb77249801183a1b88c Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/298087 Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com> Reviewed-by: Jason Gillett <jason.gillett@instructure.com> QA-Review: Jason Gillett <jason.gillett@instructure.com> Product-Review: Jason Gillett <jason.gillett@instructure.com>
This commit is contained in:
parent
407ebeeede
commit
43d845029e
|
@ -699,11 +699,12 @@ class ConversationsController < ApplicationController
|
|||
# "participants": [{"id": 1, "name": "Joe", "full_name": "Joe TA"}]
|
||||
# }
|
||||
def update
|
||||
prev_star_state = @conversation.starred
|
||||
prev_conversation_state = @conversation.deep_dup
|
||||
if @conversation.update(params.require(:conversation).permit(*API_ALLOWED_FIELDS))
|
||||
InstStatsd::Statsd.increment("inbox.conversation.archived.legacy") if params.require(:conversation)["workflow_state"] == "archived"
|
||||
InstStatsd::Statsd.increment("inbox.conversation.starred.legacy") if ActiveModel::Type::Boolean.new.cast(params[:conversation][:starred]) && !prev_star_state
|
||||
InstStatsd::Statsd.increment("inbox.conversation.unstarred.legacy") if !ActiveModel::Type::Boolean.new.cast(params[:conversation][:starred]) && prev_star_state
|
||||
InstStatsd::Statsd.increment("inbox.conversation.starred.legacy") if ActiveModel::Type::Boolean.new.cast(params[:conversation][:starred]) && !prev_conversation_state.starred
|
||||
InstStatsd::Statsd.increment("inbox.conversation.unstarred.legacy") if !ActiveModel::Type::Boolean.new.cast(params[:conversation][:starred]) && prev_conversation_state.starred
|
||||
InstStatsd::Statsd.increment("inbox.conversation.unread.legacy") if params.require(:conversation)["workflow_state"] == "unread" && prev_conversation_state.workflow_state == "read"
|
||||
render json: conversation_json(@conversation, @current_user, session)
|
||||
else
|
||||
render json: @conversation.errors, status: :bad_request
|
||||
|
@ -1028,6 +1029,7 @@ class ConversationsController < ApplicationController
|
|||
conversation_count = params[:conversation_ids].length
|
||||
InstStatsd::Statsd.count("inbox.conversation.starred.legacy", conversation_count) if params[:event] == "star"
|
||||
InstStatsd::Statsd.count("inbox.conversation.unstarred.legacy", conversation_count) if params[:event] == "unstar"
|
||||
InstStatsd::Statsd.count("inbox.conversation.unread.legacy", conversation_count) if params[:event] == "mark_as_unread"
|
||||
|
||||
progress = ConversationParticipant.batch_update(@current_user, conversation_ids, update_params)
|
||||
render json: progress_json(progress, @current_user, session)
|
||||
|
|
|
@ -1060,7 +1060,7 @@
|
|||
"check_name": "SQL",
|
||||
"message": "Possible SQL injection",
|
||||
"file": "app/controllers/conversations_controller.rb",
|
||||
"line": 1030,
|
||||
"line": 1031,
|
||||
"link": "https://brakemanscanner.org/docs/warning_types/sql_injection/",
|
||||
"code": "InstStatsd::Statsd.count(\"inbox.conversation.unstarred.legacy\", params[:conversation_ids].length)",
|
||||
"render_path": null,
|
||||
|
@ -1452,7 +1452,7 @@
|
|||
"check_name": "SQL",
|
||||
"message": "Possible SQL injection",
|
||||
"file": "app/controllers/conversations_controller.rb",
|
||||
"line": 1029,
|
||||
"line": 1030,
|
||||
"link": "https://brakemanscanner.org/docs/warning_types/sql_injection/",
|
||||
"code": "InstStatsd::Statsd.count(\"inbox.conversation.starred.legacy\", params[:conversation_ids].length)",
|
||||
"render_path": null,
|
||||
|
@ -1517,6 +1517,26 @@
|
|||
"confidence": "Medium",
|
||||
"note": ""
|
||||
},
|
||||
{
|
||||
"warning_type": "SQL Injection",
|
||||
"warning_code": 0,
|
||||
"fingerprint": "ded9e82288e144d1d531650c2d385aa95a6e3688d4d3ca04757c2c3a61db4119",
|
||||
"check_name": "SQL",
|
||||
"message": "Possible SQL injection",
|
||||
"file": "app/controllers/conversations_controller.rb",
|
||||
"line": 1032,
|
||||
"link": "https://brakemanscanner.org/docs/warning_types/sql_injection/",
|
||||
"code": "InstStatsd::Statsd.count(\"inbox.conversation.unread.legacy\", params[:conversation_ids].length)",
|
||||
"render_path": null,
|
||||
"location": {
|
||||
"type": "method",
|
||||
"class": "ConversationsController",
|
||||
"method": "batch_update"
|
||||
},
|
||||
"user_input": "params[:conversation_ids].length",
|
||||
"confidence": "Medium",
|
||||
"note": ""
|
||||
},
|
||||
{
|
||||
"warning_type": "SQL Injection",
|
||||
"warning_code": 0,
|
||||
|
@ -1698,6 +1718,6 @@
|
|||
"note": ""
|
||||
}
|
||||
],
|
||||
"updated": "2022-08-04 16:39:33 -0600",
|
||||
"updated": "2022-08-08 14:54:55 -0600",
|
||||
"brakeman_version": "5.2.3"
|
||||
}
|
||||
|
|
|
@ -642,7 +642,7 @@ describe ConversationsController do
|
|||
end
|
||||
|
||||
describe "POST 'update'" do
|
||||
it "updates the conversation" do
|
||||
it "updates the conversation to be archived and starred" do
|
||||
course_with_student_logged_in(active_all: true)
|
||||
conversation(num_other_users: 2).update_attribute(:workflow_state, "unread")
|
||||
|
||||
|
@ -657,6 +657,11 @@ describe ConversationsController do
|
|||
expect(InstStatsd::Statsd).to have_received(:increment).with("inbox.conversation.archived.legacy")
|
||||
expect(InstStatsd::Statsd).to have_received(:increment).with("inbox.conversation.starred.legacy")
|
||||
expect(InstStatsd::Statsd).not_to have_received(:increment).with("inbox.conversation.archived.react")
|
||||
end
|
||||
|
||||
it "updates the conversation to be unstarred" do
|
||||
course_with_student_logged_in(active_all: true)
|
||||
conversation(num_other_users: 2).update(starred: true)
|
||||
|
||||
post "update", params: { id: @conversation.conversation_id, conversation: { starred: false } }
|
||||
expect(response).to be_successful
|
||||
|
@ -664,6 +669,17 @@ describe ConversationsController do
|
|||
expect(@conversation.starred).to be_falsey
|
||||
expect(InstStatsd::Statsd).to have_received(:increment).with("inbox.conversation.unstarred.legacy")
|
||||
end
|
||||
|
||||
it "updates the conversation to be unread" do
|
||||
course_with_student_logged_in(active_all: true)
|
||||
conversation(num_other_users: 2).update(workflow_state: "read")
|
||||
|
||||
post "update", params: { id: @conversation.conversation_id, conversation: { workflow_state: "unread" } }
|
||||
expect(response).to be_successful
|
||||
@conversation.reload
|
||||
expect(@conversation.starred).to be_falsey
|
||||
expect(InstStatsd::Statsd).to have_received(:increment).with("inbox.conversation.unread.legacy")
|
||||
end
|
||||
end
|
||||
|
||||
describe "PUT 'batch_update'" do
|
||||
|
@ -686,6 +702,16 @@ describe ConversationsController do
|
|||
|
||||
expect(InstStatsd::Statsd).to have_received(:count).with("inbox.conversation.unstarred.legacy", 1).once
|
||||
end
|
||||
|
||||
it "calls batch update with unread event" do
|
||||
course_with_student_logged_in(active_all: true)
|
||||
conversation(num_other_users: 2).update_attribute(:workflow_state, "read")
|
||||
|
||||
allow(InstStatsd::Statsd).to receive(:count)
|
||||
put "batch_update", params: { conversation_ids: [@conversation.id], event: "mark_as_unread" }
|
||||
|
||||
expect(InstStatsd::Statsd).to have_received(:count).with("inbox.conversation.unread.legacy", 1).once
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST 'add_message'" do
|
||||
|
|
Loading…
Reference in New Issue