-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
67 changed files
with
1,103 additions
and
218 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# This class is only for internal use and is not exposed to the public since it may include reports for | ||
# files that we don't own (at Zenodo) and would only be used by our SensitiveData checker or perhaps a view | ||
# and limited to roles that can access | ||
|
||
# expect URLs to look like /api/v2/files/<file-id>/sensitiveDataReport | ||
# and do only bare output of data for our own use. Only enable PUT and GET | ||
module StashApi | ||
class ExternalReportsController < ApiApplicationController | ||
|
||
before_action :require_json_headers | ||
before_action :force_json_content_type | ||
before_action :require_file # this is different for this than for files | ||
before_action :doorkeeper_authorize!, only: %i[update] | ||
before_action :require_api_user, only: %i[update] | ||
before_action :optional_api_user, only: %i[show] | ||
before_action :require_viewable_report, only: %i[show] | ||
before_action :require_permission, only: %i[update] | ||
before_action :require_correct_status, only: %i[update] | ||
|
||
# GET | ||
private | ||
|
||
def require_file | ||
@stash_file = StashEngine::GenericFile.where(id: params[:file_id]).first | ||
@resource = @stash_file&.resource # for require_permission to use | ||
render json: { error: 'not-found' }.to_json, status: 404 if @stash_file.nil? || @resource.nil? | ||
end | ||
|
||
def require_viewable_report | ||
@report = report_object | ||
render json: { error: 'not-found' }.to_json, status: 404 if @report.nil? || | ||
!@stash_file.resource.may_view?(ui_user: @user) | ||
end | ||
|
||
def require_correct_status | ||
return if statuses.include?(params[:status]) | ||
|
||
render json: { error: 'incorrect status set' }.to_json, status: 400 | ||
end | ||
|
||
def report_object | ||
raise NotImplementedError, 'Subclasses must implement report_object' | ||
end | ||
|
||
def statuses | ||
raise NotImplementedError, 'Subclasses must implement report_object' | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
app/controllers/stash_api/sensitive_data_reports_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# This class is only for internal use and is not exposed to the public since it may include reports for | ||
# files that we don't own (at Zenodo) and would only be used by our SensitiveData checker or perhaps a view | ||
# and limited to roles that can access | ||
|
||
# expect URLs to look like /api/v2/files/<file-id>/sensitiveDataReport | ||
# and do only bare output of data for our own use. Only enable PUT and GET | ||
module StashApi | ||
class SensitiveDataReportsController < ExternalReportsController | ||
# GET | ||
def show | ||
@api_report = StashApi::SensitiveDataReport.new(file_obj: @stash_file, result_obj: @report) | ||
render json: @api_report.metadata | ||
end | ||
|
||
# PUT | ||
def update | ||
# only json for report and status will be updated, the rest is automatically updated | ||
report = @stash_file.sensitive_data_report | ||
report = StashEngine::SensitiveDataReport.new(generic_file_id: @stash_file.id) if report.nil? | ||
report.update(report: params[:report], status: params[:status]) | ||
@api_report = StashApi::SensitiveDataReport.new(file_obj: @stash_file, result_obj: report) | ||
render json: @api_report.metadata | ||
end | ||
|
||
private | ||
|
||
def report_object | ||
@stash_file&.sensitive_data_report | ||
end | ||
|
||
def statuses | ||
StashEngine::SensitiveDataReport.statuses.keys | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative 'presenter' | ||
module StashApi | ||
class SensitiveDataReport | ||
include Presenter | ||
|
||
def initialize(file_obj:, result_obj:) | ||
@se_data_file = file_obj | ||
@resource = @se_data_file.resource | ||
@se_report = result_obj | ||
end | ||
|
||
def metadata | ||
{ _links: links }.merge(report: @se_report.report, | ||
createdAt: @se_report.created_at, | ||
updatedAt: @se_report.updated_at, | ||
status: @se_report.status).recursive_compact | ||
end | ||
|
||
def links | ||
basic_links.compact.merge(stash_curie) | ||
end | ||
|
||
def parent_version | ||
@version ||= Version.new(resource_id: @se_data_file.resource_id) | ||
end | ||
|
||
private | ||
|
||
def basic_links | ||
{ | ||
self: { href: api_url_helper.file_sensitive_data_report_path(@se_data_file.id) }, | ||
'stash:dataset': { href: parent_version.parent_dataset.self_path }, | ||
'stash:version': { href: parent_version.self_path }, | ||
'stash:files': { href: parent_version.files_path } | ||
} | ||
end | ||
end | ||
end |
Oops, something went wrong.