Skip to content

Commit

Permalink
Remove all attr_accessible_role related codes and specs. Refs #1730
Browse files Browse the repository at this point in the history
  • Loading branch information
mshibuya committed Aug 29, 2013
1 parent 0be9e22 commit d521b54
Show file tree
Hide file tree
Showing 7 changed files with 5 additions and 64 deletions.
6 changes: 1 addition & 5 deletions app/controllers/rails_admin/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ApplicationController < ::ApplicationController
before_filter :_authorize!
before_filter :_audit!

helper_method :_current_user, :_attr_accessible_role, :_get_plugin_name
helper_method :_current_user, :_get_plugin_name

attr_reader :object, :model_config, :abstract_model

Expand Down Expand Up @@ -57,10 +57,6 @@ def _current_user

alias_method :user_for_paper_trail, :_current_user

def _attr_accessible_role
instance_eval &RailsAdmin::Config.attr_accessible_role
end

rescue_from RailsAdmin::ObjectNotFound do
flash[:error] = I18n.t('admin.flash.object_not_found', :model => @model_name, :id => params[:id])
params[:action] = 'index'
Expand Down
2 changes: 1 addition & 1 deletion lib/rails_admin/adapters/active_record/abstract_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def initialize(object)
self.object = object
end

def set_attributes(attributes, role = nil)
def set_attributes(attributes)
object.assign_attributes(attributes)
end

Expand Down
8 changes: 0 additions & 8 deletions lib/rails_admin/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ module Config
request.env['warden'].try(:authenticate!)
end

DEFAULT_ATTR_ACCESSIBLE_ROLE = Proc.new { :default }

DEFAULT_AUTHORIZE = Proc.new {}

DEFAULT_AUDIT = Proc.new {}
Expand Down Expand Up @@ -101,12 +99,6 @@ def authenticate_with(&blk)
@authenticate || DEFAULT_AUTHENTICATION
end


def attr_accessible_role(&blk)
@attr_accessible_role = blk if blk
@attr_accessible_role || DEFAULT_ATTR_ACCESSIBLE_ROLE
end

# Setup auditing/history/versioning provider that observe objects lifecycle
def audit_with(*args, &block)
extension = args.shift
Expand Down
2 changes: 1 addition & 1 deletion lib/rails_admin/config/actions/edit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Edit < RailsAdmin::Config::Actions::Base
satisfy_strong_params!
sanitize_params_for!(request.xhr? ? :modal : :update)

@object.set_attributes(params[@abstract_model.param_key], _attr_accessible_role)
@object.set_attributes(params[@abstract_model.param_key])
@authorization_adapter && @authorization_adapter.attributes_for(:update, @abstract_model).each do |name, value|
@object.send("#{name}=", value)
end
Expand Down
4 changes: 2 additions & 2 deletions lib/rails_admin/config/actions/new.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class New < RailsAdmin::Config::Actions::Base
@object.send("#{name}=", value)
end
if object_params = params[@abstract_model.to_param]
@object.set_attributes(@object.attributes.merge(object_params), _attr_accessible_role)
@object.set_attributes(@object.attributes.merge(object_params))
end
respond_to do |format|
format.html { render @action.template_name }
Expand All @@ -37,7 +37,7 @@ class New < RailsAdmin::Config::Actions::Base
satisfy_strong_params!
sanitize_params_for!(request.xhr? ? :modal : :create)

@object.set_attributes(params[@abstract_model.param_key], _attr_accessible_role)
@object.set_attributes(params[@abstract_model.param_key])
@authorization_adapter && @authorization_adapter.attributes_for(:create, @abstract_model).each do |name, value|
@object.send("#{name}=", value)
end
Expand Down
31 changes: 0 additions & 31 deletions spec/integration/config/edit/rails_admin_config_edit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,37 +69,6 @@
end
end

describe "attr_accessible" do


it "is configurable in the controller scope" do

RailsAdmin.config do |config|
config.excluded_models = []
config.attr_accessible_role do
_current_user.attr_accessible_role # sould be :custom_role
end

config.model FieldTest do
edit do
field :string_field
field :restricted_field
field :protected_field
end
end
end

visit new_path(:model_name => "field_test")
fill_in "field_test[string_field]", :with => "No problem here"
fill_in "field_test[restricted_field]", :with => "I'm allowed to do that as :custom_role only"
should have_no_selector "field_test[protected_field]"
click_button "Save" # first(:button, "Save").click
@field_test = FieldTest.first
expect(@field_test.string_field).to eq("No problem here")
expect(@field_test.restricted_field).to eq("I'm allowed to do that as :custom_role only")
end
end

describe "css hooks" do
it "is present" do
visit new_path(:model_name => "team")
Expand Down
16 changes: 0 additions & 16 deletions spec/rails_admin/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,22 +75,6 @@
end
end

describe ".attr_accessible_role" do
it "sould be :default by default" do
expect(RailsAdmin.config.attr_accessible_role.call).to eq(:default)
end

it "sould be configurable with user role for example" do
RailsAdmin.config do |config|
config.attr_accessible_role do
:admin
end
end

expect(RailsAdmin.config.attr_accessible_role.call).to eq(:admin)
end
end

describe ".main_app_name" do

it "as a default meaningful dynamic value" do
Expand Down

0 comments on commit d521b54

Please sign in to comment.