Sha256: 5a127a46ff3d2ee1a0b6cd26310b182aa193cdfffddbccb02b07deaafea9f690
Contents?: true
Size: 1.57 KB
Versions: 28
Compression:
Stored size: 1.57 KB
Contents
module Faalis module Permissions extend ActiveSupport::Concern module ClassMethods # Default permission hash @@permissions = { :read => nil, :update => nil, :create => nil, :destroy => nil, } @@only_owner = false # @return an array of strings representation of permissions def permission_strings(model) strings = [] model_name = model.to_s humanize_name = ActiveModel::Name.new(model).human if model.respond_to? :model_name model_name = model.model_name humanize_name = model_name.human end @@permissions.each do |key, value| strings << { :name => "#{key}|#{model_name}", :string => _("can %s %s") % [_(key.to_s), humanize_name] } end strings end def possible_permissions @@permissions.keys end # Define permissions using this method def permissions(*args) args.each do |permission| if permission.class == Symbol if not @@permissions.include? permission @@permission[permission] = nil elsif permission.class == Hash permission.each do |key, value| @@permissions[key.to_sym] = value end end end end end # This force user to have access to resources which is his. def only_his_objects @@only_owner = true end def only_his_objects? @@only_owner end end end end
Version data entries
28 entries across 28 versions & 1 rubygems