Option to publish when setting usage_rights

Gives the ability to publish the file(s)/
folder(s) when settings usage_rights via
the API

refs CNVS-17124

Change-Id: I383949c0d405658f5482fc4cc469fe20a995404b
Reviewed-on: https://gerrit.instructure.com/45221
Reviewed-by: Jeremy Stanley <jeremy@instructure.com>
Tested-by: Jenkins <jenkins@instructure.com>
Product-Review: Dan Minkevitch <dan@instructure.com>
QA-Review: Dan Minkevitch <dan@instructure.com>
This commit is contained in:
Dan Minkevitch 2014-12-03 13:10:56 -07:00
parent 5b413bb2f8
commit e42acfe19d
2 changed files with 37 additions and 1 deletions

View File

@ -94,6 +94,9 @@ class UsageRightsController < ApplicationController
# List of ids of folders to search for files to set usage rights for.
# Note that new files uploaded to these folders do not automatically inherit these rights.
#
# @argument publish [Optional, Boolean]
# Whether the file(s) or folder(s) should be published on save, provided that usage rights have been specified (set to `true` to publish on save).
#
# @argument usage_rights[use_justification] [Required, String, "own_copyright"|"used_by_permission"|"fair_use"|"public_domain"|"creative_commons"]
# The intellectual property justification for using the files in Canvas
#
@ -161,8 +164,10 @@ private
folders = @context.folders.active.where(id: folder_ids).to_a
file_ids = folders.inject([]) { |file_ids, folder| file_ids += enumerate_contents(folder) }
file_ids += @context.attachments.not_deleted.where(id: Array(params[:file_ids]).map(&:to_i)).pluck(:id)
update_attrs = {usage_rights_id: usage_rights}
update_attrs.merge!(locked: false) if usage_rights.present? && value_to_boolean(params[:publish])
count = @context.attachments.not_deleted.where(id: file_ids).update_all(usage_rights_id: usage_rights)
count = @context.attachments.not_deleted.where(id: file_ids).update_all(update_attrs)
result = usage_rights ? usage_rights_json(usage_rights, @current_user) : {}
result.merge!({
message: I18n.t({one: "1 file updated", other: "%{count} files updated"}, count: count ),

View File

@ -52,6 +52,37 @@ describe UsageRightsController, type: :request do
{}, {}, {expected_status: 401})
end
it "should publish on save when usage_rights & publish have been set" do
@fileR.locked = true
@fileR.save
expect(@fileR.reload.locked).to be_truthy
json = api_call(:put, "/api/v1/courses/#{@course.id}/usage_rights",
{ controller: 'usage_rights', action: 'set_usage_rights', course_id: @course.to_param, format: 'json' },
{ file_ids: [@fileR.id], publish: true, usage_rights: {use_justification: 'used_by_permission', legal_copyright: '(C) 2014 XYZ Corp'} })
expect(json['message']).to eq('1 file updated')
expect(json['file_ids']).to match_array([@fileR.id])
expect(json['use_justification']).to eq('used_by_permission')
@fileR.reload
expect(@fileR.usage_rights.use_justification).to eq('used_by_permission')
expect(@fileR.locked).to be_falsey
end
it "should not publish when usage_rights have not been set" do
@fileR.locked = true
@fileR.save
expect(@fileR.reload.locked).to be_truthy
json = api_call(:put, "/api/v1/courses/#{@course.id}/usage_rights",
{ controller: 'usage_rights', action: 'set_usage_rights', course_id: @course.to_param, format: 'json' },
{ file_ids: [@fileR.id], publish: true }, {}, {expected_status: 400})
expect(json).to eql({'message' => "No 'usage_rights' object supplied"})
expect(@fileR.reload.locked).to be_truthy
end
it "should require usage_rights hash" do
json = api_call(:put, "/api/v1/courses/#{@course.id}/usage_rights",
{ controller: 'usage_rights', action: 'set_usage_rights', course_id: @course.to_param, format: 'json' },