]> git.openstreetmap.org Git - rails.git/commitdiff
Move issues and reports to authorization system
authorAndy Allan <git@gravitystorm.co.uk>
Wed, 10 Oct 2018 14:34:44 +0000 (16:34 +0200)
committerAndy Allan <git@gravitystorm.co.uk>
Wed, 10 Oct 2018 14:34:44 +0000 (16:34 +0200)
app/controllers/issue_comments_controller.rb
app/controllers/issues_controller.rb
app/controllers/reports_controller.rb
app/models/ability.rb

index 8d1acec759699d511058061152f5fcd966dad15c..0e4a7079e0e4c5e27608bf344767d529a4349e1f 100644 (file)
@@ -3,8 +3,8 @@ class IssueCommentsController < ApplicationController
 
   before_action :authorize_web
   before_action :set_locale
-  before_action :require_user
-  before_action :check_permission
+
+  authorize_resource
 
   def create
     @issue = Issue.find(params[:issue_id])
@@ -22,10 +22,12 @@ class IssueCommentsController < ApplicationController
     params.require(:issue_comment).permit(:body)
   end
 
-  def check_permission
-    unless current_user.administrator? || current_user.moderator?
+  def deny_access(_exception)
+    if current_user
       flash[:error] = t("application.require_moderator_or_admin.not_a_moderator_or_admin")
       redirect_to root_path
+    else
+      super
     end
   end
 
index ad38454f0650ba62ebd2dae40c1ab383c462c12a..8943f2d4aca695bd0ec2c6766586a70ffae95de1 100644 (file)
@@ -3,8 +3,9 @@ class IssuesController < ApplicationController
 
   before_action :authorize_web
   before_action :set_locale
-  before_action :require_user
-  before_action :check_permission
+
+  authorize_resource
+
   before_action :find_issue, :only => [:show, :resolve, :reopen, :ignore]
 
   def index
@@ -82,10 +83,12 @@ class IssuesController < ApplicationController
     @issue = Issue.find(params[:id])
   end
 
-  def check_permission
-    unless current_user.administrator? || current_user.moderator?
+  def deny_access(_exception)
+    if current_user
       flash[:error] = t("application.require_moderator_or_admin.not_a_moderator_or_admin")
       redirect_to root_path
+    else
+      super
     end
   end
 end
index ef87a8699fe807884ec29d09d65a1064bf49a2fa..8087268193d9159932826415b33f9e31a05b131c 100644 (file)
@@ -3,7 +3,8 @@ class ReportsController < ApplicationController
 
   before_action :authorize_web
   before_action :set_locale
-  before_action :require_user
+
+  authorize_resource
 
   def new
     if required_new_report_params_present?
index 3ff46656899c0d45214ef1eb7e72f24e86705ec8..5107a768be95c5e5bfdcbe6cd81b8955a6140054 100644 (file)
@@ -6,19 +6,27 @@ class Ability
   def initialize(user)
     can :index, :site
     can [:permalink, :edit, :help, :fixthemap, :offline, :export, :about, :preview, :copyright, :key, :id], :site
-
     can [:index, :rss, :show, :comments], DiaryEntry
-
     can [:search, :search_latlon, :search_ca_postcode, :search_osm_nominatim,
          :search_geonames, :search_osm_nominatim_reverse, :search_geonames_reverse], :geocoder
 
     if user
       can :welcome, :site
-
       can [:create, :edit, :comment, :subscribe, :unsubscribe], DiaryEntry
+      can [:new, :create], Report
 
-      can [:hide, :hidecomment], [DiaryEntry, DiaryComment] if user.administrator?
+      if user.moderator?
+        can [:index, :show, :resolve, :ignore, :reopen], Issue
+        can :create, IssueComment
+      end
+
+      if user.administrator?
+        can [:hide, :hidecomment], [DiaryEntry, DiaryComment]
+        can [:index, :show, :resolve, :ignore, :reopen], Issue
+        can :create, IssueComment
+      end
     end
+
     # Define abilities for the passed in user here. For example:
     #
     #   user ||= User.new # guest user (not logged in)