@kwiz/common 1.0.4 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/helpers/base64.js +10 -21
- package/dist/helpers/base64.js.map +1 -1
- package/dist/helpers/browser.d.ts +13 -5
- package/dist/helpers/browser.js +61 -39
- package/dist/helpers/browser.js.map +1 -1
- package/dist/helpers/collections.base.js +46 -65
- package/dist/helpers/collections.base.js.map +1 -1
- package/dist/helpers/collections.js +4 -1
- package/dist/helpers/collections.js.map +1 -1
- package/dist/helpers/date.d.ts +2 -1
- package/dist/helpers/date.js +22 -3
- package/dist/helpers/date.js.map +1 -1
- package/dist/helpers/debug.js +9 -20
- package/dist/helpers/debug.js.map +1 -1
- package/dist/helpers/objects.js +2 -11
- package/dist/helpers/objects.js.map +1 -1
- package/dist/helpers/promises.js +28 -41
- package/dist/helpers/promises.js.map +1 -1
- package/dist/helpers/strings.js +2 -1
- package/dist/helpers/strings.js.map +1 -1
- package/dist/utils/base64.js +18 -29
- package/dist/utils/base64.js.map +1 -1
- package/dist/utils/consolelogger.js +16 -27
- package/dist/utils/consolelogger.js.map +1 -1
- package/dist/utils/emails.js +5 -2
- package/dist/utils/emails.js.map +1 -1
- package/dist/utils/knownscript.js +4 -15
- package/dist/utils/knownscript.js.map +1 -1
- package/dist/utils/localstoragecache.js +3 -3
- package/dist/utils/localstoragecache.js.map +1 -1
- package/dist/utils/rest.d.ts +2 -0
- package/dist/utils/rest.js +18 -5
- package/dist/utils/rest.js.map +1 -1
- package/dist/utils/script.js +25 -40
- package/dist/utils/script.js.map +1 -1
- package/dist/utils/sharepoint.rest/file.folder.d.ts +2 -0
- package/dist/utils/sharepoint.rest/file.folder.js +123 -123
- package/dist/utils/sharepoint.rest/file.folder.js.map +1 -1
- package/dist/utils/sharepoint.rest/item.d.ts +10 -0
- package/dist/utils/sharepoint.rest/item.js +233 -237
- package/dist/utils/sharepoint.rest/item.js.map +1 -1
- package/dist/utils/sharepoint.rest/list.d.ts +30 -1
- package/dist/utils/sharepoint.rest/list.js +296 -289
- package/dist/utils/sharepoint.rest/list.js.map +1 -1
- package/dist/utils/sharepoint.rest/listutils/GetListItemsByCaml.js +352 -360
- package/dist/utils/sharepoint.rest/listutils/GetListItemsByCaml.js.map +1 -1
- package/dist/utils/sharepoint.rest/listutils/GetListItemsById.js +47 -58
- package/dist/utils/sharepoint.rest/listutils/GetListItemsById.js.map +1 -1
- package/dist/utils/sharepoint.rest/user-search.d.ts +5 -10
- package/dist/utils/sharepoint.rest/user-search.js +129 -148
- package/dist/utils/sharepoint.rest/user-search.js.map +1 -1
- package/dist/utils/sharepoint.rest/user.d.ts +1 -0
- package/dist/utils/sharepoint.rest/user.js +200 -169
- package/dist/utils/sharepoint.rest/user.js.map +1 -1
- package/dist/utils/sharepoint.rest/web.d.ts +10 -1
- package/dist/utils/sharepoint.rest/web.js +381 -401
- package/dist/utils/sharepoint.rest/web.js.map +1 -1
- package/dist/utils/sod.js +8 -19
- package/dist/utils/sod.js.map +1 -1
- package/package.json +5 -4
- package/src/helpers/browser.ts +56 -13
- package/src/helpers/date.ts +23 -1
- package/src/helpers/strings.test.js +14 -2
- package/src/helpers/strings.ts +2 -1
- package/src/utils/rest.ts +7 -0
- package/src/utils/sharepoint.rest/file.folder.ts +18 -1
- package/src/utils/sharepoint.rest/item.ts +54 -1
- package/src/utils/sharepoint.rest/list.ts +144 -0
- package/src/utils/sharepoint.rest/user-search.ts +10 -14
- package/src/utils/sharepoint.rest/user.ts +49 -3
- package/src/utils/sharepoint.rest/web.ts +23 -1
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { BaseTypes, FieldTypeAsString, FieldTypes, GeListItemsFoldersBehaviour, IDictionary, IFieldInfo, IFieldInfoEX, IFieldInfoExHash, IFieldJsonSchema, IFieldLookupInfo, IListWorkflowAssociation, IRestItem, IRestOptions, ISPEventReceiver, ListExperienceOptions, ListTemplateTypes, NormalizeListName, PageType, PushNoDuplicate, SPBasePermissionKind, SPBasePermissions, SafeIfElse, SchemaXmlToJson, contentTypes, extendFieldInfo, firstOrNull, iContentType, iList, iListView, isBoolean, isNotEmptyArray, isNullOrEmptyArray, isNullOrEmptyString, isNullOrUndefined, isNumber, isPromise, isString, isValidGuid, jsonStringify, jsonTypes, makeServerRelativeUrl, makeUniqueArray, normalizeGuid, normalizeUrl, toHash } from "../_dependencies";
|
|
2
|
+
import { ConsoleLogger } from "../consolelogger";
|
|
2
3
|
import { GetJson, GetJsonSync, longLocalCache, shortLocalCache } from "../rest";
|
|
3
4
|
import { GetRestBaseUrl, GetSiteUrl, LIST_EXPAND, LIST_SELECT } from "./common";
|
|
4
5
|
import { __fixGetListItemsResults } from "./listutils/common";
|
|
5
6
|
import { GetContentTypes, GetContentTypesSync, GetListsSync } from "./web";
|
|
6
7
|
|
|
8
|
+
const logger = ConsoleLogger.get("SharePoint.Rest.List");
|
|
9
|
+
|
|
7
10
|
/** returns /_api/web/lists/getById() or /_api/web/lists/getByTitle() */
|
|
8
11
|
export function GetListRestUrl(siteUrl: string, listIdOrTitle: string): string {
|
|
9
12
|
siteUrl = GetSiteUrl(siteUrl);
|
|
@@ -1141,4 +1144,145 @@ export async function CreateList(siteUrl: string, info: {
|
|
|
1141
1144
|
let newList = (await GetJson<{ d: iCreateListResult }>(url, jsonStringify(body))).d;
|
|
1142
1145
|
normalizeGuid(newList.Id);
|
|
1143
1146
|
return newList;
|
|
1147
|
+
}
|
|
1148
|
+
|
|
1149
|
+
export async function SearchList(siteUrl: string, listIdOrTitle: string, query: string) {
|
|
1150
|
+
let listId = GetListId(siteUrl, listIdOrTitle);
|
|
1151
|
+
let url = `${GetRestBaseUrl(siteUrl)}/search/query?querytext='(${query}*)'&querytemplate='{searchTerms} (NormListID:${listId})'`;
|
|
1152
|
+
|
|
1153
|
+
try {
|
|
1154
|
+
const result = await GetJson<{
|
|
1155
|
+
ElapsedTime: number,
|
|
1156
|
+
PrimaryQueryResult: {
|
|
1157
|
+
CustomResults: [];
|
|
1158
|
+
QueryId: string;//"7fdf01b1-f6f0-4d42-b046-d9db22597084",
|
|
1159
|
+
QueryRuleId: string;// "00000000-0000-0000-0000-000000000000",
|
|
1160
|
+
RefinementResults: null,
|
|
1161
|
+
RelevantResults: {
|
|
1162
|
+
RowCount: number,
|
|
1163
|
+
Table: {
|
|
1164
|
+
Rows: {
|
|
1165
|
+
Cells: {
|
|
1166
|
+
Key:
|
|
1167
|
+
/** "1989637621861439888" "Edm.Int64" */
|
|
1168
|
+
"WorkId"
|
|
1169
|
+
/** "1000.1073372","Edm.Double" */
|
|
1170
|
+
| "Rank"
|
|
1171
|
+
/** "sample md as text","Edm.String" */
|
|
1172
|
+
| "Title"
|
|
1173
|
+
/** "Shai Petel", "Edm.String" */
|
|
1174
|
+
| "Author"
|
|
1175
|
+
/** "91", "Edm.Int64" */
|
|
1176
|
+
| "Size"
|
|
1177
|
+
/** "https://kwizcom.sharepoint.com/sites/s/cms/CMSPages/sample md as text.txt", "Edm.String" */
|
|
1178
|
+
| "Path"
|
|
1179
|
+
/** null, "Null" */
|
|
1180
|
+
| "Description"
|
|
1181
|
+
/** "# hello world! - bullet - bullet | table | col | | ----- | ---- | |table |col | ", "Edm.String" */
|
|
1182
|
+
| "HitHighlightedSummary"
|
|
1183
|
+
/** "https://kwizcom.sharepoint.com/_api/v2.1/drives/b!8NAeO-mocUWbgyMTqcM0Mfh8XKPhn7xOhhMrO5KfJjBs_gXb9j8ZRaLxuppgj0Uk/items/01OBXW4FLU6G4LIT7AX5BK3MXHDICVTIOT/thumbnails/0/c400x99999/content?prefer=noRedirect", "Edm.String" */
|
|
1184
|
+
| "PictureThumbnailURL"
|
|
1185
|
+
/** null,"Null" */
|
|
1186
|
+
| "ServerRedirectedURL"
|
|
1187
|
+
/** null,"Null" */
|
|
1188
|
+
| "ServerRedirectedEmbedURL"
|
|
1189
|
+
/** null,"Null" */
|
|
1190
|
+
| "ServerRedirectedPreviewURL"
|
|
1191
|
+
/** "txt","Edm.String" */
|
|
1192
|
+
| "FileExtension"
|
|
1193
|
+
/** "0x010100CB212272F1372446A2423F0A2BEA12B8", "Edm.String" */
|
|
1194
|
+
| "ContentTypeId"
|
|
1195
|
+
/** "https://kwizcom.sharepoint.com/sites/s/cms/CMSPages/Forms/AllItems.aspx","Edm.String" */
|
|
1196
|
+
| "ParentLink"
|
|
1197
|
+
/** "1","Edm.Int64" */
|
|
1198
|
+
| "ViewsLifeTime"
|
|
1199
|
+
/** "1","Edm.Int64" */
|
|
1200
|
+
| "ViewsRecent"
|
|
1201
|
+
/** "2024-02-22T18:35:48.0000000Z","Edm.DateTime" */
|
|
1202
|
+
| "LastModifiedTime"
|
|
1203
|
+
/** "txt","Edm.String" */
|
|
1204
|
+
| "FileType"
|
|
1205
|
+
/** "1989637621861439888","Edm.Int64" */
|
|
1206
|
+
| "DocId"
|
|
1207
|
+
/** "https://kwizcom.sharepoint.com/sites/s/cms","Edm.String" */
|
|
1208
|
+
| "SPWebUrl"
|
|
1209
|
+
/** "{b4b8f174-e04f-42bf-adb2-e71a0559a1d3}","Edm.String" */
|
|
1210
|
+
| "UniqueId"
|
|
1211
|
+
/** "3b1ed0f0-a8e9-4571-9b83-2313a9c33431","Edm.String" */
|
|
1212
|
+
| "SiteId"
|
|
1213
|
+
/** "a35c7cf8-9fe1-4ebc-8613-2b3b929f2630","Edm.String" */
|
|
1214
|
+
| "WebId"
|
|
1215
|
+
/** "db05fe6c-3ff6-4519-a2f1-ba9a608f4524","Edm.String" */
|
|
1216
|
+
| "ListId"
|
|
1217
|
+
/** "https://kwizcom.sharepoint.com/sites/s/cms/CMSPages/sample md as text.txt","Edm.String" */
|
|
1218
|
+
| "OriginalPath"
|
|
1219
|
+
;
|
|
1220
|
+
Value: string,
|
|
1221
|
+
ValueType: "Edm.Int64" | "Edm.Double" | "Edm.String" | "Edm.DateTime" | "Null"
|
|
1222
|
+
}[]
|
|
1223
|
+
}[]
|
|
1224
|
+
},
|
|
1225
|
+
TotalRows: number,
|
|
1226
|
+
TotalRowsIncludingDuplicates: number
|
|
1227
|
+
}
|
|
1228
|
+
},
|
|
1229
|
+
}>(url, null, { jsonMetadata: jsonTypes.nometadata });
|
|
1230
|
+
logger.json(result.PrimaryQueryResult.RelevantResults, `search ${query}`);
|
|
1231
|
+
let rows = result.PrimaryQueryResult.RelevantResults.Table.Rows;
|
|
1232
|
+
|
|
1233
|
+
const mapped: (IDictionary<string | Date | number> & {
|
|
1234
|
+
WorkId?: number;
|
|
1235
|
+
Rank?: number;
|
|
1236
|
+
Title?: string;
|
|
1237
|
+
Author?: string;
|
|
1238
|
+
Size?: number;
|
|
1239
|
+
Path?: string;
|
|
1240
|
+
Description?: string;
|
|
1241
|
+
HitHighlightedSummary?: string;
|
|
1242
|
+
PictureThumbnailURL?: string;
|
|
1243
|
+
ServerRedirectedURL?: string;
|
|
1244
|
+
ServerRedirectedEmbedURL?: string;
|
|
1245
|
+
ServerRedirectedPreviewURL?: string;
|
|
1246
|
+
FileExtension?: string;
|
|
1247
|
+
ContentTypeId?: string;
|
|
1248
|
+
ParentLink?: string;
|
|
1249
|
+
ViewsLifeTime?: number;
|
|
1250
|
+
ViewsRecent?: number;
|
|
1251
|
+
LastModifiedTime?: Date;
|
|
1252
|
+
FileType?: string;
|
|
1253
|
+
DocId?: number;
|
|
1254
|
+
SPWebUrl?: string;
|
|
1255
|
+
UniqueId?: string;
|
|
1256
|
+
SiteId?: string;
|
|
1257
|
+
WebId?: string;
|
|
1258
|
+
ListId?: string;
|
|
1259
|
+
OriginalPath?: string;
|
|
1260
|
+
$itemId?: number;
|
|
1261
|
+
})[] = [];
|
|
1262
|
+
rows.forEach(r => {
|
|
1263
|
+
try {
|
|
1264
|
+
const rowValues: IDictionary<string | Date | number> = {};
|
|
1265
|
+
r.Cells.forEach(cell => {
|
|
1266
|
+
rowValues[cell.Key] = cell.ValueType === "Edm.Int64" || cell.ValueType === "Edm.Double"
|
|
1267
|
+
? parseInt(cell.Value, 10)
|
|
1268
|
+
: cell.ValueType === "Edm.DateTime"
|
|
1269
|
+
? new Date(cell.Value)
|
|
1270
|
+
: cell.ValueType === "Null"
|
|
1271
|
+
? ""
|
|
1272
|
+
: cell.Value
|
|
1273
|
+
});
|
|
1274
|
+
let resultPath = isNullOrEmptyString(rowValues.Path) ? "" : (rowValues.Path as string).toLowerCase();
|
|
1275
|
+
let indexOfId = resultPath.toLowerCase().indexOf("id=");
|
|
1276
|
+
let itemId = indexOfId >= 0 ? parseInt(resultPath.slice(indexOfId + 3)) : -1;
|
|
1277
|
+
if (itemId >= 0)
|
|
1278
|
+
rowValues.$itemId = itemId;
|
|
1279
|
+
mapped.push(rowValues);
|
|
1280
|
+
} catch (e) { return null; }
|
|
1281
|
+
});
|
|
1282
|
+
|
|
1283
|
+
return mapped;
|
|
1284
|
+
} catch (e) {
|
|
1285
|
+
logger.error(e);
|
|
1286
|
+
return [];
|
|
1287
|
+
}
|
|
1144
1288
|
}
|
|
@@ -2,14 +2,10 @@ import { IUserInfo, PrincipalType, contentTypes, firstIndexOf, jsonTypes } from
|
|
|
2
2
|
import { GetJson } from "../rest";
|
|
3
3
|
import { EnsureUser } from "./user";
|
|
4
4
|
|
|
5
|
-
interface
|
|
6
|
-
/**
|
|
7
|
-
* LoginName or Id of the principal in the site.
|
|
8
|
-
*/
|
|
5
|
+
export interface iPeoplePickerUserItem {
|
|
6
|
+
/** LoginName or Id of the principal in the site. */
|
|
9
7
|
id: string;
|
|
10
|
-
/**
|
|
11
|
-
* LoginName of the principal.
|
|
12
|
-
*/
|
|
8
|
+
/** LoginName of the principal. */
|
|
13
9
|
loginName: string;
|
|
14
10
|
imageUrl: string;
|
|
15
11
|
imageInitials: string;
|
|
@@ -72,7 +68,7 @@ export class SPPeopleSearchService {
|
|
|
72
68
|
/**
|
|
73
69
|
* Search person by its email or login name
|
|
74
70
|
*/
|
|
75
|
-
public async searchPersonByEmailOrLogin(email: string, principalTypes: PrincipalType[], siteUrl: string = null, groupId: number = null, ensureUser: boolean = false): Promise<
|
|
71
|
+
public async searchPersonByEmailOrLogin(email: string, principalTypes: PrincipalType[], siteUrl: string = null, groupId: number = null, ensureUser: boolean = false): Promise<iPeoplePickerUserItem> {
|
|
76
72
|
// if (Environment.type === EnvironmentType.Local) {
|
|
77
73
|
// // If the running environment is local, load the data from the mock
|
|
78
74
|
// const mockUsers = await this.searchPeopleFromMock(email);
|
|
@@ -86,7 +82,7 @@ export class SPPeopleSearchService {
|
|
|
86
82
|
/**
|
|
87
83
|
* Search All Users from the SharePoint People database
|
|
88
84
|
*/
|
|
89
|
-
public async searchPeople(query: string, maximumSuggestions: number, principalTypes: PrincipalType[], siteUrl: string = null, groupId: number = null, ensureUser: boolean = false): Promise<
|
|
85
|
+
public async searchPeople(query: string, maximumSuggestions: number, principalTypes: PrincipalType[], siteUrl: string = null, groupId: number = null, ensureUser: boolean = false): Promise<iPeoplePickerUserItem[]> {
|
|
90
86
|
// if (Environment.type === EnvironmentType.Local) {
|
|
91
87
|
// // If the running environment is local, load the data from the mock
|
|
92
88
|
// return this.searchPeopleFromMock(query);
|
|
@@ -98,7 +94,7 @@ export class SPPeopleSearchService {
|
|
|
98
94
|
/**
|
|
99
95
|
* Tenant search
|
|
100
96
|
*/
|
|
101
|
-
private async searchTenant(siteUrl: string, query: string, maximumSuggestions: number, principalTypes: PrincipalType[], ensureUser: boolean, groupId: number): Promise<
|
|
97
|
+
private async searchTenant(siteUrl: string, query: string, maximumSuggestions: number, principalTypes: PrincipalType[], ensureUser: boolean, groupId: number): Promise<iPeoplePickerUserItem[]> {
|
|
102
98
|
try {
|
|
103
99
|
// If the running env is SharePoint, loads from the peoplepicker web service
|
|
104
100
|
const userRequestUrl: string = `${siteUrl || this.context.siteUrl}/_api/SP.UI.ApplicationPages.ClientPeoplePickerWebServiceInterface.clientPeoplePickerSearchUser`;
|
|
@@ -171,7 +167,7 @@ export class SPPeopleSearchService {
|
|
|
171
167
|
secondaryText: element.EntityData.Email || element.Description, // email
|
|
172
168
|
tertiaryText: "", // status
|
|
173
169
|
optionalText: "" // anything
|
|
174
|
-
} as
|
|
170
|
+
} as iPeoplePickerUserItem;
|
|
175
171
|
case 'SecGroup':
|
|
176
172
|
return {
|
|
177
173
|
id: element.Key,
|
|
@@ -179,7 +175,7 @@ export class SPPeopleSearchService {
|
|
|
179
175
|
imageInitials: this.getFullNameInitials(element.DisplayText),
|
|
180
176
|
text: element.DisplayText,
|
|
181
177
|
secondaryText: element.ProviderName
|
|
182
|
-
} as
|
|
178
|
+
} as iPeoplePickerUserItem;
|
|
183
179
|
case 'FormsRole':
|
|
184
180
|
return {
|
|
185
181
|
id: element.Key,
|
|
@@ -187,7 +183,7 @@ export class SPPeopleSearchService {
|
|
|
187
183
|
imageInitials: this.getFullNameInitials(element.DisplayText),
|
|
188
184
|
text: element.DisplayText,
|
|
189
185
|
secondaryText: element.ProviderName
|
|
190
|
-
} as
|
|
186
|
+
} as iPeoplePickerUserItem;
|
|
191
187
|
default:
|
|
192
188
|
return {
|
|
193
189
|
id: element.EntityData.SPGroupID,
|
|
@@ -195,7 +191,7 @@ export class SPPeopleSearchService {
|
|
|
195
191
|
imageInitials: this.getFullNameInitials(element.DisplayText),
|
|
196
192
|
text: element.DisplayText,
|
|
197
193
|
secondaryText: element.EntityData.AccountName
|
|
198
|
-
} as
|
|
194
|
+
} as iPeoplePickerUserItem;
|
|
199
195
|
}
|
|
200
196
|
});
|
|
201
197
|
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { IGroupInfo, ISPPeoplePickerControlFormEntity, IUserInfo, IsSPPeoplePickerControlFormEntity, PrincipalType, encodeURIComponentEX, getPrincipalTypeFromPickerEntity, isNullOrEmptyString, isNullOrNaN, isNullOrUndefined, isNumber, jsonStringify, jsonTypes } from "../_dependencies";
|
|
2
|
-
|
|
1
|
+
import { IGroupInfo, ISPPeoplePickerControlFormEntity, IUserInfo, IsSPPeoplePickerControlFormEntity, PrincipalType, contentTypes, encodeURIComponentEX, getPrincipalTypeFromPickerEntity, isNullOrEmptyArray, isNullOrEmptyString, isNullOrNaN, isNullOrUndefined, isNumber, jsonStringify, jsonTypes } from "../_dependencies";
|
|
2
|
+
import { ConsoleLogger } from "../consolelogger";
|
|
3
3
|
import { GetJson, GetJsonSync, longLocalCache, shortLocalCache } from "../rest";
|
|
4
4
|
import { GetRestBaseUrl, GetSiteUrl } from "./common";
|
|
5
|
+
import { GetSiteId } from "./web";
|
|
5
6
|
|
|
6
|
-
|
|
7
|
+
const logger = ConsoleLogger.get("utils/sharepoint/user");
|
|
7
8
|
var __currentUserId: number = null;
|
|
8
9
|
const groupSelect = "Id,Title,Description,CanCurrentUserViewMembership,OnlyAllowMembersViewMembership,IsHiddenInUI,OwnerTitle";
|
|
9
10
|
const userSelect = "PrincipalType,Id,LoginName,UserPrincipalName,Title,IsSiteAdmin,Email";
|
|
@@ -444,4 +445,49 @@ export async function AddUserToGroup(siteUrl: string, groupId: number, userIdOrL
|
|
|
444
445
|
export async function RemoveUserFromGroup(siteUrl: string, groupId: number, userId: number): Promise<void> {
|
|
445
446
|
let url = `${GetRestBaseUrl(siteUrl)}/web/siteGroups(${groupId})/users/removeById(${userId})`;
|
|
446
447
|
await GetJson(url, null, { method: "POST", allowCache: false, jsonMetadata: jsonTypes.nometadata });
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
export async function SetGroupOwner(siteUrl: string, groupId: number, ownerId: number, ownerIsAGroup?: boolean) {
|
|
451
|
+
//https://github.com/SharePoint/sp-dev-docs/issues/5031#issuecomment-594710013
|
|
452
|
+
//if owner is a group - rest API doens't work.
|
|
453
|
+
if (ownerIsAGroup !== true) {
|
|
454
|
+
let url = `${GetRestBaseUrl(siteUrl)}/web/siteGroups/getById('${groupId}')/SetUserAsOwner(${ownerId})`;
|
|
455
|
+
try {
|
|
456
|
+
await GetJson<{ 'odata.null': true }>(url, null, { jsonMetadata: jsonTypes.nometadata, method: "POST" });
|
|
457
|
+
return true;
|
|
458
|
+
} catch (e) {
|
|
459
|
+
logger.error(`SetGroupOwner ${groupId} ${ownerId} error:`);
|
|
460
|
+
logger.error(e);
|
|
461
|
+
return false;
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
else {
|
|
465
|
+
try {
|
|
466
|
+
let soapUrl = `${GetSiteUrl(siteUrl)}_vti_bin/client.svc/ProcessQuery`;
|
|
467
|
+
let siteId = await GetSiteId(siteUrl);
|
|
468
|
+
let serviceJSONResponse = await GetJson<{ ErrorInfo?: string }[]>(soapUrl, `<Request AddExpandoFieldTypeSuffix="true" SchemaVersion="15.0.0.0" LibraryVersion="15.0.0.0" ApplicationName=".NET Library" xmlns="http://schemas.microsoft.com/sharepoint/clientquery/2009">
|
|
469
|
+
<Actions>
|
|
470
|
+
<SetProperty Id="1" ObjectPathId="2" Name="Owner">
|
|
471
|
+
<Parameter ObjectPathId="3" />
|
|
472
|
+
</SetProperty>
|
|
473
|
+
<Method Name="Update" Id="4" ObjectPathId="2" />
|
|
474
|
+
</Actions>
|
|
475
|
+
<ObjectPaths>
|
|
476
|
+
<Identity Id="2" Name="740c6a0b-85e2-48a0-a494-e0f1759d4aa7:site:${siteId}:g:${groupId}" />
|
|
477
|
+
<Identity Id="3" Name="740c6a0b-85e2-48a0-a494-e0f1759d4aa7:site:${siteId}:g:${ownerId}" />
|
|
478
|
+
</ObjectPaths>
|
|
479
|
+
</Request>`, {
|
|
480
|
+
headers: {
|
|
481
|
+
Accept: jsonTypes.standard,
|
|
482
|
+
"content-type": contentTypes.xml
|
|
483
|
+
}
|
|
484
|
+
});
|
|
485
|
+
//logger.json(serviceJSONResponse, "soap result");
|
|
486
|
+
return isNullOrEmptyArray(serviceJSONResponse) || isNullOrEmptyString(serviceJSONResponse[0].ErrorInfo);
|
|
487
|
+
} catch (e) {
|
|
488
|
+
logger.error(`SetGroupOwner via SOAP ${ownerId} ${ownerId} error:`);
|
|
489
|
+
logger.error(e);
|
|
490
|
+
return false;
|
|
491
|
+
}
|
|
492
|
+
}
|
|
447
493
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IAppTile, IContextWebInformation, IDictionary, IFieldInfoEX, IRestOptions, IRestRoleDefinition, IRootWebInfo, ISiteInfo, ITimeZone, IUserCustomActionInfo, IWebBasicInfo, IWebInfo, IWebRegionalSettings, SPBasePermissionKind, SPBasePermissions, WebTypes, extendFieldInfo, getGlobal, iContentType, iList, isDate, isNotEmptyArray, isNullOrEmptyArray, isNullOrEmptyString, isNullOrUndefined, isString, isTypeofFullNameNullOrUndefined, isValidGuid, jsonTypes, makeServerRelativeUrl, normalizeGuid, normalizeUrl, sortArray } from "../_dependencies";
|
|
1
|
+
import { IAppTile, IContextWebInformation, IDictionary, IFieldInfoEX, IGroupInfo, IRestOptions, IRestRoleDefinition, IRootWebInfo, ISiteInfo, ITimeZone, IUserCustomActionInfo, IUserInfo, IWebBasicInfo, IWebInfo, IWebRegionalSettings, SPBasePermissionKind, SPBasePermissions, WebTypes, extendFieldInfo, getGlobal, iContentType, iList, isDate, isNotEmptyArray, isNullOrEmptyArray, isNullOrEmptyString, isNullOrUndefined, isString, isTypeofFullNameNullOrUndefined, isValidGuid, jsonStringify, jsonTypes, makeServerRelativeUrl, normalizeGuid, normalizeUrl, sortArray } from "../_dependencies";
|
|
2
2
|
import { ConsoleLogger } from "../consolelogger";
|
|
3
3
|
import { toIsoDateFormat } from "../date";
|
|
4
4
|
import { GetJson, GetJsonSync, longLocalCache, mediumLocalCache, shortLocalCache, weeekLongLocalCache } from "../rest";
|
|
@@ -636,6 +636,18 @@ export async function GetWebRoleDefinitions(siteUrl: string): Promise<IRestRoleD
|
|
|
636
636
|
.catch<IRestRoleDefinition[]>(() => []);
|
|
637
637
|
}
|
|
638
638
|
|
|
639
|
+
export interface iRoleAssignment {
|
|
640
|
+
Member: IGroupInfo | IUserInfo,
|
|
641
|
+
RoleDefinitionBindings: IRestRoleDefinition[],
|
|
642
|
+
PrincipalId: 14
|
|
643
|
+
};
|
|
644
|
+
/** get roles for site or list */
|
|
645
|
+
export async function GetRoleAssignments(siteUrl: string, listIdOrTitle?: string) {
|
|
646
|
+
const url = `${isNullOrEmptyString(listIdOrTitle) ? GetRestBaseUrl(siteUrl) + "/web" : GetListRestUrl(siteUrl, listIdOrTitle)}/roleassignments?$expand=Member/users,RoleDefinitionBindings`;
|
|
647
|
+
const result = await GetJson<{ value: iRoleAssignment[] }>(url, undefined, { jsonMetadata: jsonTypes.nometadata });
|
|
648
|
+
return result.value;
|
|
649
|
+
}
|
|
650
|
+
|
|
639
651
|
/** Web sub webs for the selected site */
|
|
640
652
|
export async function GetSubWebs(siteUrl: string, options?: { allowAppWebs?: boolean; }): Promise<IWebInfo[]> {
|
|
641
653
|
return GetJson<{ d: { results: IWebInfo[]; }; }>(GetRestBaseUrl(siteUrl) + `/web/webs${options && options.allowAppWebs ? "" : "&$filter=WebTemplate ne 'APP'"}`, null,
|
|
@@ -1029,3 +1041,13 @@ export async function RemoveWebPermission(siteUrl: string, principalId: number,
|
|
|
1029
1041
|
let url = `${GetRestBaseUrl(siteUrl)}/web/roleassignments/removeroleassignment(principalid=${principalId},roleDefId=${roleId})`;
|
|
1030
1042
|
await GetJson(url, undefined, { method: "POST", allowCache: false, jsonMetadata: jsonTypes.nometadata });
|
|
1031
1043
|
}
|
|
1044
|
+
|
|
1045
|
+
/** set a user as site admin - rejects/throws if not successful */
|
|
1046
|
+
export async function SetUserAsSiteAdmin(siteUrl: string, userId: number) {
|
|
1047
|
+
const url = `${GetRestBaseUrl(siteUrl)}/web/getuserbyid(${userId})`;
|
|
1048
|
+
await GetJson<{}>(url, jsonStringify({
|
|
1049
|
+
"__metadata": { "type": "SP.User" },
|
|
1050
|
+
"IsSiteAdmin": true
|
|
1051
|
+
}), { method: 'POST', xHttpMethod: 'MERGE' });
|
|
1052
|
+
return true;
|
|
1053
|
+
}
|