Skip to content

Commit

Permalink
refactor Page authorization
Browse files Browse the repository at this point in the history
  • Loading branch information
otariidae committed Jun 22, 2021
1 parent 7fd1d38 commit 9b84f9f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
13 changes: 6 additions & 7 deletions app/controllers/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,15 @@ def show_page
parent_pathname = pathname.parent
parent = Page.find_by_pathname(parent_pathname)

if !is_root_path?(pathname)
if parent.nil?
raise ActiveRecord::RecordNotFound
end
authorize! :write, parent
end

title = get_title pathname
@page = Page.new(title: title, parent: parent)

if !is_root_path?(pathname) && @page.parent.nil?
raise ActiveRecord::RecordNotFound
end

authorize! :create, @page

render_pankuzu_list
render_left
render_right
Expand Down
3 changes: 3 additions & 0 deletions app/models/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ def initialize(user)
can :read, Page, readable_group: nil
can :read, Page, readable_group: { id: user.usergroup_ids }
can [:read, :create], Usergroup
can :create, Page, parent: nil, title: "" # root page
can :create, Page, parent: { editable_group: nil }
can :create, Page, parent: { editable_group: { id: user.usergroup_ids } }
can :write, Page, editable_group: nil
can :write, Page, editable_group: { id: user.usergroup_ids }
can :write, Comment, user_id: user.id
Expand Down

0 comments on commit 9b84f9f

Please sign in to comment.