ember-arcgis-portal-services
Advanced tools
Comparing version 1.5.0 to 1.5.1
@@ -173,3 +173,23 @@ import { debug } from '@ember/debug'; | ||
}); | ||
}, | ||
/** | ||
* Wrap the options passed to rest-js with auth info and use ember-fetch. | ||
*/ | ||
addOptions (args, portalOpts) { | ||
// use ember-fetch | ||
args.fetch = fetch; | ||
// if portal options are present, they're preferred | ||
if (portalOpts && portalOpts.portalHostname) { | ||
args.portal = `https://${portalOpts.portalHostname}/sharing/rest`; | ||
if (!args.params) { | ||
args.params = {}; | ||
} | ||
args.params.token = portalOpts.token; | ||
} else { | ||
// pass through auth info from the session | ||
args.authentication = this.get('session.authMgr'); | ||
} | ||
return args; | ||
} | ||
}); |
@@ -1,5 +0,14 @@ | ||
import { copy } from '@ember/object/internals'; | ||
import Service from '@ember/service'; | ||
import serviceMixin from '../mixins/service-mixin'; | ||
import fetchImageAsBlob from 'ember-arcgis-portal-services/utils/fetch-image-as-blob'; | ||
import { | ||
searchItems, | ||
getItem, | ||
getItemData, | ||
updateItem, | ||
createItemInFolder, | ||
removeItem, | ||
protectItem, | ||
unprotectItem | ||
} from '@esri/arcgis-rest-items'; | ||
@@ -19,5 +28,4 @@ export default Service.extend(serviceMixin, { | ||
search (form, portalOpts) { | ||
const qs = this.encodeForm(form); | ||
const urlPath = `/search?${qs}&f=json`; | ||
return this.request(urlPath, null, portalOpts); | ||
const args = this.addOptions({ searchForm: form }, portalOpts); | ||
return searchItems(args); | ||
}, | ||
@@ -29,5 +37,4 @@ | ||
getById (itemId, portalOpts) { | ||
const qs = this.encodeForm(this.get('defaultParams')); | ||
const urlPath = `/content/items/${itemId}?${qs}`; | ||
return this.request(urlPath, null, portalOpts); | ||
const args = this.addOptions({}, portalOpts); | ||
return getItem(itemId, args); | ||
}, | ||
@@ -40,5 +47,4 @@ | ||
getDataById (itemId, portalOpts) { | ||
const qs = this.encodeForm(this.get('defaultParams')); | ||
const urlPath = `/content/items/${itemId}/data?${qs}`; | ||
return this.request(urlPath, null, portalOpts); | ||
const args = this.addOptions({}, portalOpts); | ||
return getItemData(itemId, args); | ||
}, | ||
@@ -51,4 +57,4 @@ | ||
update (item, portalOpts) { | ||
const urlPath = `/content/users/${item.owner}/items/${item.id}/update?f=json`; | ||
return this._post(urlPath, item, portalOpts); | ||
const args = this.addOptions({ item, owner: item.owner }, portalOpts); | ||
return updateItem(args); | ||
}, | ||
@@ -61,7 +67,9 @@ | ||
createInFolder (item, folderId, portalOpts) { | ||
let urlPath = `/content/users/${item.owner}/addItem?f=json`; | ||
if (folderId) { | ||
urlPath = `/content/users/${item.owner}/${folderId}/addItem?f=json`; | ||
} | ||
return this._post(urlPath, item, portalOpts); | ||
const args = this.addOptions({ | ||
item, | ||
owner: item.owner, | ||
folder: folderId | ||
}, portalOpts); | ||
return createItemInFolder(args); | ||
}, | ||
@@ -82,14 +90,26 @@ | ||
remove (itemId, owner, portalOpts) { | ||
const urlPath = `/content/users/${owner}/items/${itemId}/delete?f=json`; | ||
return this._post(urlPath, {}, portalOpts); | ||
const args = this.addOptions({ | ||
id: itemId, | ||
owner | ||
}, portalOpts); | ||
return removeItem(args); | ||
}, | ||
protect (itemId, owner, portalOpts) { | ||
const urlPath = `/content/users/${owner}/items/${itemId}/protect?f=json`; | ||
return this._post(urlPath, {}, portalOpts); | ||
const args = this.addOptions({ | ||
id: itemId, | ||
owner | ||
}, portalOpts); | ||
return protectItem(args); | ||
}, | ||
unprotect (itemId, owner, portalOpts) { | ||
const urlPath = `/content/users/${owner}/items/${itemId}/unprotect?f=json`; | ||
return this._post(urlPath, {}, portalOpts); | ||
const args = this.addOptions({ | ||
id: itemId, | ||
owner | ||
}, portalOpts); | ||
return unprotectItem(args); | ||
}, | ||
@@ -232,44 +252,3 @@ | ||
}, portalOpts); | ||
}, | ||
/** | ||
* Extra logic to transform the item prior to POSTing it | ||
*/ | ||
_serializeItem (item) { | ||
let clone = copy(item, true); | ||
// Array items need to become comma delim strings | ||
if (clone.typeKeywords) { | ||
clone.typeKeywords = item.typeKeywords.join(', '); | ||
} | ||
if (clone.tags) { | ||
clone.tags = item.tags.join(', '); | ||
} | ||
// convert .data to .text | ||
if (clone.data) { | ||
clone.text = JSON.stringify(clone.data); | ||
delete clone.data; | ||
} | ||
// Convert properties to a string | ||
if (clone.properties) { | ||
clone.properties = JSON.stringify(clone.properties); | ||
} | ||
if (clone.serviceProxyParams) { | ||
clone.serviceProxyParams = JSON.stringify(clone.serviceProxyParams); | ||
} | ||
return clone; | ||
}, | ||
/** | ||
* Shared logic for POST operations | ||
*/ | ||
_post (urlPath, item, portalOpts) { | ||
const serializedItem = this._serializeItem(item); | ||
const options = { | ||
method: 'POST', | ||
data: serializedItem | ||
}; | ||
return this.request(urlPath, options, portalOpts); | ||
} | ||
}); |
@@ -7,2 +7,3 @@ import { deprecate } from '@ember/application/deprecations'; | ||
import serviceMixin from '../mixins/service-mixin'; | ||
import { setItemAccess } from '@esri/arcgis-rest-sharing'; | ||
@@ -19,28 +20,13 @@ export default Service.extend(serviceMixin, { | ||
setAccess (owner, itemId, access = null, portalOpts) { | ||
const urlPath = `/content/users/${owner}/items/${itemId}/share`; | ||
const username = this.get('session.currentUser.username'); | ||
const isAdmin = this.get('session').isAdmin(); | ||
// Reject if the current user is neither the owner nor an orgAdmin | ||
if (owner !== username && !isAdmin) { | ||
return reject(`This item can not be shared by ${username} as they are neither the owner, nor an org_admin.`); | ||
if (access === 'everyone') { | ||
access = 'public'; | ||
} | ||
let data = { | ||
f: 'json', | ||
org: false, | ||
everyone: false | ||
}; | ||
// handle the access | ||
if (access) { | ||
if (access === 'org') { | ||
data.org = true; | ||
data.everyone = false; | ||
} | ||
if (access === 'everyone' || access === 'public') { | ||
data.everyone = true; | ||
data.org = true; | ||
} | ||
} | ||
const args = this.addOptions({ | ||
id: itemId, | ||
owner, | ||
access, | ||
}, portalOpts); | ||
return this._post(urlPath, data, portalOpts); | ||
return setItemAccess(args); | ||
}, | ||
@@ -47,0 +33,0 @@ /** |
@@ -5,3 +5,15 @@ # Change Log | ||
## Unreleased | ||
## [Unreleased] | ||
## [1.5.1] | ||
### Changed | ||
- use @esri/arcgis-rest-sharing for `sharing-service:setAccess` | ||
- use @esri/arcgis-rest-items for `items-service` | ||
- upgrade to torii-provider-arcgis `v1.1.6` | ||
### Removed | ||
- `item-service._serializeItem()` | ||
- `item-service._post()` | ||
## 1.5.0 | ||
### Added | ||
@@ -377,1 +389,4 @@ - `hosted-service:deleteFromDefinition` method | ||
- `.update(item)`, will update the data via `item.text` is sent | ||
[Unreleased]: https://github.com/Esri/ember-arcgis-portal-services/compare/v1.5.1...HEAD | ||
[1.5.1]: https://github.com/Esri/ember-arcgis-portal-services/compare/v1.5.0...v1.5.1 |
57
index.js
@@ -1,14 +0,8 @@ | ||
/* Copyright 2017 Esri | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. */ | ||
/* Copyright 2017-2018 Esri - Apache 2.0 */ | ||
/* jshint node: true */ | ||
'use strict'; | ||
var path = require('path'); | ||
var Funnel = require('broccoli-funnel'); | ||
var MergeTrees = require('broccoli-merge-trees'); | ||
@@ -19,3 +13,46 @@ module.exports = { | ||
return false; | ||
}, | ||
included (/* app */) { | ||
this._super.included.apply(this, arguments); | ||
// bundle scripts from vendor folder | ||
this.import('vendor/@esri/arcgis-rest-request/request.umd.js'); | ||
this.import('vendor/@esri/arcgis-rest-auth/auth.umd.js'); | ||
this.import('vendor/@esri/arcgis-rest-sharing/sharing.umd.js'); | ||
this.import('vendor/@esri/arcgis-rest-items/items.umd.js'); | ||
this.import('vendor/shims/@esri/arcgis-rest-auth.js'); | ||
this.import('vendor/shims/@esri/arcgis-rest-request.js'); | ||
this.import('vendor/shims/@esri/arcgis-rest-sharing.js'); | ||
this.import('vendor/shims/@esri/arcgis-rest-items.js'); | ||
}, | ||
treeForVendor (vendorTree) { | ||
var arcgisRequestTree = new Funnel(path.dirname(require.resolve('@esri/arcgis-rest-request/dist/umd/request.umd.js')), { | ||
files: ['request.umd.js', 'request.umd.js.map'], | ||
destDir: '@esri/arcgis-rest-request' | ||
}); | ||
var arcgisAuthTree = new Funnel(path.dirname(require.resolve('@esri/arcgis-rest-auth/dist/umd/auth.umd.js')), { | ||
files: ['auth.umd.js', 'auth.umd.js.map'], | ||
destDir: '@esri/arcgis-rest-auth' | ||
}); | ||
var arcgisSharingTree = new Funnel(path.dirname(require.resolve('@esri/arcgis-rest-sharing/dist/umd/sharing.umd.js')), { | ||
files: ['sharing.umd.js', 'sharing.umd.js.map'], | ||
destDir: '@esri/arcgis-rest-sharing' | ||
}); | ||
var arcgisItemsTree = new Funnel(path.dirname(require.resolve('@esri/arcgis-rest-items/dist/umd/items.umd.js')), { | ||
files: ['items.umd.js', 'items.umd.js.map'], | ||
destDir: '@esri/arcgis-rest-items' | ||
}); | ||
var treesToMerge = [arcgisRequestTree, arcgisAuthTree, arcgisSharingTree, arcgisItemsTree]; | ||
// if we got a vendorTree, and add it in | ||
if (vendorTree) { | ||
treesToMerge.unshift(vendorTree); | ||
} | ||
return new MergeTrees(treesToMerge); | ||
} | ||
}; |
{ | ||
"name": "ember-arcgis-portal-services", | ||
"version": "1.5.0", | ||
"version": "1.5.1", | ||
"description": "A set of promise-based Ember Services for working with the ArcGIS Portal API.", | ||
@@ -31,8 +31,15 @@ "keywords": [ | ||
"dependencies": { | ||
"@esri/arcgis-rest-request": "^1.8.0", | ||
"@esri/arcgis-rest-auth": "^1.8.0", | ||
"@esri/arcgis-rest-sharing": "^1.8.0", | ||
"@esri/arcgis-rest-items": "^1.8.0", | ||
"ember-cli-babel": "^6.7.1", | ||
"ember-cli-htmlbars": "^1.0.3", | ||
"ember-fetch": "3.4.4" | ||
"ember-fetch": "3.4.4", | ||
"broccoli-funnel": "^2.0.1", | ||
"broccoli-merge-trees": "^2.0.0" | ||
}, | ||
"devDependencies": { | ||
"broccoli-asset-rev": "^2.4.5", | ||
"@esri/arcgis-rest-common-types": "^1.7.1", | ||
"broccoli-asset-rev": "^2.7.0", | ||
"ember-cli": "~2.18.0", | ||
@@ -69,3 +76,3 @@ "ember-cli-active-link-wrapper": "0.3.2", | ||
"loader.js": "^4.2.3", | ||
"torii-provider-arcgis": "0.12.0" | ||
"torii-provider-arcgis": "1.1.6" | ||
}, | ||
@@ -72,0 +79,0 @@ "engines": { |
@@ -42,3 +42,3 @@ # ember-arcgis-portal-services | ||
{ | ||
portalHostname: 'https://some.portal.com', | ||
portalHostname: 'some.portal.com', | ||
token: 'BZSOMETOKENQJ' | ||
@@ -45,0 +45,0 @@ } |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
682483
42
18728
9
34
4
+ Addedbroccoli-funnel@^2.0.1
+ Addedbroccoli-merge-trees@^2.0.0
+ Added@esri/arcgis-rest-auth@1.19.2(transitive)
+ Added@esri/arcgis-rest-common-types@1.19.2(transitive)
+ Added@esri/arcgis-rest-groups@1.19.2(transitive)
+ Added@esri/arcgis-rest-items@1.19.2(transitive)
+ Added@esri/arcgis-rest-request@1.19.2(transitive)
+ Added@esri/arcgis-rest-sharing@1.19.2(transitive)
+ Addedtslib@1.14.1(transitive)