Module: ActiveScaffold

Defined in:
lib/active_scaffold/active_record_permissions.rb,
lib/active_scaffold.rb,
lib/active_scaffold/engine.rb,
lib/active_scaffold/finder.rb,
lib/active_scaffold/bridges.rb,
lib/active_scaffold/version.rb,
lib/active_scaffold/constraints.rb,
lib/active_scaffold/configurable.rb,
lib/active_scaffold/marked_model.rb,
lib/active_scaffold/attribute_params.rb,
lib/active_scaffold/helpers/id_helpers.rb,
lib/active_scaffold/helpers/view_helpers.rb,
lib/active_scaffold/bridges/dragonfly/form_ui.rb,
lib/active_scaffold/bridges/dragonfly/list_ui.rb,
lib/active_scaffold/bridges/paperclip/form_ui.rb,
lib/active_scaffold/bridges/paperclip/list_ui.rb,
lib/active_scaffold/bridges/shared/date_bridge.rb,
lib/active_scaffold/helpers/controller_helpers.rb,
lib/active_scaffold/helpers/pagination_helpers.rb,
lib/active_scaffold/bridges/carrierwave/form_ui.rb,
lib/active_scaffold/bridges/carrierwave/list_ui.rb,
lib/active_scaffold/bridges/file_column/form_ui.rb,
lib/active_scaffold/bridges/file_column/list_ui.rb,
lib/active_scaffold/helpers/association_helpers.rb,
lib/active_scaffold/helpers/form_column_helpers.rb,
lib/active_scaffold/helpers/list_column_helpers.rb,
lib/active_scaffold/helpers/show_column_helpers.rb,
lib/active_scaffold/helpers/search_column_helpers.rb,
lib/active_scaffold/helpers/human_condition_helpers.rb,
lib/active_scaffold/bridges/dragonfly/dragonfly_bridge.rb,
lib/active_scaffold/bridges/paperclip/paperclip_bridge.rb,
lib/active_scaffold/bridges/carrierwave/carrierwave_bridge.rb,
lib/active_scaffold/bridges/file_column/file_column_helpers.rb,
lib/active_scaffold/bridges/calendar_date_select/as_cds_bridge.rb,
lib/active_scaffold/bridges/dragonfly/dragonfly_bridge_helpers.rb,
lib/active_scaffold/bridges/paperclip/paperclip_bridge_helpers.rb,
lib/active_scaffold/bridges/carrierwave/carrierwave_bridge_helpers.rb

Overview

This module attempts to create permissions conventions for your ActiveRecord models. It supports english-based methods that let you restrict access per-model, per-record, per-column, per-action, and per-user. All at once.

You may define instance methods in the following formats:

def #{column}_authorized_for_#{action}?
def #{column}_authorized?
def authorized_for_#{action}?

Your methods should allow for the following special cases:

* cron scripts
* guest users (or nil current_user objects)

Defined Under Namespace

Modules: Actions, AttributeParams, Bridges, ClassMethods, Config, Configurable, Constraints, DataStructures, Finder, Helpers, MarkedModel, ModelPermissions, RespondsToParent, Version Classes: ActionNotAllowed, ControllerNotFound, DependencyFailure, Engine, MalformedConstraint, Paginator, RecordNotAllowed, ReverseAssociationRequired

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.autoload_subdir(dir, mod = self, root = File.dirname(__FILE__)) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/active_scaffold.rb', line 32

def self.autoload_subdir(dir, mod=self, root = File.dirname(__FILE__))
  Dir["#{root}/active_scaffold/#{dir}/*.rb"].each { |file|
    basename = File.basename(file, ".rb")
    mod.module_eval {
      autoload basename.camelcase.to_sym, "active_scaffold/#{dir}/#{basename}"
    }
  }
end

.exclude_bridgesObject



155
156
157
# File 'lib/active_scaffold.rb', line 155

def self.exclude_bridges
  @@exclude_bridges ||= []
end

.exclude_bridges=(bridges) ⇒ Object

exclude bridges you do not need name of bridge subdir should be used to exclude it eg

ActiveScaffold.exclude_bridges = [:cancan, :ancestry]
if you are using Activescaffold as a gem add to initializer
if you are using Activescaffold as a plugin add to active_scaffold_env.rb


151
152
153
# File 'lib/active_scaffold.rb', line 151

def self.exclude_bridges=(bridges)
  @@exclude_bridges = bridges
end

.included(base) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
# File 'lib/active_scaffold.rb', line 64

def self.included(base)
  base.extend(ClassMethods)
  base.module_eval do
    # TODO: these should be in actions/core
    before_filter :handle_user_settings
    before_filter :check_input_device
  end

  base.helper_method :touch_device?
  base.helper_method :hover_via_click?
end

.js_configObject



141
142
143
# File 'lib/active_scaffold.rb', line 141

def self.js_config
  @@js_config ||= {:scroll_on_close => true}
end

.js_config=(config) ⇒ Object



137
138
139
# File 'lib/active_scaffold.rb', line 137

def self.js_config=(config)
  @@js_config = config
end

.js_frameworkObject



129
130
131
132
133
134
135
# File 'lib/active_scaffold.rb', line 129

def self.js_framework
  @@js_framework ||= if defined? Jquery
    :jquery
  elsif defined? PrototypeRails
    :prototype
  end
end

.js_framework=(framework) ⇒ Object



125
126
127
# File 'lib/active_scaffold.rb', line 125

def self.js_framework=(framework)
  @@js_framework = framework
end

.rootObject



159
160
161
# File 'lib/active_scaffold.rb', line 159

def self.root
  File.dirname(__FILE__) + "/.."
end

.set_defaults(&block) ⇒ Object



76
77
78
# File 'lib/active_scaffold.rb', line 76

def self.set_defaults(&block)
  ActiveScaffold::Config::Core.configure &block
end

Instance Method Details

#active_scaffold_configObject



80
81
82
# File 'lib/active_scaffold.rb', line 80

def active_scaffold_config
  self.class.active_scaffold_config
end

#active_scaffold_config_for(klass) ⇒ Object



84
85
86
# File 'lib/active_scaffold.rb', line 84

def active_scaffold_config_for(klass)
  self.class.active_scaffold_config_for(klass)
end

#active_scaffold_session_storage(id = nil) ⇒ Object



88
89
90
91
92
93
# File 'lib/active_scaffold.rb', line 88

def active_scaffold_session_storage(id = nil)
  id ||= params[:eid] || "#{params[:controller]}#{"_#{nested.parent_id}" if nested?}"
  session_index = "as:#{id}"
  session[session_index] ||= {}
  session[session_index]
end

#check_input_deviceObject



107
108
109
110
111
112
113
114
115
# File 'lib/active_scaffold.rb', line 107

def check_input_device
 if request.env["HTTP_USER_AGENT"] && request.env["HTTP_USER_AGENT"][/(iPhone|iPod|iPad)/i]
   session[:input_device_type] = 'TOUCH'
   session[:hover_supported] = false
 else
   session[:input_device_type] = 'MOUSE'
   session[:hover_supported] = true
 end if session[:input_device_type].nil?
end

#handle_user_settingsObject

at some point we need to pass the session and params into config. we’ll just take care of that before any particular action occurs by passing those hashes off to the UserSettings class of each action.



96
97
98
99
100
101
102
103
104
105
# File 'lib/active_scaffold.rb', line 96

def 
  if self.class.uses_active_scaffold?
    active_scaffold_config.actions.each do |action_name|
      conf_instance = active_scaffold_config.send(action_name) rescue next
      next if conf_instance.class::UserSettings == ActiveScaffold::Config::Base::UserSettings # if it hasn't been extended, skip it
      active_scaffold_session_storage[action_name] ||= {}
      conf_instance.user = conf_instance.class::UserSettings.new(conf_instance, active_scaffold_session_storage[action_name], params)
    end
  end
end

#hover_via_click?Boolean

Returns:

  • (Boolean)


121
122
123
# File 'lib/active_scaffold.rb', line 121

def hover_via_click?
  session[:hover_supported] == false
end

#touch_device?Boolean

Returns:

  • (Boolean)


117
118
119
# File 'lib/active_scaffold.rb', line 117

def touch_device?
  session[:input_device_type] == 'TOUCH'
end