Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

Fix for #517, update extractWebId to use metadata and editLink #520

Merged
merged 1 commit into from
Jul 5, 2017
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
9 changes: 4 additions & 5 deletions src/sharepoint/odata.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { QueryableConstructor } from "./queryable";
import { Util } from "../utils/util";
import { Util, extractWebUrl } from "../utils/util";
import { Logger, LogLevel } from "../utils/logging";
import { HttpClient, mergeHeaders } from "../net/httpclient";
import { RuntimeConfig } from "../configuration/pnplibconfig";
import { TypedHash } from "../collections/collections";
import { ODataIdException, BatchParseException } from "../utils/exceptions";
import { ProcessHttpClientResponseException } from "../utils/exceptions";
import { ODataIdException, BatchParseException, ProcessHttpClientResponseException } from "../utils/exceptions";

export function extractOdataId(candidate: any): string {

Expand Down Expand Up @@ -135,9 +134,9 @@ class ODataEntityArrayParserImpl<T> extends ODataParserBase<T[]> {

export function getEntityUrl(entity: any): string {

if (entity.hasOwnProperty("odata.editLink")) {
if (entity.hasOwnProperty("odata.metadata") && entity.hasOwnProperty("odata.editLink")) {
// we are dealign with minimal metadata (default)
return Util.combinePaths("_api", entity["odata.editLink"]);
return Util.combinePaths(extractWebUrl(entity["odata.metadata"]), "_api", entity["odata.editLink"]);
} else if (entity.hasOwnProperty("__metadata")) {
// we are dealing with verbose, which has an absolute uri
return entity.__metadata.uri;
Expand Down
15 changes: 2 additions & 13 deletions src/sharepoint/webs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Folders, Folder } from "./folders";
import { RoleDefinitions } from "./roles";
import { File } from "./files";
import { TypedHash } from "../collections/collections";
import { Util } from "../utils/util";
import { Util, extractWebUrl } from "../utils/util";
import { BasePermissions, ChangeQuery } from "./types";
import { List } from "./lists";
import { SiteUsers, SiteUser, CurrentUser, SiteUserProps } from "./siteusers";
Expand Down Expand Up @@ -109,18 +109,7 @@ export class Web extends QueryableShareableWeb {
* @param url
*/
public static fromUrl(url: string, path?: string) {

if (url === null) {
return new Web("");
}

const index = url.indexOf("_api/");

if (index > -1) {
return new Web(url.substr(0, index), path);
}

return new Web(url, path);
return new Web(extractWebUrl(url), path);
}

/**
Expand Down
16 changes: 16 additions & 0 deletions src/utils/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,22 @@ declare var global: any;
import { TypedHash } from "../collections/collections";
import { RuntimeConfig } from "../configuration/pnplibconfig";

export function extractWebUrl(candidateUrl: string) {

if (candidateUrl === null) {
return "";
}

const index = candidateUrl.indexOf("_api/");

if (index > -1) {
return candidateUrl.substr(0, index);
}

// if all else fails just give them what they gave us back
return candidateUrl;
}

export class Util {

/**
Expand Down