Skip to content

Commit 54ef004

Browse files
committed
fix bugs, complete DocumentSharingLocation
1 parent 7b96d58 commit 54ef004

File tree

8 files changed

+193
-52
lines changed

8 files changed

+193
-52
lines changed

src/js/Autodiscover/AutodiscoverResponseCollection.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export abstract class AutodiscoverResponseCollection<TResponse extends Autodisco
8989
private LoadResponseCollectionFromXmlJsObject(jsObject: any): void {
9090
var element = this.GetResponseInstanceXmlElementName()
9191
var responses: any = undefined;
92-
if (Object.prototype.toString.call(jsObject[element]) === "[object Array]")
92+
if (Array.isArray(jsObject[element]))
9393
responses = jsObject[element];
9494
else
9595
responses = [jsObject[element]];

src/js/Autodiscover/AutodiscoverService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ export class AutodiscoverService extends ExchangeServiceBase {
708708

709709
// If Url is specified, call service directly.
710710
if (this.Url != null) {
711-
711+
urlRef = this.url;
712712
response = await getSettingsMethod(
713713
identities,
714714
settings,
Lines changed: 139 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,143 @@
1-
import {EwsXmlReader} from "../Core/EwsXmlReader";
1+
import { Convert } from "../ExtensionMethods";
2+
import { EwsLogging } from "../Core/EwsLogging";
3+
import { XmlElementNames } from "../Core/XmlElementNames";
24

5+
/**
6+
* Represents a sharing location.
7+
* @sealed
8+
*/
39
export class DocumentSharingLocation {
4-
ServiceUrl: string;
5-
LocationUrl: string;
6-
DisplayName: string;
7-
SupportedFileExtensions: string[];// System.Collections.Generic.IEnumerable<string>;
8-
ExternalAccessAllowed: boolean;
9-
AnonymousAccessAllowed: boolean;
10-
CanModifyPermissions: boolean;
11-
IsDefault: boolean;
12-
private serviceUrl: string;
13-
private locationUrl: string;
14-
private displayName: string;
15-
private supportedFileExtensions: string[];// System.Collections.Generic.IEnumerable<string>;
16-
private externalAccessAllowed: boolean;
17-
private anonymousAccessAllowed: boolean;
18-
private canModifyPermissions: boolean;
19-
private isDefault: boolean;
20-
//LoadFromXml(reader: EwsXmlReader): DocumentSharingLocation { throw new Error("DocumentSharingLocation.ts - LoadFromXml : Not implemented."); }
21-
static LoadFromJson(obj: any): DocumentSharingLocation { throw new Error("this was skipped at dev time, fix this"); }
10+
/**
11+
* The URL of the web service to use to manipulate documents at the sharing location.
12+
*/
13+
private serviceUrl: string = null;
2214

15+
/**
16+
* The URL of the sharing location (for viewing the contents in a web browser).
17+
*/
18+
private locationUrl: string = null;
19+
20+
/**
21+
* The display name of the location.
22+
*/
23+
private displayName: string = null;
24+
25+
/**
26+
* The set of file extensions that are allowed at the location.
27+
*/
28+
private supportedFileExtensions: string[] = [];
29+
30+
/**
31+
* Indicates whether external users (outside the enterprise/tenant) can view documents at the location.
32+
*/
33+
private externalAccessAllowed: boolean = false;
34+
35+
/**
36+
* Indicates whether anonymous users can view documents at the location.
37+
*/
38+
private anonymousAccessAllowed: boolean = false;
39+
40+
/**
41+
* Indicates whether the user can modify permissions for documents at the location.
42+
*/
43+
private canModifyPermissions: boolean = false;
44+
45+
/**
46+
* Indicates whether this location is the user's default location. This will generally be their My Site.
47+
*/
48+
private isDefault: boolean = false;
49+
50+
// ref: no need to have setter for all properties as all of them are private, can directly be assigned to private variables.
51+
52+
/**
53+
* Gets the URL of the web service to use to manipulate documents at the sharing location.
54+
*/
55+
get ServiceUrl(): string {
56+
return this.serviceUrl;
57+
}
58+
59+
/**
60+
* Gets the URL of the sharing location (for viewing the contents in a web browser).
61+
*/
62+
get LocationUrl(): string {
63+
return this.locationUrl;
64+
}
65+
66+
/**
67+
* Gets the display name of the location.
68+
*/
69+
get DisplayName(): string {
70+
return this.displayName;
71+
}
72+
73+
/**
74+
* Gets the space-separated list of file extensions that are allowed at the location.
75+
* @remarks Example: "docx pptx xlsx"
76+
*/
77+
get SupportedFileExtensions(): string[] {
78+
return this.supportedFileExtensions;
79+
}
80+
81+
/**
82+
* Gets a flag indicating whether external users (outside the enterprise/tenant) can view documents at the location.
83+
*/
84+
get ExternalAccessAllowed(): boolean {
85+
return this.externalAccessAllowed;
86+
}
87+
88+
/**
89+
* Gets a flag indicating whether anonymous users can view documents at the location.
90+
*/
91+
get AnonymousAccessAllowed(): boolean {
92+
return this.anonymousAccessAllowed;
93+
}
94+
95+
/**
96+
* Gets a flag indicating whether the user can modify permissions for documents at the location.
97+
* @remarks This will be true for the user's "My Site," for example. However, documents at team and project sites will typically be ACLed by the site owner, so the user will not be able to modify permissions. This will most likely by false even if the caller is the owner, to avoid surprises. They should go to SharePoint to modify permissions for team and project sites.
98+
*/
99+
get CanModifyPermissions(): boolean {
100+
return this.canModifyPermissions;
101+
}
102+
103+
/**
104+
* Gets a flag indicating whether this location is the user's default location. This will generally be their My Site.
105+
*/
106+
get IsDefault(): boolean {
107+
return this.isDefault;
108+
}
109+
110+
/**
111+
* Initializes a new instance of the **DocumentSharingLocation** class.
112+
*/
113+
private constructor() {
114+
}
115+
116+
/**
117+
* @internal Loads DocumentSharingLocation instance.
118+
*
119+
* @param {any} jsObject Json Object converted from XML.
120+
*/
121+
static LoadFromXmlJsObject(jsObject: any): DocumentSharingLocation {
122+
EwsLogging.Assert(false, "DocumentSharingLocation.LoadFromXmlJsObject", "Please provide feedback if this is successful or failed.", true);
123+
const location: DocumentSharingLocation = new DocumentSharingLocation();
124+
location.serviceUrl = jsObject[XmlElementNames.ServiceUrl];
125+
location.locationUrl = jsObject[XmlElementNames.LocationUrl];
126+
location.displayName = jsObject[XmlElementNames.DisplayName];
127+
location.supportedFileExtensions = [];
128+
const supportedFileExtensions = jsObject[XmlElementNames.SupportedFileExtensions];
129+
let extensions = supportedFileExtensions[XmlElementNames.FileExtension];
130+
if (!Array.isArray(extensions)) {
131+
extensions = [extensions]
132+
}
133+
for (let i = 0; i < extensions.length; i++) {
134+
location.supportedFileExtensions.push(extensions[i]);
135+
}
136+
jsObject[XmlElementNames.SupportedFileExtensions];
137+
location.externalAccessAllowed = Convert.toBool(jsObject[XmlElementNames.ExternalAccessAllowed]);
138+
location.anonymousAccessAllowed = Convert.toBool(jsObject[XmlElementNames.AnonymousAccessAllowed]);
139+
location.canModifyPermissions = Convert.toBool(jsObject[XmlElementNames.CanModifyPermissions]);
140+
location.isDefault = Convert.toBool(jsObject[XmlElementNames.IsDefault]);
141+
return location;
142+
}
23143
}
Lines changed: 44 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,49 @@
1-
import {EwsXmlReader} from "../Core/EwsXmlReader";
2-
import {DocumentSharingLocation} from "./DocumentSharingLocation";
3-
import {XmlElementNames} from "../Core/XmlElementNames";
1+
import { DocumentSharingLocation } from "./DocumentSharingLocation";
2+
import { XmlElementNames } from "../Core/XmlElementNames";
43

4+
/**
5+
* Represents a user setting that is a collection of alternate mailboxes.
6+
* @sealed
7+
*/
58
export class DocumentSharingLocationCollection {
6-
Entries: DocumentSharingLocation[] = [];//System.Collections.Generic.List<DocumentSharingLocation>;
7-
/**@internal */
8-
static LoadFromXml(reader: EwsXmlReader): DocumentSharingLocationCollection { throw new Error("Not implemented. Depricated, use LoadFromJson"); }
9-
static LoadFromJson(obj: any): DocumentSharingLocationCollection {
10-
var instance = new DocumentSharingLocationCollection();
11-
12-
var element = XmlElementNames.AlternateMailbox;
13-
var responses = undefined;
14-
if (Object.prototype.toString.call(obj[element]) === "[object Array]")
15-
responses = obj[element];
16-
else
17-
responses = [obj[element]];
18-
19-
for (var i = 0; i < responses.length; i++) {
20-
instance.Entries.push(responses[i]); //skipped processing individual objects in collection against DocumentSharingLocation, fix if there is parsing error later
21-
//DocumentSharingLocation.LoadFromJson(responses[i]);
22-
//instance.Entries.push(responses);
23-
}
24-
25-
return instance;
9+
10+
private entries: DocumentSharingLocation[];
2611

12+
/**
13+
* Gets the collection of alternate mailboxes.
14+
*/
15+
get Entries(): DocumentSharingLocation[] {
16+
return this.entries
17+
}
18+
19+
/**
20+
* @internal Initializes a new instance of the **DocumentSharingLocationCollection** class.
21+
*/
22+
constructor() {
23+
this.entries = [];
24+
}
25+
26+
/**
27+
* @internal Loads instance of DocumentSharingLocationCollection.
28+
*
29+
* @param {any} jsObject Json Object converted from XML.
30+
* @returns {DocumentSharingLocationCollection}
31+
*/
32+
static LoadFromXmlJsObject(jsObject: any): DocumentSharingLocationCollection {
33+
const instance = new DocumentSharingLocationCollection();
34+
35+
const element = XmlElementNames.DocumentSharingLocation;
36+
let responses = undefined;
37+
if (Array.isArray(jsObject[element]))
38+
responses = jsObject[element];
39+
else
40+
responses = [jsObject[element]];
41+
42+
for (let i = 0; i < responses.length; i++) {
43+
instance.Entries.push(DocumentSharingLocation.LoadFromXmlJsObject(responses[i]));
2744
}
45+
46+
return instance;
47+
48+
}
2849
}

src/js/Autodiscover/Requests/AutodiscoverRequest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ export abstract class AutodiscoverRequest {
161161

162162
EwsLogging.DebugLog(responseObject, true);
163163
if (xhrResponse.status == 200) {
164-
164+
EwsLogging.DebugLog(xhrResponse, true);
165165
this.ReadSoapHeader(responseObject[XmlElementNames.SOAPHeaderElementName]);
166166

167167
var response: AutodiscoverResponse = this.ReadSoapBody(responseObject);

src/js/Autodiscover/Responses/GetDomainSettingsResponse.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export class GetDomainSettingsResponse extends AutodiscoverResponse {
7575

7676
for (var i = 0; i < errors.length; i++) {
7777
var error = new DomainSettingError();
78-
error.LoadFromXmlJsObject(errors[0]);
78+
error.LoadFromXmlJsObject(errors[i]);
7979
this.DomainSettingErrors.push(error);
8080
}
8181

src/js/Autodiscover/Responses/GetUserSettingsResponse.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export class GetUserSettingsResponse extends AutodiscoverResponse {
105105

106106
for (var i = 0; i < errors.length; i++) {
107107
var error = new UserSettingError();
108-
error.LoadFromXmlJsObject(errors[0]);
108+
error.LoadFromXmlJsObject(errors[i]);
109109
this.UserSettingErrors.push(error);
110110
}
111111
}
@@ -172,14 +172,14 @@ export class GetUserSettingsResponse extends AutodiscoverResponse {
172172
//debugger;
173173
EwsLogging.Log("------------DocumentSharingLocationCollection needs test and fix ----------------", true);
174174
EwsLogging.Log(jsObject, true, true);
175-
value = DocumentSharingLocationCollection.LoadFromJson(jsObject);
175+
value = DocumentSharingLocationCollection.LoadFromXmlJsObject(jsObject);
176176
break;
177177
}
178178

179179
// EWS Managed API is broken with AutoDSvc endpoint in RedirectUrl scenario
180180
var userSettingName: UserSettingName = UserSettingName[name];// EwsUtilities.Parse<UserSettingName>(name);
181181
if (userSettingName !== undefined)
182-
this.Settings[userSettingName] = value;
182+
this.Settings.Add(userSettingName, value);
183183
else
184184
EwsLogging.Assert(false,
185185
"GetUserSettingsResponse.ReadSettingFromXml",

src/js/Autodiscover/WebClientUrl.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ export class WebClientUrl {
5252
* @param {any} jsObject Json Object converted from XML.
5353
* @returns {WebClientUrl} WebClientUrl.
5454
*/
55-
static LoadFromXmlJsObject(obj: any): WebClientUrl {
55+
static LoadFromXmlJsObject(jsObject: any): WebClientUrl {
5656
const webClientUrl = new WebClientUrl();
57-
webClientUrl.AuthenticationMethods = obj[XmlElementNames.AuthenticationMethods];
58-
webClientUrl.Url = obj[XmlElementNames.Url];
57+
webClientUrl.AuthenticationMethods = jsObject[XmlElementNames.AuthenticationMethods];
58+
webClientUrl.Url = jsObject[XmlElementNames.Url];
5959
return webClientUrl;
6060
}
6161
}

0 commit comments

Comments
 (0)