Create usage rights type

refs VICE-3852
flag=discussion_create

Test Plan
1. in graphiql navigate to an attachment
2. Verify the UsageRights option appears
3. Verify that the data is correctly returned

Change-Id: Ideff50c18723395b6970bff18b45a9ce01c79cf3
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/332332
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
Reviewed-by: Omar Soto-Fortuño <omar.soto@instructure.com>
Product-Review: Omar Soto-Fortuño <omar.soto@instructure.com>
QA-Review: Chawn Neal <chawn.neal@instructure.com>
This commit is contained in:
Jason Gillett 2023-11-07 14:34:05 -07:00
parent 742ac05ca5
commit f1abd78aef
7 changed files with 99 additions and 0 deletions

View File

@ -94,6 +94,7 @@ class CanvasSchema < GraphQL::Schema
when ContextExternalTool then Types::ExternalToolType
when Setting then Types::InternalSettingType
when AssessmentRequest then Types::AssessmentRequestType
when UsageRights then Types::UsageRightsType
end
end

View File

@ -245,6 +245,12 @@ module GraphQLNodeLoader
record
end
when "UsageRights"
Loaders::IDLoader.for(UsageRights).load(id).then do |usage_rights|
next unless usage_rights.context.grants_right?(ctx[:current_user], :read)
usage_rights
end
else
raise UnsupportedTypeError, "don't know how to load #{type}"
end

View File

@ -57,6 +57,9 @@ module Types
authenticated_thumbnail_url(object)
end
field :usage_rights, UsageRightsType, null: true
delegate :usage_rights, to: :object
field :url, Types::UrlType, null: true
def url
return if object.locked_for?(current_user, check_policies: true)

View File

@ -48,6 +48,7 @@ class Types::LegacyNodeType < Types::BaseEnum
value "Section"
value "Submission"
value "Term"
value "UsageRights"
value "User"
# # TODO: seems like we should be able to dynamically generate the types that

View File

@ -0,0 +1,35 @@
# frozen_string_literal: true
#
# Copyright (C) 2023 - present Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
#
module Types
class UsageRightsType < ApplicationObjectType
graphql_name "UsageRights"
implements GraphQL::Types::Relay::Node
implements Interfaces::LegacyIDInterface
global_id_field :id
field :use_justification, String, null: true
field :license, String, null: true
field :legal_copyright, String, null: true
end
end

View File

@ -0,0 +1,47 @@
# frozen_string_literal: true
#
# Copyright (C) 2023 - present Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
#
require_relative "../graphql_spec_helper"
describe Types::UsageRightsType do
let!(:account) { Account.create! }
let!(:course) { account.courses.create! }
let!(:usage_rights) { course.usage_rights.create!(legal_copyright: "(C) 2012 Initrode", use_justification: "creative_commons", license: "cc_by_sa") }
let!(:teacher) { course.enroll_teacher(User.create!, enrollment_state: "active").user }
let(:usage_rights_type) { GraphQLTypeTester.new(usage_rights, current_user: teacher) }
describe "fields" do
it "use_justification" do
expect(usage_rights_type.resolve("useJustification")).to eq usage_rights.use_justification
end
it "license" do
expect(usage_rights_type.resolve("license")).to eq usage_rights.license
end
it "legal_copyright" do
expect(usage_rights_type.resolve("legalCopyright")).to eq usage_rights.legal_copyright
end
it "_id" do
expect(usage_rights_type.resolve("_id")).to eq usage_rights.id.to_s
end
end
end

View File

@ -221,6 +221,9 @@
{
"name": "Term"
},
{
"name": "UsageRights"
},
{
"name": "User"
}
@ -404,6 +407,9 @@
{
"name": "Term"
},
{
"name": "UsageRights"
},
{
"name": "User"
}