canvas-lms/lib/services/rich_content.rb

65 lines
2.0 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
#
# Copyright (C) 2015 - 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 Services
class RichContent
def self.env_for(user: nil, domain: nil, real_user: nil, context: nil)
env_hash = service_settings.dup
if user && domain
begin
env_hash[:JWT] = Canvas::Security::ServicesJwt.for_user(
domain,
user,
context: context,
real_user: real_user,
workflows: [:rich_content, :ui]
)
rescue Canvas::Security::InvalidJwtKey => exception
Canvas::Errors.capture_exception(:jwt, exception)
env_hash[:JWT] = "InvalidJwtKey"
end
end
# TODO: Remove once rich content service pull from jwt
env_hash[:RICH_CONTENT_CAN_UPLOAD_FILES] = (
user &&
context &&
context.grants_any_right?(user, :manage_files, :manage_files_add)
) || false
env_hash
end
class << self
private
add granular permissions for course files Note: we'll want to re-run the data fix-up when we're ready to turn on the feature flag permanently; in hopes to capture any differences made to course files permissions between now and then. Modified the files_controller quota and api_quota permission checks to make them more lenient in regards to accepting any or all of the files permissions role overrides. This allows legacy grouping and new granularized files permissions to live in harmony and be modified without causing unauthorized errors on the quota resource. This commit will cover the backend permissions required to granularize files / folders permission calls, however there will be a follow-up ps to clean up the course file page to hide elements the user might not be authorized to use. closes FOO-130 refs FOO-1501 flag = granular_permissions_course_files [fsc-max-nodes=18] [fsc-timeout=30] Test Plan: - Run the migration and make sure there are no errors - With the granular_permissions_course_files FF turned off, course sections and REST API should work the same with this patch set checked out as it does in beta/production - Some things to check: * How it acts as a teacher, student, and public user in course files/folders and personal files/folders with the various settings above toggled to different states * How it acts as a teacher, student, and public user in discussions, modules, content migrations/import/exports (RCE should behave similarly throughout the site) - With the granular_permissions_course_files feature flag turned on course files/folders and REST API should work as expected. The same list checked above should be done so again, but this time: * Should only be able to upload or add folders if the Course Files - add permission is enabled for the user's role * Should only be able to manage file access, usage rights, move, or rename course files/folders if the Course Files - edit permission is enabled for the user's role • Check Toolbar header at the top of Course files • Check Cog (hamburger menu) to the right of each file/folder • Check Usage Rights Indicator under usage rights column that can be found in course and group file pages. This can be enabled under course settings if not available * Should only be able to delete course files/folders if the Course Files - delete permission is enabled for the user's role * Any given user/role should have full access to their respective personal files/folders regardless of granted permissions. The same also applies to a group context with some caveats • Should not be able to modify file access in a group context • Should not be able to modify usage rights in personal files * A student enrollment not granted any file permissions (the default) should only be able to _view_ and _download_ files unless granted additional access from an authorizing role * REST API works as expected * UI works as expected with no additional javascript errors Change-Id: Ieb2d10915c274959e8da4c623f7aba11d3540c2b Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/253777 Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com> QA-Review: Simon Williams <simon@instructure.com> Product-Review: August Thornton <august@instructure.com> Reviewed-by: Michael Ziwisky <mziwisky@instructure.com>
2020-11-26 06:51:02 +08:00
def service_settings
add granular permissions for course files Note: we'll want to re-run the data fix-up when we're ready to turn on the feature flag permanently; in hopes to capture any differences made to course files permissions between now and then. Modified the files_controller quota and api_quota permission checks to make them more lenient in regards to accepting any or all of the files permissions role overrides. This allows legacy grouping and new granularized files permissions to live in harmony and be modified without causing unauthorized errors on the quota resource. This commit will cover the backend permissions required to granularize files / folders permission calls, however there will be a follow-up ps to clean up the course file page to hide elements the user might not be authorized to use. closes FOO-130 refs FOO-1501 flag = granular_permissions_course_files [fsc-max-nodes=18] [fsc-timeout=30] Test Plan: - Run the migration and make sure there are no errors - With the granular_permissions_course_files FF turned off, course sections and REST API should work the same with this patch set checked out as it does in beta/production - Some things to check: * How it acts as a teacher, student, and public user in course files/folders and personal files/folders with the various settings above toggled to different states * How it acts as a teacher, student, and public user in discussions, modules, content migrations/import/exports (RCE should behave similarly throughout the site) - With the granular_permissions_course_files feature flag turned on course files/folders and REST API should work as expected. The same list checked above should be done so again, but this time: * Should only be able to upload or add folders if the Course Files - add permission is enabled for the user's role * Should only be able to manage file access, usage rights, move, or rename course files/folders if the Course Files - edit permission is enabled for the user's role • Check Toolbar header at the top of Course files • Check Cog (hamburger menu) to the right of each file/folder • Check Usage Rights Indicator under usage rights column that can be found in course and group file pages. This can be enabled under course settings if not available * Should only be able to delete course files/folders if the Course Files - delete permission is enabled for the user's role * Any given user/role should have full access to their respective personal files/folders regardless of granted permissions. The same also applies to a group context with some caveats • Should not be able to modify file access in a group context • Should not be able to modify usage rights in personal files * A student enrollment not granted any file permissions (the default) should only be able to _view_ and _download_ files unless granted additional access from an authorizing role * REST API works as expected * UI works as expected with no additional javascript errors Change-Id: Ieb2d10915c274959e8da4c623f7aba11d3540c2b Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/253777 Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com> QA-Review: Simon Williams <simon@instructure.com> Product-Review: August Thornton <august@instructure.com> Reviewed-by: Michael Ziwisky <mziwisky@instructure.com>
2020-11-26 06:51:02 +08:00
settings = Canvas::DynamicSettings.find('rich-content-service', default_ttl: 5.minutes)
{
RICH_CONTENT_APP_HOST: settings['app-host'],
RICH_CONTENT_SKIP_SIDEBAR: settings['skip-sidebar']
}
rescue Diplomat::KeyNotFound,
add granular permissions for course files Note: we'll want to re-run the data fix-up when we're ready to turn on the feature flag permanently; in hopes to capture any differences made to course files permissions between now and then. Modified the files_controller quota and api_quota permission checks to make them more lenient in regards to accepting any or all of the files permissions role overrides. This allows legacy grouping and new granularized files permissions to live in harmony and be modified without causing unauthorized errors on the quota resource. This commit will cover the backend permissions required to granularize files / folders permission calls, however there will be a follow-up ps to clean up the course file page to hide elements the user might not be authorized to use. closes FOO-130 refs FOO-1501 flag = granular_permissions_course_files [fsc-max-nodes=18] [fsc-timeout=30] Test Plan: - Run the migration and make sure there are no errors - With the granular_permissions_course_files FF turned off, course sections and REST API should work the same with this patch set checked out as it does in beta/production - Some things to check: * How it acts as a teacher, student, and public user in course files/folders and personal files/folders with the various settings above toggled to different states * How it acts as a teacher, student, and public user in discussions, modules, content migrations/import/exports (RCE should behave similarly throughout the site) - With the granular_permissions_course_files feature flag turned on course files/folders and REST API should work as expected. The same list checked above should be done so again, but this time: * Should only be able to upload or add folders if the Course Files - add permission is enabled for the user's role * Should only be able to manage file access, usage rights, move, or rename course files/folders if the Course Files - edit permission is enabled for the user's role • Check Toolbar header at the top of Course files • Check Cog (hamburger menu) to the right of each file/folder • Check Usage Rights Indicator under usage rights column that can be found in course and group file pages. This can be enabled under course settings if not available * Should only be able to delete course files/folders if the Course Files - delete permission is enabled for the user's role * Any given user/role should have full access to their respective personal files/folders regardless of granted permissions. The same also applies to a group context with some caveats • Should not be able to modify file access in a group context • Should not be able to modify usage rights in personal files * A student enrollment not granted any file permissions (the default) should only be able to _view_ and _download_ files unless granted additional access from an authorizing role * REST API works as expected * UI works as expected with no additional javascript errors Change-Id: Ieb2d10915c274959e8da4c623f7aba11d3540c2b Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/253777 Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com> QA-Review: Simon Williams <simon@instructure.com> Product-Review: August Thornton <august@instructure.com> Reviewed-by: Michael Ziwisky <mziwisky@instructure.com>
2020-11-26 06:51:02 +08:00
Canvas::DynamicSettings::ConsulError => e
Canvas::Errors.capture_exception(:rce_flag, e)
add granular permissions for course files Note: we'll want to re-run the data fix-up when we're ready to turn on the feature flag permanently; in hopes to capture any differences made to course files permissions between now and then. Modified the files_controller quota and api_quota permission checks to make them more lenient in regards to accepting any or all of the files permissions role overrides. This allows legacy grouping and new granularized files permissions to live in harmony and be modified without causing unauthorized errors on the quota resource. This commit will cover the backend permissions required to granularize files / folders permission calls, however there will be a follow-up ps to clean up the course file page to hide elements the user might not be authorized to use. closes FOO-130 refs FOO-1501 flag = granular_permissions_course_files [fsc-max-nodes=18] [fsc-timeout=30] Test Plan: - Run the migration and make sure there are no errors - With the granular_permissions_course_files FF turned off, course sections and REST API should work the same with this patch set checked out as it does in beta/production - Some things to check: * How it acts as a teacher, student, and public user in course files/folders and personal files/folders with the various settings above toggled to different states * How it acts as a teacher, student, and public user in discussions, modules, content migrations/import/exports (RCE should behave similarly throughout the site) - With the granular_permissions_course_files feature flag turned on course files/folders and REST API should work as expected. The same list checked above should be done so again, but this time: * Should only be able to upload or add folders if the Course Files - add permission is enabled for the user's role * Should only be able to manage file access, usage rights, move, or rename course files/folders if the Course Files - edit permission is enabled for the user's role • Check Toolbar header at the top of Course files • Check Cog (hamburger menu) to the right of each file/folder • Check Usage Rights Indicator under usage rights column that can be found in course and group file pages. This can be enabled under course settings if not available * Should only be able to delete course files/folders if the Course Files - delete permission is enabled for the user's role * Any given user/role should have full access to their respective personal files/folders regardless of granted permissions. The same also applies to a group context with some caveats • Should not be able to modify file access in a group context • Should not be able to modify usage rights in personal files * A student enrollment not granted any file permissions (the default) should only be able to _view_ and _download_ files unless granted additional access from an authorizing role * REST API works as expected * UI works as expected with no additional javascript errors Change-Id: Ieb2d10915c274959e8da4c623f7aba11d3540c2b Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/253777 Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com> QA-Review: Simon Williams <simon@instructure.com> Product-Review: August Thornton <august@instructure.com> Reviewed-by: Michael Ziwisky <mziwisky@instructure.com>
2020-11-26 06:51:02 +08:00
{ RICH_CONTENT_APP_HOST: 'error' }
end
end
end
end