2012-08-21 07:41:42 +08:00
|
|
|
#
|
2017-04-28 03:32:21 +08:00
|
|
|
# Copyright (C) 2012 - present Instructure, Inc.
|
2012-08-21 07:41:42 +08:00
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
#
|
2017-04-28 03:32:21 +08:00
|
|
|
# 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/>.
|
2012-08-21 07:41:42 +08:00
|
|
|
#
|
|
|
|
|
|
|
|
class CrocodocSessionsController < ApplicationController
|
2017-02-09 01:08:10 +08:00
|
|
|
before_action :require_user
|
2014-06-05 06:08:56 +08:00
|
|
|
include HmacHelper
|
2012-08-21 07:41:42 +08:00
|
|
|
|
2014-06-05 06:08:56 +08:00
|
|
|
def show
|
|
|
|
blob = extract_blob(params[:hmac], params[:blob],
|
2014-06-11 03:47:21 +08:00
|
|
|
"user_id" => @current_user.global_id,
|
|
|
|
"type" => "crocodoc")
|
2014-06-05 06:08:56 +08:00
|
|
|
attachment = Attachment.find(blob["attachment_id"])
|
2012-08-21 07:41:42 +08:00
|
|
|
|
|
|
|
if attachment.crocodoc_available?
|
2012-09-28 03:26:11 +08:00
|
|
|
annotations = params[:annotations] ?
|
|
|
|
value_to_boolean(params[:annotations]) :
|
|
|
|
true
|
|
|
|
|
2012-08-21 07:41:42 +08:00
|
|
|
crocodoc = attachment.crocodoc_document
|
2014-06-11 14:49:14 +08:00
|
|
|
url = crocodoc.session_url(:user => @current_user,
|
2015-08-26 06:36:10 +08:00
|
|
|
:annotations => annotations,
|
2017-06-24 03:01:22 +08:00
|
|
|
:enable_annotations => blob["enable_annotations"],
|
2017-06-29 04:23:41 +08:00
|
|
|
:moderated_grading_whitelist => blob["moderated_grading_whitelist"])
|
2016-01-07 03:44:55 +08:00
|
|
|
|
|
|
|
# For the purposes of reporting student viewership, we only
|
|
|
|
# care if the original attachment owner is looking
|
2016-09-23 03:06:28 +08:00
|
|
|
# Depending on how the attachment came to exist that might be
|
|
|
|
# either the context of the attachment or the attachments' user
|
|
|
|
if (attachment.context == @current_user) || (attachment.user == @current_user)
|
|
|
|
attachment.touch(:viewed_at)
|
|
|
|
end
|
2016-01-07 03:44:55 +08:00
|
|
|
|
2014-06-11 14:49:14 +08:00
|
|
|
redirect_to url
|
2012-08-21 07:41:42 +08:00
|
|
|
else
|
2017-03-15 01:48:55 +08:00
|
|
|
render :plain => "Not found", :status => :not_found
|
2012-08-21 07:41:42 +08:00
|
|
|
end
|
2014-06-05 06:08:56 +08:00
|
|
|
|
|
|
|
rescue HmacHelper::Error
|
2017-03-15 01:48:55 +08:00
|
|
|
render :plain => 'unauthorized', :status => :unauthorized
|
2014-10-08 12:23:49 +08:00
|
|
|
rescue Timeout::Error
|
2017-03-15 01:48:55 +08:00
|
|
|
render :plain => "Service is currently unavailable. Try again later.",
|
2014-10-08 12:23:49 +08:00
|
|
|
:status => :service_unavailable
|
2012-08-21 07:41:42 +08:00
|
|
|
end
|
|
|
|
end
|