Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IIIF #30 - Manifest #31

Merged
merged 5 commits into from
May 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions app/controllers/api/resources_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Api::ResourcesController < Api::BaseController
before_action :set_defineable_params, only: :index
before_action :validate_new_resource, unless: -> { current_user.admin? }, only: :create
before_action :validate_resource, unless: -> { current_user.admin? }, only: [:update, :destroy]
before_action :validate_resources, unless: -> { current_user.admin? }, only: :index

protected

Expand Down Expand Up @@ -48,4 +49,9 @@ def validate_resource
resource = Resource.find(params[:id])
check_authorization resource.project.organization_id
end

def validate_resources
project = Project.find(params[:project_id])
check_authorization project.organization_id
end
end
19 changes: 18 additions & 1 deletion app/controllers/public/resources_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
class Public::ResourcesController < Api::ResourcesController
# Actions
prepend_before_action :set_project, only: [:create, :update]
prepend_before_action :set_resource, only: [:show, :destroy, :update]
prepend_before_action :set_project_id, only: :index
prepend_before_action :set_resource, only: [:show, :destroy, :update, :manifest]

def manifest
resource = Resource.find(params[:id])
render json: JSON.parse(resource.manifest)
end

protected

Expand All @@ -24,11 +30,22 @@ def render_unauthorized(errors)

def set_project
project = Project.find_by_uuid(params[:resource][:project_id])
render_unauthorized I18n.t('errors.unauthorized') and return if project.nil?

params[:resource][:project_id] = project.id
end

def set_project_id
project = Project.find_by_uuid(params[:project_id])
render_unauthorized I18n.t('errors.unauthorized') and return if project.nil?

params[:project_id] = project.id
end

def set_resource
resource = Resource.find_by_uuid(params[:id])
render_unauthorized I18n.t('errors.unauthorized') and return if resource.nil?

params[:id] = resource.id
end
end
31 changes: 31 additions & 0 deletions client/src/components/ReadOnlyField.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// @flow

import React from 'react';

type Props = {
label?: string,
value: string
};

const ReadOnlyField = (props: Props) => (
<div
className='field'
>
{ props.label && (
<label
htmlFor='read-only-element'
>
{ props.label }
</label>
)}
<div
id='read-only-element'
className='ui input'
role='textbox'
>
{ props.value }
</div>
</div>
);

export default ReadOnlyField;
3 changes: 2 additions & 1 deletion client/src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@
"exif": "View Info"
},
"labels": {
"content": "Content"
"content": "Content",
"uuid": "Unique identifier"
}
},
"ResourceExifModal": {
Expand Down
21 changes: 5 additions & 16 deletions client/src/pages/Project.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import AuthenticationService from '../services/Authentication';
import Organization from '../transforms/Organization';
import OrganizationsService from '../services/Organizations';
import ProjectsService from '../services/Projects';
import ReadOnlyField from '../components/ReadOnlyField';
import SimpleEditPage from '../components/SimpleEditPage';
import withEditPage from '../hooks/EditPage';

Expand Down Expand Up @@ -97,22 +98,10 @@ const ProjectForm = withTranslation()((props) => {
required={props.isRequired('description')}
value={props.item.description}
/>
<div
className='field'
>
<label
htmlFor='uuid-element'
>
{ props.t('Project.labels.uuid') }
</label>
<div
id='uuid-element'
className='ui input'
role='textbox'
>
{ props.item.uuid }
</div>
</div>
<ReadOnlyField
label={props.t('Project.labels.uuid')}
value={props.item.uuid}
/>
</SimpleEditPage.Tab>
<SimpleEditPage.Tab
key='fields'
Expand Down
5 changes: 5 additions & 0 deletions client/src/pages/Resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { withTranslation } from 'react-i18next';
import { useParams } from 'react-router-dom';
import { Button, Form } from 'semantic-ui-react';
import ProjectsService from '../services/Projects';
import ReadOnlyField from '../components/ReadOnlyField';
import ResourceExifModal from '../components/ResourceExifModal';
import ResourcesService from '../services/Resources';
import SimpleEditPage from '../components/SimpleEditPage';
Expand Down Expand Up @@ -110,6 +111,10 @@ const ResourceForm = withTranslation()((props) => {
required={props.isRequired('name')}
value={props.item.name}
/>
<ReadOnlyField
label={props.t('Resource.labels.uuid')}
value={props.item.uuid}
/>
<UserDefinedFieldsForm
data={props.item.user_defined}
defineableId={projectId}
Expand Down
2 changes: 1 addition & 1 deletion client/src/pages/Resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const Resources: ComponentType<any> = () => {
preview={resource.content_thumbnail_url}
/>
)}
renderMeta={() => ''}
renderMeta={(resource) => resource.uuid}
saved={location.state && location.state.saved}
sort={[{
key: 'name',
Expand Down
15 changes: 6 additions & 9 deletions config/initializers/cors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@

# Read more: https://github.com/cyu/rack-cors

# Rails.application.config.middleware.insert_before 0, Rack::Cors do
# allow do
# origins "example.com"
#
# resource "*",
# headers: :any,
# methods: [:get, :post, :put, :patch, :delete, :options, :head]
# end
# end
Rails.application.config.middleware.insert_before 0, Rack::Cors do
allow do
origins '*'
resource '/public/resources/:id/manifest', headers: :any, methods: :get
end
end
6 changes: 5 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
end

namespace :public do
resources :resources, only: [:create, :show, :destroy, :update]
resources :resources, only: [:index, :create, :show, :destroy, :update] do
member do
get :manifest
end
end
end

# Default route for static front-end
Expand Down