mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 06:57:53 +08:00
Refactors PostsController and adds unit tests.
This commit is contained in:
@ -64,7 +64,7 @@ class PostsController < ApplicationController
|
||||
post = post.first
|
||||
post.image_sizes = params[:image_sizes] if params[:image_sizes].present?
|
||||
|
||||
if !guardian.can_edit?(post) && post.user_id == current_user.id && post.edit_time_limit_expired?
|
||||
if too_late_to(:edit, post)
|
||||
render json: {errors: [I18n.t('too_late_to_edit')]}, status: 422
|
||||
return
|
||||
end
|
||||
@ -134,7 +134,7 @@ class PostsController < ApplicationController
|
||||
def destroy
|
||||
post = find_post_from_params
|
||||
|
||||
if !guardian.can_delete_post?(post) && post.user_id == current_user.id && post.edit_time_limit_expired?
|
||||
if too_late_to(:delete_post, post)
|
||||
render json: {errors: [I18n.t('too_late_to_edit')]}, status: 422
|
||||
return
|
||||
end
|
||||
@ -269,4 +269,8 @@ class PostsController < ApplicationController
|
||||
end
|
||||
end
|
||||
|
||||
def too_late_to(action, post)
|
||||
!guardian.send("can_#{action}?", post) && post.user_id == current_user.id && post.edit_time_limit_expired?
|
||||
end
|
||||
|
||||
end
|
||||
|
Reference in New Issue
Block a user