-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added a permission form that supports destroy and id. Fixes #67 #68
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module HydraEditor | ||
module Form | ||
module Permissions | ||
extend ActiveSupport::Concern | ||
|
||
module ClassMethods | ||
|
||
def build_permitted_params | ||
permitted = super | ||
permitted << { permissions_attributes: [:type, :name, :access, :id, :_destroy] } | ||
permitted | ||
end | ||
end | ||
|
||
# This is required so that fields_for will draw a nested form. | ||
# See ActionView::Helpers#nested_attributes_association? | ||
# https://github.com/rails/rails/blob/a04c0619617118433db6e01b67d5d082eaaa0189/actionview/lib/action_view/helpers/form_helper.rb#L1890 | ||
def permissions_attributes= attributes | ||
model.permissions_attributes= attributes | ||
end | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
require 'spec_helper' | ||
|
||
describe HydraEditor::Form::Permissions do | ||
class TestModel < ActiveFedora::Base | ||
property :title, predicate: ::RDF::DC.title | ||
property :creator, predicate: ::RDF::DC.creator, multiple: false | ||
end | ||
|
||
class TestForm | ||
include HydraEditor::Form | ||
include HydraEditor::Form::Permissions | ||
self.model_class = TestModel | ||
# Terms is the list of fields displayed by app/views/records/_form.html.erb | ||
self.terms = [:title, :creator] | ||
end | ||
|
||
describe "model_attributes" do | ||
let(:params) { ActionController::Parameters.new(title: [''], creator: 'bob', description: ['huh'], permissions_attributes: {'0' => { id: '123', _destroy: 'true' }}) } | ||
subject { TestForm.model_attributes(params) } | ||
|
||
it { is_expected.to eq('creator' => 'bob', 'title' => [], | ||
'permissions_attributes' => { '0' => { 'id' => '123', '_destroy' => 'true' } }) } | ||
end | ||
|
||
describe "permissions_attributes=" do | ||
subject { TestForm.new(TestModel.new) } | ||
it "should respond to permissions_attributes=" do | ||
expect(subject).to respond_to(:permissions_attributes=) | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,13 @@ class TestForm | |
describe "class methods" do | ||
subject { TestForm.model_name } | ||
it { is_expected.to eq 'TestModel' } | ||
|
||
describe "model_attributes" do | ||
let(:params) { ActionController::Parameters.new(title: [''], creator: 'bob', description: ['huh']) } | ||
subject { TestForm.model_attributes(params) } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again on description setting here... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. checking it's removed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 Now I understand! |
||
|
||
it { is_expected.to eq('creator' => 'bob', 'title' => []) } | ||
end | ||
end | ||
|
||
let(:object) { TestModel.new(title: ['foo', 'bar'], creator: 'baz') } | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are you setting description when you do not check for it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we're checking that it's removed, because its not an authorized attribute.