This instance will be upgraded to Heptapod 0.31.0 (final) on 2022-05-24 at 14:00 UTC+2 (a few minutes of down time)

Commit 5bf49bb6 authored by Felipe Artur's avatar Felipe Artur
Browse files

Move note helper method to notes entity file

parent 07cdfdb3a8c2
...@@ -397,9 +397,5 @@ def handle_member_errors(errors) ...@@ -397,9 +397,5 @@ def handle_member_errors(errors)
error!(errors[:access_level], 422) if errors[:access_level].any? error!(errors[:access_level], 422) if errors[:access_level].any?
not_found!(errors) not_found!(errors)
end end
def noteable_ability_name(noteable)
"read_#{noteable.class.to_s.underscore.downcase}".to_sym
end
end end
end end
...@@ -21,7 +21,7 @@ class Notes < Grape::API ...@@ -21,7 +21,7 @@ class Notes < Grape::API
get ":id/#{noteables_str}/:#{noteable_id_str}/notes" do get ":id/#{noteables_str}/:#{noteable_id_str}/notes" do
@noteable = user_project.send(noteables_str.to_sym).find(params[noteable_id_str.to_sym]) @noteable = user_project.send(noteables_str.to_sym).find(params[noteable_id_str.to_sym])
if can?(current_user, noteable_ability_name(@noteable), @noteable) if can?(current_user, noteable_read_ability_name(@noteable), @noteable)
# We exclude notes that are cross-references and that cannot be viewed # We exclude notes that are cross-references and that cannot be viewed
# by the current user. By doing this exclusion at this level and not # by the current user. By doing this exclusion at this level and not
# at the DB query level (which we cannot in that case), the current # at the DB query level (which we cannot in that case), the current
...@@ -51,7 +51,7 @@ class Notes < Grape::API ...@@ -51,7 +51,7 @@ class Notes < Grape::API
get ":id/#{noteables_str}/:#{noteable_id_str}/notes/:note_id" do get ":id/#{noteables_str}/:#{noteable_id_str}/notes/:note_id" do
@noteable = user_project.send(noteables_str.to_sym).find(params[noteable_id_str.to_sym]) @noteable = user_project.send(noteables_str.to_sym).find(params[noteable_id_str.to_sym])
@note = @noteable.notes.find(params[:note_id]) @note = @noteable.notes.find(params[:note_id])
can_read_note = can?(current_user, noteable_ability_name(@noteable), @noteable) && !@note.cross_reference_not_visible_for?(current_user) can_read_note = can?(current_user, noteable_read_ability_name(@noteable), @noteable) && !@note.cross_reference_not_visible_for?(current_user)
if can_read_note if can_read_note
present @note, with: Entities::Note present @note, with: Entities::Note
...@@ -141,5 +141,11 @@ class Notes < Grape::API ...@@ -141,5 +141,11 @@ class Notes < Grape::API
end end
end end
end end
helpers do
def noteable_read_ability_name(noteable)
"read_#{noteable.class.to_s.underscore.downcase}".to_sym
end
end
end end
end end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment