forked from fixin.me/fixin.me
		
	Update permission checking
This commit is contained in:
		
							parent
							
								
									537cd18336
								
							
						
					
					
						commit
						817b1a4376
					
				@ -1,11 +1,30 @@
 | 
				
			|||||||
class Default::UnitsController < ApplicationController
 | 
					class Default::UnitsController < ApplicationController
 | 
				
			||||||
  navigation_tab :units
 | 
					  navigation_tab :units
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  before_action :find_unit, only: [:import, :export, :destroy]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  before_action except: :index do
 | 
					  before_action except: :index do
 | 
				
			||||||
 | 
					    case action_name.to_sym
 | 
				
			||||||
 | 
					    when :import, :import_all
 | 
				
			||||||
 | 
					      raise AccessForbidden unless current_user.at_least(:active)
 | 
				
			||||||
 | 
					    else
 | 
				
			||||||
      raise AccessForbidden unless current_user.at_least(:admin)
 | 
					      raise AccessForbidden unless current_user.at_least(:admin)
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def index
 | 
					  def index
 | 
				
			||||||
    @units = current_user.units.defaults_diff
 | 
					    @units = current_user.units.defaults_diff
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  def import
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  def import_all
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  def export
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  def destroy
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
				
			|||||||
@ -1,5 +1,5 @@
 | 
				
			|||||||
class UnitsController < ApplicationController
 | 
					class UnitsController < ApplicationController
 | 
				
			||||||
  before_action only: [:new] do
 | 
					  before_action only: :new do
 | 
				
			||||||
    find_unit if params[:id].present?
 | 
					    find_unit if params[:id].present?
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
  before_action :find_unit, only: [:edit, :update, :rebase, :destroy]
 | 
					  before_action :find_unit, only: [:edit, :update, :rebase, :destroy]
 | 
				
			||||||
 | 
				
			|||||||
@ -2,11 +2,14 @@ class UsersController < ApplicationController
 | 
				
			|||||||
  helper_method :allow_disguise?
 | 
					  helper_method :allow_disguise?
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  before_action :find_user, only: [:show, :update, :disguise]
 | 
					  before_action :find_user, only: [:show, :update, :disguise]
 | 
				
			||||||
  before_action except: :revert do
 | 
					
 | 
				
			||||||
 | 
					  before_action do
 | 
				
			||||||
 | 
					    case action_name.to_sym
 | 
				
			||||||
 | 
					    when :revert
 | 
				
			||||||
 | 
					      raise AccessForbidden unless current_user_disguised?
 | 
				
			||||||
 | 
					    else
 | 
				
			||||||
      raise AccessForbidden unless current_user.at_least(:admin)
 | 
					      raise AccessForbidden unless current_user.at_least(:admin)
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
  before_action only: :revert do
 | 
					 | 
				
			||||||
    raise AccessForbidden unless current_user_disguised?
 | 
					 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def index
 | 
					  def index
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user