call translated license names in a lambda

Change-Id: Ibdbca9847de64e79f472df8d3ff886e3b9c4a4ba
Reviewed-on: https://gerrit.instructure.com/122503
Tested-by: Jenkins
Reviewed-by: Cody Cutrer <cody@instructure.com>
Product-Review: James Williams  <jamesw@instructure.com>
QA-Review: James Williams  <jamesw@instructure.com>
This commit is contained in:
James Williams 2017-08-11 14:28:58 -06:00
parent 570d1b32a3
commit b8eb9b04d2
9 changed files with 63 additions and 53 deletions

View File

@ -146,7 +146,7 @@ class UsageRightsController < ApplicationController
# there are no per-context licenses yet, but let's pretend like there are, for future expandability
if authorized_action(@context, @current_user, :read)
render json: UsageRights.licenses.map { |license, data|
{ id: license, name: data[:readable_license], url: data[:license_url] }
{ id: license, name: data[:readable_license].call, url: data[:license_url] }
}
end
end

View File

@ -473,7 +473,7 @@ class Course < ActiveRecord::Base
end
def readable_license
license_data[:readable_license]
license_data[:readable_license].call
end
def unpublishable?

View File

@ -41,7 +41,7 @@ class UsageRights < ActiveRecord::Base
end
def license_name
self.class.licenses[license || 'private'][:readable_license]
self.class.licenses[license || 'private'][:readable_license].call
end
def license_url

View File

@ -308,7 +308,7 @@
<td class="form-label"><%= f.label :license, :en => "License" %></td>
<td colspan="3">
<% if can_manage %>
<% cc, non_cc = Course.licenses.map { |id, attrs| [attrs[:readable_license], id]}.partition{|n, id| id.start_with?('cc')} %>
<% cc, non_cc = Course.licenses.map { |id, attrs| [attrs[:readable_license].call, id]}.partition{|n, id| id.start_with?('cc')} %>
<select name="course[license]" id="course_license">
<%= options_for_select(non_cc, @context.license) %>
<%= grouped_options_for_select([[t("Creative Commons Licenses"), cc]], @context.license) %>

View File

@ -47,7 +47,7 @@
:en => "Content License",
:class => "control-label" %>
<div class="controls">
<% cc, non_cc = Course.licenses.map { |id, attrs| [attrs[:readable_license], id]}.partition{|n, id| id.start_with?('cc')} %>
<% cc, non_cc = Course.licenses.map { |id, attrs| [attrs[:readable_license].call, id]}.partition{|n, id| id.start_with?('cc')} %>
<select name="course[license]" id="course_license" class="input-xlarge">
<%= options_for_select(non_cc) %>
<%= grouped_options_for_select([[t("Creative Commons Licenses"), cc]]) %>

View File

@ -109,7 +109,7 @@ module CC
node.lomimscc :value, "yes"
end
rights.lomimscc :description do |desc|
desc.lomimscc :string, "#{course.license_data[:readable_license]} - #{course.license_data[:license_url]}"
desc.lomimscc :string, "#{course.readable_license} - #{course.license_data[:license_url]}"
end
end
end

View File

@ -128,7 +128,7 @@ module QTI
node.imsmd :value, "yes"
end
rights.imsmd :description do |desc|
desc.imsmd :string, "#{course.license_data[:readable_license]} - #{course.license_data[:license_url]}"
desc.imsmd :string, "#{course.readable_license} - #{course.license_data[:license_url]}"
end
end
end

View File

@ -20,54 +20,64 @@ module ContentLicenses
base.extend ContentLicenses::ClassMethods
end
LICENSES = ActiveSupport::OrderedHash[
'private',
{
:readable_license =>
-> { I18n.t('#cc.private', 'Private (Copyrighted)') },
:license_url => "http://en.wikipedia.org/wiki/Copyright"
},
'public_domain',
{
:readable_license =>
-> { I18n.t('#cc.public_domain', 'Public Domain') },
:license_url => "http://en.wikipedia.org/wiki/Public_domain"
},
'cc_by',
{
:readable_license =>
-> { I18n.t('#cc.by', 'CC Attribution') },
:license_url => "http://creativecommons.org/licenses/by/4.0"
},
'cc_by_sa',
{
:readable_license =>
-> { I18n.t('#cc.by_sa', 'CC Attribution Share Alike') },
:license_url => "http://creativecommons.org/licenses/by-sa/4.0"
},
'cc_by_nc',
{
:readable_license =>
-> { I18n.t('#cc.by_nc', 'CC Attribution Non-Commercial') },
:license_url => "http://creativecommons.org/licenses/by-nc/4.0"
},
'cc_by_nc_sa',
{
:readable_license =>
-> { I18n.t('#cc.by_nc_sa', 'CC Attribution Non-Commercial Share Alike')},
:license_url => "http://creativecommons.org/licenses/by-nc-sa/4.0"
},
'cc_by_nd',
{
:readable_license =>
-> { I18n.t('#cc.by_nd', 'CC Attribution No Derivatives') },
:license_url => "http://creativecommons.org/licenses/by-nd/4.0"
},
'cc_by_nc_nd',
{
:readable_license =>
-> { I18n.t('#cc.by_nc_nd', 'CC Attribution Non-Commercial No Derivatives') },
:license_url => "http://creativecommons.org/licenses/by-nc-nd/4.0/"
}
].freeze
module ClassMethods
def licenses
ActiveSupport::OrderedHash[
'private',
{
:readable_license => t('#cc.private', 'Private (Copyrighted)'),
:license_url => "http://en.wikipedia.org/wiki/Copyright"
},
'public_domain',
{
:readable_license => t('#cc.public_domain', 'Public Domain'),
:license_url => "http://en.wikipedia.org/wiki/Public_domain"
},
'cc_by',
{
:readable_license => t('#cc.by', 'CC Attribution'),
:license_url => "http://creativecommons.org/licenses/by/4.0"
},
'cc_by_sa',
{
:readable_license => t('#cc.by_sa', 'CC Attribution Share Alike'),
:license_url => "http://creativecommons.org/licenses/by-sa/4.0"
},
'cc_by_nc',
{
:readable_license => t('#cc.by_nc', 'CC Attribution Non-Commercial'),
:license_url => "http://creativecommons.org/licenses/by-nc/4.0"
},
'cc_by_nc_sa',
{
:readable_license => t('#cc.by_nc_sa', 'CC Attribution Non-Commercial Share Alike'),
:license_url => "http://creativecommons.org/licenses/by-nc-sa/4.0"
},
'cc_by_nd',
{
:readable_license => t('#cc.by_nd', 'CC Attribution No Derivatives'),
:license_url => "http://creativecommons.org/licenses/by-nd/4.0"
},
'cc_by_nc_nd',
{
:readable_license => t('#cc.by_nc_nd', 'CC Attribution Non-Commercial No Derivatives'),
:license_url => "http://creativecommons.org/licenses/by-nc-nd/4.0/"
}
]
ContentLicenses::LICENSES
end
def public_license?(license)
license != 'private'
end
end
end
end

View File

@ -40,7 +40,7 @@ describe UsageRightsController, type: :request do
it "should list licenses" do
json = api_call(:get, "/api/v1/courses/#{@course.id}/content_licenses",
{ controller: 'usage_rights', action: 'licenses', course_id: @course.to_param, format: 'json'})
expect(json).to match_array(UsageRights.licenses.map { |license, data| { 'id' => license, 'name' => data[:readable_license], 'url' => data[:license_url] } })
expect(json).to match_array(UsageRights.licenses.map { |license, data| { 'id' => license, 'name' => data[:readable_license].call, 'url' => data[:license_url] } })
end
end
@ -202,7 +202,7 @@ describe UsageRightsController, type: :request do
it "should list licenses" do
json = api_call(:get, "/api/v1/users/#{@user.id}/content_licenses",
{ controller: 'usage_rights', action: 'licenses', user_id: @user.to_param, format: 'json'})
expect(json).to match_array(UsageRights.licenses.map { |license, data| { 'id' => license, 'name' => data[:readable_license], 'url' => data[:license_url] } })
expect(json).to match_array(UsageRights.licenses.map { |license, data| { 'id' => license, 'name' => data[:readable_license].call, 'url' => data[:license_url] } })
end
it "should set usage rights" do
@ -223,7 +223,7 @@ describe UsageRightsController, type: :request do
it "should list licenses" do
json = api_call(:get, "/api/v1/groups/#{@group.id}/content_licenses",
{ controller: 'usage_rights', action: 'licenses', group_id: @group.to_param, format: 'json'})
expect(json).to match_array(UsageRights.licenses.map { |license, data| { 'id' => license, 'name' => data[:readable_license], 'url' => data[:license_url] } })
expect(json).to match_array(UsageRights.licenses.map { |license, data| { 'id' => license, 'name' => data[:readable_license].call, 'url' => data[:license_url] } })
end
it "should set usage rights" do