Skip to content

Commit

Permalink
Track changes on visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Aug 27, 2013
1 parent f1cc39c commit 30f28f4
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 96 deletions.
15 changes: 0 additions & 15 deletions lib/sufia/files_controller_behavior.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright © 2012 The Pennsylvania State University
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

module Sufia
module FilesController
autoload :LocalIngestBehavior, 'sufia/files_controller/local_ingest_behavior'
Expand Down
72 changes: 44 additions & 28 deletions spec/models/generic_file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,74 +90,90 @@
end
end

describe "visibility" do
it "should not be changed when it's new" do
subject.should_not be_visibility_changed
end
it "should be changed when it has been changed" do
subject.visibility= 'open'
subject.should be_visibility_changed
end

it "should not be changed when it's set to its previous value" do
subject.visibility= 'private'
subject.should_not be_visibility_changed
end

end

describe "attributes" do
it "should have rightsMetadata" do
@file.rightsMetadata.should be_instance_of ParanoidRightsDatastream
subject.rightsMetadata.should be_instance_of ParanoidRightsDatastream
end
it "should have properties datastream for depositor" do
@file.properties.should be_instance_of PropertiesDatastream
subject.properties.should be_instance_of PropertiesDatastream
end
it "should have apply_depositor_metadata" do
@file.rightsMetadata.edit_access.should == ['jcoyne']
@file.depositor.should == 'jcoyne'
subject.rightsMetadata.edit_access.should == ['jcoyne']
subject.depositor.should == 'jcoyne'
end
it "should have a set of permissions" do
@file.read_groups=['group1', 'group2']
@file.edit_users=['user1']
@file.read_users=['user2', 'user3']
@file.permissions.should == [{:type=>"group", :access=>"read", :name=>"group1"},
subject.read_groups=['group1', 'group2']
subject.edit_users=['user1']
subject.read_users=['user2', 'user3']
subject.permissions.should == [{:type=>"group", :access=>"read", :name=>"group1"},
{:type=>"group", :access=>"read", :name=>"group2"},
{:type=>"user", :access=>"read", :name=>"user2"},
{:type=>"user", :access=>"read", :name=>"user3"},
{:type=>"user", :access=>"edit", :name=>"user1"}]
end
describe "updating permissions" do
it "should create new group permissions" do
@file.permissions = {:new_group_name => {'group1'=>'read'}}
@file.permissions.should == [{:type=>"group", :access=>"read", :name=>"group1"},
subject.permissions = {:new_group_name => {'group1'=>'read'}}
subject.permissions.should == [{:type=>"group", :access=>"read", :name=>"group1"},
{:type=>"user", :access=>"edit", :name=>"jcoyne"}]
end
it "should create new user permissions" do
@file.permissions = {:new_user_name => {'user1'=>'read'}}
@file.permissions.should == [{:type=>"user", :access=>"read", :name=>"user1"},
subject.permissions = {:new_user_name => {'user1'=>'read'}}
subject.permissions.should == [{:type=>"user", :access=>"read", :name=>"user1"},
{:type=>"user", :access=>"edit", :name=>"jcoyne"}]
end
it "should not replace existing groups" do
@file.permissions = {:new_group_name=> {'group1' => 'read'}}
@file.permissions = {:new_group_name=> {'group2' => 'read'}}
@file.permissions.should == [{:type=>"group", :access=>"read", :name=>"group1"},
subject.permissions = {:new_group_name=> {'group1' => 'read'}}
subject.permissions = {:new_group_name=> {'group2' => 'read'}}
subject.permissions.should == [{:type=>"group", :access=>"read", :name=>"group1"},
{:type=>"group", :access=>"read", :name=>"group2"},
{:type=>"user", :access=>"edit", :name=>"jcoyne"}]
end
it "should not replace existing users" do
@file.permissions = {:new_user_name=>{'user1'=>'read'}}
@file.permissions = {:new_user_name=>{'user2'=>'read'}}
@file.permissions.should == [{:type=>"user", :access=>"read", :name=>"user1"},
subject.permissions = {:new_user_name=>{'user1'=>'read'}}
subject.permissions = {:new_user_name=>{'user2'=>'read'}}
subject.permissions.should == [{:type=>"user", :access=>"read", :name=>"user1"},
{:type=>"user", :access=>"read", :name=>"user2"},
{:type=>"user", :access=>"edit", :name=>"jcoyne"}]
end
it "should update permissions on existing users" do
@file.permissions = {:new_user_name=>{'user1'=>'read'}}
@file.permissions = {:user=>{'user1'=>'edit'}}
@file.permissions.should == [{:type=>"user", :access=>"edit", :name=>"user1"},
subject.permissions = {:new_user_name=>{'user1'=>'read'}}
subject.permissions = {:user=>{'user1'=>'edit'}}
subject.permissions.should == [{:type=>"user", :access=>"edit", :name=>"user1"},
{:type=>"user", :access=>"edit", :name=>"jcoyne"}]
end
it "should update permissions on existing groups" do
@file.permissions = {:new_group_name=>{'group1'=>'read'}}
@file.permissions = {:group=>{'group1'=>'edit'}}
@file.permissions.should == [{:type=>"group", :access=>"edit", :name=>"group1"},
subject.permissions = {:new_group_name=>{'group1'=>'read'}}
subject.permissions = {:group=>{'group1'=>'edit'}}
subject.permissions.should == [{:type=>"group", :access=>"edit", :name=>"group1"},
{:type=>"user", :access=>"edit", :name=>"jcoyne"}]
end
end
it "should have a characterization datastream" do
@file.characterization.should be_kind_of FitsDatastream
subject.characterization.should be_kind_of FitsDatastream
end
it "should have a dc desc metadata" do
@file.descMetadata.should be_kind_of GenericFileRdfDatastream
subject.descMetadata.should be_kind_of GenericFileRdfDatastream
end
it "should have content datastream" do
@file.add_file(File.open(fixture_path + '/world.png'), 'content', 'world.png')
@file.content.should be_kind_of FileContentDatastream
subject.add_file(File.open(fixture_path + '/world.png'), 'content', 'world.png')
subject.content.should be_kind_of FileContentDatastream
end
end
describe "delegations" do
Expand Down
13 changes: 0 additions & 13 deletions sufia-models/app/models/generic_file.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
# Copyright © 2012 The Pennsylvania State University
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
class GenericFile < ActiveFedora::Base
include Sufia::GenericFile
end
2 changes: 0 additions & 2 deletions sufia-models/lib/sufia/models/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,11 @@ class Engine < ::Rails::Engine
require 'sufia/models/noid'
require 'sufia/models/file_content'
require 'sufia/models/file_content/versions'
require 'sufia/models/generic_file/actions'
require 'sufia/models/generic_file/audit'
require 'sufia/models/generic_file/characterization'
require 'sufia/models/generic_file/derivatives'
require 'sufia/models/generic_file/export'
require 'sufia/models/generic_file/mime_types'
require 'sufia/models/generic_file/permissions'
require 'sufia/models/generic_file/thumbnail'
require 'sufia/models/generic_file'
require 'sufia/models/user'
Expand Down
5 changes: 3 additions & 2 deletions sufia-models/lib/sufia/models/generic_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ module Sufia
module GenericFile
extend ActiveSupport::Concern
extend ActiveSupport::Autoload
autoload :Actions
autoload :Permissions
autoload :Actions, 'sufia/models/generic_file/actions'
autoload :Permissions, 'sufia/models/generic_file/permissions'
autoload :Visibility, 'sufia/models/generic_file/visibility'
autoload :WebForm, 'sufia/models/generic_file/web_form'
autoload :AccessibleAttributes, 'sufia/models/generic_file/accessible_attributes'
include Sufia::ModelMethods
Expand Down
24 changes: 2 additions & 22 deletions sufia-models/lib/sufia/models/generic_file/permissions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,15 @@ module Sufia
module GenericFile
module Permissions
extend ActiveSupport::Concern
extend Deprecation
#we're overriding the permissions= method which is in RightsMetadata
include Hydra::ModelMixins::RightsMetadata
include Sufia::GenericFile::Visibility

included do
has_metadata :name => "rightsMetadata", :type => ParanoidRightsDatastream
validate :paranoid_permissions
end

def visibility= (visibility)
# only set explicit permissions
case visibility
when "open"
self.datastreams["rightsMetadata"].permissions({:group=>"public"}, "read")
when "psu"
self.datastreams["rightsMetadata"].permissions({:group=>"registered"}, "read")
self.datastreams["rightsMetadata"].permissions({:group=>"public"}, "none")
when "restricted"
self.datastreams["rightsMetadata"].permissions({:group=>"registered"}, "none")
self.datastreams["rightsMetadata"].permissions({:group=>"public"}, "none")
end
end

def set_visibility(visibility)
Deprecation.warn Permissions, "set_visibility is deprecated, use visibility= instead. set_visibility will be removed in sufia 3.0", caller
self.visibility= visibility
end

def paranoid_permissions
# let the rightsMetadata ds make this determination
# - the object instance is passed in for easier access to the props ds
Expand Down Expand Up @@ -62,8 +44,6 @@ def permission_hash
end
{'person'=>user_perms, 'group'=>group_perms}
end


end
end
end
59 changes: 59 additions & 0 deletions sufia-models/lib/sufia/models/generic_file/visibility.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
module Sufia
module GenericFile
module Visibility
extend ActiveSupport::Concern
extend Deprecation
include ActiveModel::Dirty

included do
define_attribute_methods :visibility
end

def visibility= (value)
# only set explicit permissions
case value
when "open"
public_visibility!
when "psu"
registered_visibility!
when "restricted"
private_visibility!
end
end

def public_visibility!
visibility_will_change! unless visibility == 'public'
self.datastreams["rightsMetadata"].permissions({:group=>"public"}, "read")
end

def registered_visibility!
visibility_will_change! unless visibility == 'registered'
self.datastreams["rightsMetadata"].permissions({:group=>"registered"}, "read")
self.datastreams["rightsMetadata"].permissions({:group=>"public"}, "none")
end

def private_visibility!
visibility_will_change! unless visibility == 'private'
self.datastreams["rightsMetadata"].permissions({:group=>"registered"}, "none")
self.datastreams["rightsMetadata"].permissions({:group=>"public"}, "none")
end

def visibility
if read_groups.include? 'public'
'public'
elsif read_groups.include? 'registered'
'registered'
else
'private'
end
end

def set_visibility(visibility)
Deprecation.warn Permissions, "set_visibility is deprecated, use visibility= instead. set_visibility will be removed in sufia 3.0", caller
self.visibility= visibility
end
end
end
end


14 changes: 0 additions & 14 deletions sufia-models/lib/sufia/models/jobs/batch_update_job.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
# Copyright © 2012 The Pennsylvania State University
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

class BatchUpdateJob
include Hydra::PermissionsQuery
include Rails.application.routes.url_helpers
Expand Down

0 comments on commit 30f28f4

Please sign in to comment.