Sha256: 0afebabdb11ac89c9b29019536cca14be190b7f960d593f3f77bb35c0bc463b4

Contents?: true

Size: 816 Bytes

Versions: 14

Compression:

Stored size: 816 Bytes

Contents

module Permitify
  extend ActiveSupport::Concern
  
  included do
    before_action :require_permission!
  end
  
  def require_permission!
    return false unless current_admin
    return true if current_admin_is_updating_profile?
    unless current_admin.permitted_to?(params)
      respond_to do |format|
        format.html { redirect_to polymorphic_path([:admin, :root]), alert: t('flash.unpermitted') }
        format.xml { head :ok }
        format.js do
          flash.now[:alert] = t('flash.unpermitted')
          render js: "window.location = '#{polymorphic_path([:admin, :root])}'"
        end
      end
      return false
    end
  end

  def current_admin_is_updating_profile?
    params[:id].to_i == current_admin.id && params[:controller] == "admin/admins" && params[:action] == "update"
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
comfortable_mexican_loveseat-0.1.1 app/controllers/concerns/permitify.rb
comfortable_mexican_loveseat-0.1.0 app/controllers/concerns/permitify.rb
comfortable_mexican_loveseat-0.0.23 app/controllers/concerns/permitify.rb
comfortable_mexican_loveseat-0.0.22 app/controllers/concerns/permitify.rb
comfortable_mexican_loveseat-0.0.21 app/controllers/concerns/permitify.rb
comfortable_mexican_loveseat-0.0.20 app/controllers/concerns/permitify.rb
comfortable_mexican_loveseat-0.0.19 app/controllers/concerns/permitify.rb
comfortable_mexican_loveseat-0.0.18 app/controllers/concerns/permitify.rb
comfortable_mexican_loveseat-0.0.17 app/controllers/concerns/permitify.rb
comfortable_mexican_loveseat-0.0.16 app/controllers/concerns/permitify.rb
comfortable_mexican_loveseat-0.0.15 app/controllers/concerns/permitify.rb
comfortable_mexican_loveseat-0.0.14 app/controllers/concerns/permitify.rb
comfortable_mexican_loveseat-0.0.13 app/controllers/concerns/permitify.rb
comfortable_mexican_loveseat-0.0.12 app/controllers/concerns/permitify.rb