Skip to content

Commit

Permalink
Adds propertybag set command
Browse files Browse the repository at this point in the history
web EffectiveBasePermissions check added before adding new property

docs added

confirm var cleanup

propertybag folder desc update
  • Loading branch information
VelinGeorgiev committed Apr 3, 2018
1 parent 0d82e4a commit 9cd9cd1
Show file tree
Hide file tree
Showing 6 changed files with 1,364 additions and 0 deletions.
62 changes: 62 additions & 0 deletions docs/manual/docs/cmd/spo/propertybag/propertybag-set.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# spo propertybag set

Sets the value of the specified property from the property bag. Adds the property if does not exist

## Usage

```sh
spo propertybag set [options]
```

## Options

Option|Description
------|-----------
`--help`|output usage information
`-u, --webUrl <webUrl>`|The URL of the site from which the property should be set
`-k, --key <key>`|Key of the property to be set. Case-sensitive
`-v, --value <value>`|Value of the property to be set
`-f, --folder [folder]`|Site relative URL of the folder which the property should be set
`-o, --output [output]`|Output type. `json|text`. Default `text`
`--verbose`|Runs command with verbose logging
`--debug`|Runs command with debug logging

!!! important
Before using this command, connect to a SharePoint Online site, using the [spo connect](../connect.md) command.

## Remarks

To set property bag value, you have to first connect to a SharePoint
Online site using the [spo connect](../connect.md) command, eg. `spo connect https://contoso.sharepoint.com`.

## Examples

Sets the value of the _key1_ property located in site _https://contoso.sharepoint.com/sites/test_

```sh
spo propertybag set --webUrl https://contoso.sharepoint.com/sites/test --key key1 --value value1
```

Sets the value of the _key1_ property located in site root folder _https://contoso.sharepoint.com/sites/test_

```sh
spo propertybag set --webUrl https://contoso.sharepoint.com/sites/test --key key1 --value value1 --folder /
```

Sets the value of the _key1_ property located in site document library _https://contoso.sharepoint.com/sites/test_

```sh
spo propertybag set --webUrl https://contoso.sharepoint.com/sites/test --key key1 --value value1 --folder '/Shared Documents'
```

Sets the value of the _key1_ property located in folder in site document library _https://contoso.sharepoint.com/sites/test_

```sh
spo propertybag set --webUrl https://contoso.sharepoint.com/sites/test --key key1 --value value1 --folder '/Shared Documents/MyFolder'
```

Sets the value of the _key1_ property located in site list _https://contoso.sharepoint.com/sites/test_

```sh
spo propertybag set --webUrl https://contoso.sharepoint.com/sites/test --key key1 --value value1 --folder /Lists/MyList
```
1 change: 1 addition & 0 deletions docs/manual/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ pages:
- propertybag get: 'cmd/spo/propertybag/propertybag-get.md'
- propertybag list: 'cmd/spo/propertybag/propertybag-list.md'
- propertybag remove: 'cmd/spo/propertybag/propertybag-remove.md'
- propertybag set: 'cmd/spo/propertybag/propertybag-set.md'
- serviceprincipal:
- serviceprincipal grant list: 'cmd/spo/serviceprincipal/serviceprincipal-grant-list.md'
- serviceprincipal grant revoke: 'cmd/spo/serviceprincipal/serviceprincipal-grant-revoke.md'
Expand Down
1 change: 1 addition & 0 deletions src/o365/spo/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export default {
PROPERTYBAG_GET: `${prefix} propertybag get`,
PROPERTYBAG_LIST: `${prefix} propertybag list`,
PROPERTYBAG_REMOVE: `${prefix} propertybag remove`,
PROPERTYBAG_SET: `${prefix} propertybag set`,
SERVICEPRINCIPAL_GRANT_LIST: `${prefix} serviceprincipal grant list`,
SERVICEPRINCIPAL_GRANT_REVOKE: `${prefix} serviceprincipal grant revoke`,
SERVICEPRINCIPAL_PERMISSIONREQUEST_APPROVE: `${prefix} serviceprincipal permissionrequest approve`,
Expand Down
53 changes: 53 additions & 0 deletions src/o365/spo/commands/propertybag/propertybag-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as request from 'request-promise-native';
import Utils from '../../../../Utils';
import { ClientSvcResponseContents, ClientSvcResponse } from "../../spo";
import config from '../../../../config';
import { BasePermissions } from "../../common/base-permissions";

export interface Property {
key: string;
Expand Down Expand Up @@ -247,6 +248,58 @@ export abstract class SpoPropertyBagBaseCommand extends SpoCommand {
});
}

/**
* Gets EffectiveBasePermissions for web return type is "_ObjectType_\":\"SP.Web\".
* Note: This method can be moved as common method if is to be used for other commands.
*/
protected getEffectiveBasePermissions(webObjectIdentity: string, webUrl: string, cmd: CommandInstance): Promise<BasePermissions> {

let basePermissionsResult = new BasePermissions();

const requestOptions: any = {
url: `${webUrl}/_vti_bin/client.svc/ProcessQuery`,
headers: Utils.getRequestHeaders({
authorization: `Bearer ${this.siteAccessToken}`,
'X-RequestDigest': this.formDigestValue
}),
body: `<Request AddExpandoFieldTypeSuffix="true" SchemaVersion="15.0.0.0" LibraryVersion="16.0.0.0" ApplicationName="${config.applicationName}" xmlns="http://schemas.microsoft.com/sharepoint/clientquery/2009"><Actions><Query Id="11" ObjectPathId="5"><Query SelectAllProperties="false"><Properties><Property Name="EffectiveBasePermissions" ScalarProperty="true" /></Properties></Query></Query></Actions><ObjectPaths><Identity Id="5" Name="${webObjectIdentity}" /></ObjectPaths></Request>`
};

if (this.debug) {
cmd.log('Request:');
cmd.log(JSON.stringify(requestOptions));
cmd.log('');
}

return new Promise<BasePermissions>((resolve: any, reject: any): void => {
request.post(requestOptions).then((res: any) => {

if (this.debug) {
cmd.log('Response:');
cmd.log(JSON.stringify(res));
cmd.log('');

cmd.log('Attempt to get the web EffectiveBasePermissions');
}

const json: ClientSvcResponse = JSON.parse(res);
const contents: ClientSvcResponseContents = json.find(x => { return x['ErrorInfo']; });
if (contents && contents.ErrorInfo) {
return reject(contents.ErrorInfo.ErrorMessage || 'ClientSvc unknown error');
}

const permissionsObj = json.find(x => { return x['EffectiveBasePermissions'] });
if (permissionsObj) {
basePermissionsResult.high = permissionsObj['EffectiveBasePermissions']['High'];
basePermissionsResult.low = permissionsObj['EffectiveBasePermissions']['Low'];
return resolve(basePermissionsResult);
}

reject('Cannot proceed. EffectiveBasePermissions not found'); // this is not supposed to happen
}, (err: any): void => { reject(err); })
});
}

/**
* The property bag item data returned from the client.svc/ProcessQuery response
* has to be formatted before displayed since the key, value objects
Expand Down
Loading

0 comments on commit 9cd9cd1

Please sign in to comment.