-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[F] Implement backend collection management
[Completes #281]
- Loading branch information
Showing
74 changed files
with
3,650 additions
and
897 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
class CollectionAuthorizer < ApplicationAuthorizer | ||
|
||
def self.updatable_by?(user) | ||
user.admin? | ||
end | ||
|
||
def self.readable_by?(_user) | ||
true | ||
end | ||
|
||
def self.creatable_by?(user) | ||
user.admin? | ||
end | ||
|
||
def self.deletable_by?(user) | ||
user.admin? | ||
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
43 changes: 43 additions & 0 deletions
43
api/app/controllers/api/v1/projects/relationships/collections_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,43 @@ | ||
module Api | ||
module V1 | ||
module Projects | ||
module Relationships | ||
# Responds with resources in a project | ||
class CollectionsController < ApplicationController | ||
|
||
before_action :set_project, only: [:index, :create] | ||
|
||
resourceful! Collection, authorize_options: { except: [:index] } do | ||
Collection.filter( | ||
with_pagination!(collection_filter_params), | ||
scope: @project.collections | ||
) | ||
end | ||
|
||
def index | ||
@collections = load_collections | ||
render_multiple_resources(@collections, each_serializer: CollectionSerializer) | ||
end | ||
|
||
def create | ||
@collection = ::Updaters::Collection.new(collection_params) | ||
.update(@project.collections.new) | ||
@collection.save | ||
authorize_action_for @collection | ||
location = api_v1_project_relationships_collections_url( | ||
@collection, | ||
project_id: @project.id | ||
) | ||
render_single_resource @collection, location: location | ||
end | ||
|
||
private | ||
|
||
def set_project | ||
@project = Project.friendly.find(params[:project_id]) | ||
end | ||
end | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module Updaters | ||
# Updates a Collection model from JSON-API style params | ||
class Collection | ||
include ::Updaters | ||
|
||
def attachment_fields | ||
[ | ||
:thumbnail | ||
] | ||
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,66 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe "Collections API", type: :request do | ||
|
||
include_context("authenticated request") | ||
include_context("param helpers") | ||
|
||
let(:collection) { FactoryGirl.create(:collection) } | ||
|
||
describe "sends a list of collections" do | ||
describe "the response" do | ||
it "has a 200 status code" do | ||
get api_v1_collections_path | ||
expect(response).to have_http_status(200) | ||
end | ||
end | ||
end | ||
|
||
describe "updates a collection" do | ||
|
||
let(:path) { api_v1_collection_path(collection) } | ||
|
||
context "when the user is an admin" do | ||
|
||
let(:headers) { admin_headers } | ||
|
||
describe "the response" do | ||
context "body" do | ||
it("contains the updated title") { expect_updated_param("title", "some title") } | ||
it("contains the updated description") { expect_updated_param("description", "some description") } | ||
end | ||
|
||
it "has a 200 OK status code" do | ||
patch path, headers: headers, params: json_payload() | ||
expect(response).to have_http_status(200) | ||
end | ||
end | ||
end | ||
|
||
describe "destroys a collection" do | ||
|
||
let(:path) { api_v1_collection_path(collection) } | ||
|
||
context "when the user is an admin" do | ||
|
||
let(:headers) { admin_headers } | ||
|
||
it "has a 204 NO CONTENT status code" do | ||
delete path, headers: headers | ||
expect(response).to have_http_status(204) | ||
end | ||
end | ||
|
||
context "when the user is a reader" do | ||
|
||
let(:headers) { reader_headers } | ||
|
||
it "has a 403 FORBIDDEN status code" do | ||
delete path, headers: headers | ||
expect(response).to have_http_status(403) | ||
end | ||
end | ||
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
Oops, something went wrong.