* Create DiscussionLocks
* Fix specs
* Update nullify_blank_notes_and_reason
* Update before_validation call
* Updated DiscussionLockPolicy for clarity
* Move permitted_attributes to a constant
* Update route
* Apply suggestions from code review for frontend
Co-authored-by: Suzanne Aitchison <suzanne@forem.com>
* Add title tags
* Wrap unlock confirm in main element
* Wrap flash messages up in div
* Actually fix title tags
* Hide comment reply button when discussion is locked
* Add E2E tests
* Try to fix E2E tests
* Cypress...you work locally but not in CI...why!?
* PR feedback
* Update E2E tests
* More E2E updates 😭
Co-authored-by: Suzanne Aitchison <suzanne@forem.com>
49 lines
1.2 KiB
Ruby
49 lines
1.2 KiB
Ruby
class DiscussionLocksController < ApplicationController
|
|
before_action :authenticate_user!
|
|
|
|
DISCUSSION_LOCK_PARAMS = %i[article_id notes reason].freeze
|
|
|
|
def create
|
|
@discussion_lock = DiscussionLock.new(discussion_lock_params)
|
|
|
|
authorize @discussion_lock
|
|
article = Article.find(discussion_lock_params[:article_id])
|
|
|
|
if @discussion_lock.save
|
|
bust_article_cache(article)
|
|
|
|
flash[:success] = "Discussion was successfully locked!"
|
|
else
|
|
flash[:error] = "Error: #{@discussion_lock.errors_as_sentence}"
|
|
end
|
|
|
|
redirect_to "#{article.path}/manage"
|
|
end
|
|
|
|
def destroy
|
|
discussion_lock = DiscussionLock.find(params[:id])
|
|
|
|
authorize discussion_lock
|
|
article = discussion_lock.article
|
|
|
|
if discussion_lock.destroy
|
|
bust_article_cache(article)
|
|
|
|
flash[:success] = "Discussion was successfully unlocked!"
|
|
else
|
|
flash[:error] = "Error: #{discussion_lock.errors_as_sentence}"
|
|
end
|
|
|
|
redirect_to "#{article.path}/manage"
|
|
end
|
|
|
|
private
|
|
|
|
def discussion_lock_params
|
|
params.require(:discussion_lock).permit(DISCUSSION_LOCK_PARAMS).merge(locking_user_id: current_user.id)
|
|
end
|
|
|
|
def bust_article_cache(article)
|
|
EdgeCache::BustArticle.call(article)
|
|
end
|
|
end
|