forked from e621ng/e621ng
[Dmails] Add route to mark single dmail read
This commit is contained in:
parent
16014a438f
commit
f477141c63
@ -1,6 +1,6 @@
|
||||
class DmailsController < ApplicationController
|
||||
respond_to :html
|
||||
respond_to :json, only: %i[index show destroy mark_all_as_read]
|
||||
respond_to :json, only: %i[index show destroy mark_as_read mark_all_as_read]
|
||||
before_action :member_only
|
||||
|
||||
def new
|
||||
@ -44,6 +44,12 @@ class DmailsController < ApplicationController
|
||||
redirect_to dmails_path, :notice => "Message destroyed"
|
||||
end
|
||||
|
||||
def mark_as_read
|
||||
@dmail = Dmail.find(params[:id])
|
||||
check_privilege(@dmail)
|
||||
@dmail.mark_as_read!
|
||||
end
|
||||
|
||||
def mark_all_as_read
|
||||
Dmail.visible.unread.each do |x|
|
||||
x.update_column(:is_read, true)
|
||||
|
@ -129,6 +129,9 @@ Rails.application.routes.draw do
|
||||
end
|
||||
end
|
||||
resources :dmails, :only => [:new, :create, :index, :show, :destroy] do
|
||||
member do
|
||||
post :mark_as_read
|
||||
end
|
||||
collection do
|
||||
post :mark_all_as_read
|
||||
end
|
||||
|
@ -71,6 +71,14 @@ class DmailsControllerTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
end
|
||||
|
||||
context "mark as read action" do
|
||||
should "mark the dmail as read" do
|
||||
post_auth mark_as_read_dmail_path(@dmail), @dmail.owner, params: { format: :json }
|
||||
assert_response :success
|
||||
assert_predicate @dmail.reload, :is_read?
|
||||
end
|
||||
end
|
||||
|
||||
context "create action" do
|
||||
setup do
|
||||
@user_2 = create(:user)
|
||||
|
Loading…
Reference in New Issue
Block a user