Authorisation management using CanCanCan added

This commit is contained in:
Christoph Haas 2021-02-28 21:36:46 +01:00
parent 51be4a4777
commit 7a3b65fe50
24 changed files with 211 additions and 295 deletions

View file

@ -15,6 +15,3 @@
/ ' | Cookie is #{session[:token]}
= render 'cookies_eu/consent_banner', link: '/about#cookies'
/ = current_user.is_admin?
/ = session.id

View file

@ -31,12 +31,6 @@
a.button.alert.round href=delete_screenshot_path(screenshot) onclick="return confirm('Really delete the screenshot?');" Reject
a.button.success.round href=approve_screenshot_path(screenshot) Approve
/ Existing screenshots that was requested for removal
- if screenshot.markedfordelete==true
.button-group
a.button.alert.round href=delete_screenshot_path(screenshot) onclick="return confirm('Really delete the screenshot?');" Remove as requested
a.button.success.round href=approve_screenshot_path(screenshot) Keep the screenshot
.small-6.cell
p Existing screenshots:

View file

@ -7,11 +7,11 @@
= link_to moderate_list_path
= fa_icon 'check 2x', text: 'Moderate'
// Add link if user has uploaded screenshots
- if @current_users_screenshots and @current_users_screenshots.any?
li class=('active' if controller_name=='my' and action_name=='uploads')
= link_to my_uploads_path
= fa_icon 'image 2x', text: 'My uploads'
' My uploads
/ - if @current_users_screenshots and @current_users_screenshots.any?
/ li class=('active' if controller_name=='my' and action_name=='uploads')
/ = link_to my_uploads_path
/ = fa_icon 'image 2x', text: 'My uploads'
/ ' My uploads
li
= link_to destroy_user_session_path, method: :delete

View file

@ -27,8 +27,8 @@
h2 Number of screenshots you uploaded
p = current_user.screenshots.count
- if current_user.is_admin?
h2 Admin
p Apparently you are an administrator. Be careful with that thing!
tt = current_user.inspect
/ - if current_user.is_admin?
/ h2 Admin
/ p Apparently you are an administrator. Be careful with that thing!
/ - you can moderate
/ - you can …

View file

@ -16,8 +16,8 @@
- @current_users_screenshots.each do |screenshot|
.column
/ TODO: old Paperclip style
a.black.fancybox href=screenshot.image.variant(resize_to_limit: [800,600], timestamp: false)
a.black.fancybox href=screenshot.simage_url(:large)
div.grid-thumbnail
= image_tag(screenshot.image.variant(resize_to_limit: [160,120]), alt: screenshot.caption, class: 'thumbnail')
= image_tag(screenshot.simage_url(:medium), alt: screenshot.caption, class: 'thumbnail')
div
= screenshot.description

View file

@ -1,7 +1,13 @@
// Button that reveals a dropdown/modal for moderation/reporting
- if can?(:destroy, screenshot) || can?(:approve, screenshot)
.text
span.label.secondary
= status_text(screenshot)
.button-group.small.align-center
- if (screenshot_uploaded_by_current_user?(screenshot) || (current_user && current_user.is_admin?))
- if can?(:destroy, screenshot)
a.button.small.bordered.radius.alert[
href=delete_screenshot_path(screenshot.id)
onclick="return confirm('Really delete the screenshot?');"
@ -15,29 +21,15 @@
/ href='#'
/ ] #{fa_icon 'star'} Make primary
- if not screenshot.approved
- if current_user && current_user.is_admin?
- unless screenshot.approved
- if can?(:approve, screenshot)
a.button.small.success[
href=approve_screenshot_path(screenshot.id)
method='post'
] Approve
/ - elsif screenshot.markedfordelete
/ a.button.small.success[
/ href=approve_screenshot_path(screenshot.id)
/ method='post'
/ ] Keep
] #{fa_icon 'check'} Approve
/ Display additional information to admins
p Status: #{screenshot.adminstatus}
p Uploader IP=#{screenshot.uploaderip}
p Uploader Token=#{session[:token]}
p Uploaded #{screenshot.age} ago (#{screenshot.created_at})
/ TODO: Move reporting screenshots to an extra page with a form and captcha
/ - else
/ / Allow anonymous users to report inappropriate screenshots
/ = form_tag(report_screenshot_path(screenshot.id))
/ = text_area_tag 'delete_reason', nil, class: 'input-group-field', maxlength: 100, rows: 3, cols: 50
/ = submit_tag 'Request removal', class: 'button alert'
/ p Status: #{screenshot.adminstatus}
/ p Uploader IP=#{screenshot.uploaderip}
/ p Uploader Token=#{session[:token]}
/ p Uploaded #{time_ago_in_words(screenshot.created_at)} ago (#{screenshot.created_at})

View file

@ -1,12 +0,0 @@
// Button that reveals a dropdown/modal for users (for their own screenshots)
.text-right
button.small.dropdown.warning.button type="button" data-toggle="admin-info-#{screenshot.id}"
'Request removal
.dropdown-pane data-dropdown=true id="admin-info-#{screenshot.id}"
p If you think this screenshot does not meet the guidelines
or is misleading or not useful then please report it so that
the moderators can review it. Just let us know why you think
the screenshot should get removed:
= form_tag(report_screenshot_path(screenshot.id))
= text_area_tag 'delete_reason', nil, class: 'input-group-field', maxlength: 100, rows: 3, cols: 50
= submit_tag 'Request removal', class: 'button alert'

View file

@ -25,24 +25,13 @@
.text
= screenshot.caption
// Has the unmoderated screenshot been uploaded by the current user?
- if screenshot_uploaded_by_current_user?(screenshot)
- if current_user.screenshots.include?(screenshot)
.text
span.label.secondary
' Uploaded by you
- unless screenshot.approved
' (needs to be approved)
= render(partial: 'admin_buttons', locals: {screenshot: screenshot})
// Is the user an admin?
// or does the screenshot belong to the user (determined by session cookie)
- if current_user && current_user.is_admin?
hr
.text
span.label.secondary
= status_text(screenshot)
= render(partial: 'admin_buttons', locals: {screenshot: screenshot})
/ - elsif user_signed_in? and screenshot.user == current_user
/ = render(partial: 'user_dropdown', locals: {screenshot: screenshot})
= render(partial: 'admin_buttons', locals: {screenshot: screenshot})
// Second paginator at the bottom so the user does not have to scroll up again