parent
33fc27ffd1
commit
68f0e91259
14 changed files with 46 additions and 7 deletions
|
@ -124,7 +124,7 @@ class MapsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_map_params
|
def create_map_params
|
||||||
params.permit(:name, :desc, :permission)
|
params.permit(:name, :desc, :permission, :source_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_map_params
|
def update_map_params
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
class Map < ApplicationRecord
|
class Map < ApplicationRecord
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
|
belongs_to :source, class_name: :Map
|
||||||
|
|
||||||
has_many :topicmappings, -> { Mapping.topicmapping }, class_name: :Mapping, dependent: :destroy
|
has_many :topicmappings, -> { Mapping.topicmapping }, class_name: :Mapping, dependent: :destroy
|
||||||
has_many :synapsemappings, -> { Mapping.synapsemapping }, class_name: :Mapping, dependent: :destroy
|
has_many :synapsemappings, -> { Mapping.synapsemapping }, class_name: :Mapping, dependent: :destroy
|
||||||
|
|
|
@ -18,6 +18,7 @@ module Api
|
||||||
def self.embeddable
|
def self.embeddable
|
||||||
{
|
{
|
||||||
user: {},
|
user: {},
|
||||||
|
source: {},
|
||||||
topics: {},
|
topics: {},
|
||||||
synapses: {},
|
synapses: {},
|
||||||
mappings: {},
|
mappings: {},
|
||||||
|
|
5
db/migrate/20161218183817_add_source_to_maps.rb
Normal file
5
db/migrate/20161218183817_add_source_to_maps.rb
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
class AddSourceToMaps < ActiveRecord::Migration[5.0]
|
||||||
|
def change
|
||||||
|
add_reference :maps, :source, foreign_key: {to_table: :maps}
|
||||||
|
end
|
||||||
|
end
|
|
@ -10,7 +10,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 20161216174257) do
|
ActiveRecord::Schema.define(version: 20161218183817) do
|
||||||
|
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
|
@ -151,6 +151,8 @@ ActiveRecord::Schema.define(version: 20161216174257) do
|
||||||
t.string "screenshot_content_type", limit: 255
|
t.string "screenshot_content_type", limit: 255
|
||||||
t.integer "screenshot_file_size"
|
t.integer "screenshot_file_size"
|
||||||
t.datetime "screenshot_updated_at"
|
t.datetime "screenshot_updated_at"
|
||||||
|
t.integer "source_id"
|
||||||
|
t.index ["source_id"], name: "index_maps_on_source_id", using: :btree
|
||||||
t.index ["user_id"], name: "index_maps_on_user_id", using: :btree
|
t.index ["user_id"], name: "index_maps_on_user_id", using: :btree
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -340,5 +342,6 @@ ActiveRecord::Schema.define(version: 20161216174257) do
|
||||||
add_foreign_key "mailboxer_notifications", "mailboxer_conversations", column: "conversation_id", name: "notifications_on_conversation_id"
|
add_foreign_key "mailboxer_notifications", "mailboxer_conversations", column: "conversation_id", name: "notifications_on_conversation_id"
|
||||||
add_foreign_key "mailboxer_receipts", "mailboxer_notifications", column: "notification_id", name: "receipts_on_notification_id"
|
add_foreign_key "mailboxer_receipts", "mailboxer_notifications", column: "notification_id", name: "receipts_on_notification_id"
|
||||||
add_foreign_key "mappings", "users", column: "updated_by_id"
|
add_foreign_key "mappings", "users", column: "updated_by_id"
|
||||||
|
add_foreign_key "maps", "maps", column: "source_id"
|
||||||
add_foreign_key "tokens", "users"
|
add_foreign_key "tokens", "users"
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#type: collection
|
#type: collection
|
||||||
get:
|
get:
|
||||||
is: [ searchable: { searchFields: "name, desc" }, embeddable: { embedFields: "user,topics,synapses,mappings,contributors,collaborators" }, orderable, pageable ]
|
is: [ searchable: { searchFields: "name, desc" }, embeddable: { embedFields: "user,source,topics,synapses,mappings,contributors,collaborators" }, orderable, pageable ]
|
||||||
securedBy: [ null, token, oauth_2_0, cookie ]
|
securedBy: [ null, token, oauth_2_0, cookie ]
|
||||||
queryParameters:
|
queryParameters:
|
||||||
user_id:
|
user_id:
|
||||||
|
@ -23,6 +23,8 @@ post:
|
||||||
description: description
|
description: description
|
||||||
permission:
|
permission:
|
||||||
description: commons, public, or private
|
description: commons, public, or private
|
||||||
|
source_id:
|
||||||
|
description: the id of the map this map is a fork of
|
||||||
screenshot:
|
screenshot:
|
||||||
description: url to a screenshot of the map
|
description: url to a screenshot of the map
|
||||||
contributor_ids:
|
contributor_ids:
|
||||||
|
@ -37,7 +39,7 @@ post:
|
||||||
/{id}:
|
/{id}:
|
||||||
#type: item
|
#type: item
|
||||||
get:
|
get:
|
||||||
is: [ embeddable: { embedFields: "user,topics,synapses,mappings,contributors,collaborators" } ]
|
is: [ embeddable: { embedFields: "user,source,topics,synapses,mappings,contributors,collaborators" } ]
|
||||||
securedBy: [ null, token, oauth_2_0, cookie ]
|
securedBy: [ null, token, oauth_2_0, cookie ]
|
||||||
responses:
|
responses:
|
||||||
200:
|
200:
|
||||||
|
@ -60,6 +62,9 @@ post:
|
||||||
screenshot:
|
screenshot:
|
||||||
description: url to a screenshot of the map
|
description: url to a screenshot of the map
|
||||||
required: false
|
required: false
|
||||||
|
source_id:
|
||||||
|
description: the id of the map this map is a fork of
|
||||||
|
required: false
|
||||||
responses:
|
responses:
|
||||||
200:
|
200:
|
||||||
body:
|
body:
|
||||||
|
@ -81,6 +86,9 @@ post:
|
||||||
screenshot:
|
screenshot:
|
||||||
description: url to a screenshot of the map
|
description: url to a screenshot of the map
|
||||||
required: false
|
required: false
|
||||||
|
source_id:
|
||||||
|
description: the id of the map this map is a fork of
|
||||||
|
required: false
|
||||||
responses:
|
responses:
|
||||||
200:
|
200:
|
||||||
body:
|
body:
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
"created_at": "2016-03-26T08:02:05.379Z",
|
"created_at": "2016-03-26T08:02:05.379Z",
|
||||||
"updated_at": "2016-03-27T07:20:18.047Z",
|
"updated_at": "2016-03-27T07:20:18.047Z",
|
||||||
"user_id": 1234,
|
"user_id": 1234,
|
||||||
|
"source_id": null,
|
||||||
"topic_ids": [
|
"topic_ids": [
|
||||||
58,
|
58,
|
||||||
59
|
59
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
"created_at": "2016-03-26T08:02:05.379Z",
|
"created_at": "2016-03-26T08:02:05.379Z",
|
||||||
"updated_at": "2016-03-27T07:20:18.047Z",
|
"updated_at": "2016-03-27T07:20:18.047Z",
|
||||||
"user_id": 1234,
|
"user_id": 1234,
|
||||||
|
"source_id": null,
|
||||||
"topic_ids": [
|
"topic_ids": [
|
||||||
58,
|
58,
|
||||||
59
|
59
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
"created_at": "2016-03-26T08:02:05.379Z",
|
"created_at": "2016-03-26T08:02:05.379Z",
|
||||||
"updated_at": "2016-03-27T07:20:18.047Z",
|
"updated_at": "2016-03-27T07:20:18.047Z",
|
||||||
"user_id": 1234,
|
"user_id": 1234,
|
||||||
|
"source_id": 2,
|
||||||
"topic_ids": [
|
"topic_ids": [
|
||||||
58,
|
58,
|
||||||
59
|
59
|
||||||
|
|
|
@ -33,6 +33,12 @@
|
||||||
"user": {
|
"user": {
|
||||||
"$ref": "_user.json"
|
"$ref": "_user.json"
|
||||||
},
|
},
|
||||||
|
"source_id": {
|
||||||
|
"$ref": "_optid.json"
|
||||||
|
},
|
||||||
|
"source": {
|
||||||
|
"$ref": "_map.json"
|
||||||
|
},
|
||||||
"topic_ids": {
|
"topic_ids": {
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"items": {
|
"items": {
|
||||||
|
@ -111,6 +117,12 @@
|
||||||
{ "required": [ "user" ] }
|
{ "required": [ "user" ] }
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"oneOf": [
|
||||||
|
{ "required": [ "source_id" ] },
|
||||||
|
{ "required": [ "source" ] }
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"oneOf": [
|
"oneOf": [
|
||||||
{ "required": [ "topic_ids" ] },
|
{ "required": [ "topic_ids" ] },
|
||||||
|
|
3
doc/api/schemas/_optid.json
Normal file
3
doc/api/schemas/_optid.json
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
"type": "integer|nil"
|
||||||
|
}
|
|
@ -61,6 +61,7 @@ const CreateMap = {
|
||||||
if (GlobalUI.lightbox === 'forkmap') {
|
if (GlobalUI.lightbox === 'forkmap') {
|
||||||
self.newMap.set('topicsToMap', self.topicsToMap)
|
self.newMap.set('topicsToMap', self.topicsToMap)
|
||||||
self.newMap.set('synapsesToMap', self.synapsesToMap)
|
self.newMap.set('synapsesToMap', self.synapsesToMap)
|
||||||
|
self.newMap.set('source_id', Active.Map.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
var formId = GlobalUI.lightbox === 'forkmap' ? '#fork_map' : '#new_map'
|
var formId = GlobalUI.lightbox === 'forkmap' ? '#fork_map' : '#new_map'
|
||||||
|
|
|
@ -5,7 +5,8 @@ require 'rails_helper'
|
||||||
RSpec.describe 'maps API', type: :request do
|
RSpec.describe 'maps API', type: :request do
|
||||||
let(:user) { create(:user, admin: true) }
|
let(:user) { create(:user, admin: true) }
|
||||||
let(:token) { create(:token, user: user).token }
|
let(:token) { create(:token, user: user).token }
|
||||||
let(:map) { create(:map, user: user) }
|
let(:source) { create(:map, user: user) }
|
||||||
|
let(:map) { create(:map, user: user, source: source) }
|
||||||
|
|
||||||
describe 'GET /api/v2/maps' do
|
describe 'GET /api/v2/maps' do
|
||||||
it 'returns all maps' do
|
it 'returns all maps' do
|
||||||
|
@ -42,7 +43,7 @@ RSpec.describe 'maps API', type: :request do
|
||||||
|
|
||||||
expect(response).to have_http_status(:success)
|
expect(response).to have_http_status(:success)
|
||||||
expect(response).to match_json_schema(:map)
|
expect(response).to match_json_schema(:map)
|
||||||
expect(Map.count).to eq 2
|
expect(Map.count).to eq 3
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'PATCH /api/v2/maps/:id' do
|
it 'PATCH /api/v2/maps/:id' do
|
||||||
|
@ -56,7 +57,7 @@ RSpec.describe 'maps API', type: :request do
|
||||||
delete "/api/v2/maps/#{map.id}", params: { access_token: token }
|
delete "/api/v2/maps/#{map.id}", params: { access_token: token }
|
||||||
|
|
||||||
expect(response).to have_http_status(:no_content)
|
expect(response).to have_http_status(:no_content)
|
||||||
expect(Map.count).to eq 0
|
expect(Map.count).to eq 1
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'POST /api/v2/maps/:id/stars' do
|
it 'POST /api/v2/maps/:id/stars' do
|
||||||
|
|
|
@ -4,6 +4,7 @@ FactoryGirl.define do
|
||||||
sequence(:name) { |n| "Cool Map ##{n}" }
|
sequence(:name) { |n| "Cool Map ##{n}" }
|
||||||
permission :commons
|
permission :commons
|
||||||
arranged { false }
|
arranged { false }
|
||||||
|
source_id nil
|
||||||
desc ''
|
desc ''
|
||||||
user
|
user
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue