Skip to content

Commit

Permalink
Adds ability to resume group membership or sharing calculations and r…
Browse files Browse the repository at this point in the history
…ecalculate sharing rule calculations
  • Loading branch information
Kyle Thornton committed Sep 15, 2020
1 parent 824d121 commit 5170280
Show file tree
Hide file tree
Showing 6 changed files with 276 additions and 3 deletions.
68 changes: 66 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ Link the plugin: sfdx plugins:link .
* [`sfdx texei:package:dependencies:install [-k <string>] [-b <string>] [-p <string>] [-s <string>] [-n <string>] [-w <number>] [-r] [-a <string>] [-v <string>] [-u <string>] [--apiversion <string>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]`](#sfdx-texeipackagedependenciesinstall--k-string--b-string--p-string--s-string--n-string--w-number--r--a-string--v-string--u-string---apiversion-string---json---loglevel-tracedebuginfowarnerrorfataltracedebuginfowarnerrorfatal)
* [`sfdx texei:profile:clean [-k <string>] [-p <string>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]`](#sfdx-texeiprofileclean--k-string--p-string---json---loglevel-tracedebuginfowarnerrorfataltracedebuginfowarnerrorfatal)
* [`sfdx texei:sharedactivities:enable [-u <string>] [--apiversion <string>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]`](#sfdx-texeisharedactivitiesenable--u-string---apiversion-string---json---loglevel-tracedebuginfowarnerrorfataltracedebuginfowarnerrorfatal)
* [`sfdx texei:sharingcalc:recalculate [-s <string>] [-u <string>] [--apiversion <string>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]`](#sfdx-texeisharingcalcrecalculate--s-string--u-string---apiversion-string---json---loglevel-tracedebuginfowarnerrorfataltracedebuginfowarnerrorfatal)
* [`sfdx texei:sharingcalc:resume [-s <string>] [-u <string>] [--apiversion <string>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]`](#sfdx-texeisharingcalcresume--s-string--u-string---apiversion-string---json---loglevel-tracedebuginfowarnerrorfataltracedebuginfowarnerrorfatal)
* [`sfdx texei:sharingcalc:suspend [-s <string>] [-u <string>] [--apiversion <string>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]`](#sfdx-texeisharingcalcsuspend--s-string--u-string---apiversion-string---json---loglevel-tracedebuginfowarnerrorfataltracedebuginfowarnerrorfatal)
* [`sfdx texei:skinnyprofile:retrieve [-t <string>] [-v <string>] [-u <string>] [--apiversion <string>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]`](#sfdx-texeiskinnyprofileretrieve--t-string--v-string--u-string---apiversion-string---json---loglevel-tracedebuginfowarnerrorfataltracedebuginfowarnerrorfatal)
* [`sfdx texei:source:customlabel:replace -l <string> -v <string> [-p <string>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]`](#sfdx-texeisourcecustomlabelreplace--l-string--v-string--p-string---json---loglevel-tracedebuginfowarnerrorfataltracedebuginfowarnerrorfatal)
Expand Down Expand Up @@ -315,13 +317,75 @@ EXAMPLE

_See code: [src/commands/texei/sharedactivities/enable.ts](https://github.com/texei/texei-sfdx-plugin/blob/v1.6.3/src/commands/texei/sharedactivities/enable.ts)_

## `sfdx texei:sharingcalc:recalculate [-u <string>] [--apiversion <string>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]`

suspend sharing calculation

```
USAGE
$ sfdx texei:sharingcalc:recalculatte [-s <string>] [-u <string>] [--apiversion <string>] [--json] [--loglevel
trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]
OPTIONS
-s, --scope=sharingRule [default: sharingRule] scope of
recalculation
-u, --targetusername=targetusername username or alias for the target
org; overrides default target org
--apiversion=apiversion override the api version used for
api requests made by this command
--json format output as json
--loglevel=(trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL) [default: warn] logging level for
this command invocation
EXAMPLE
$ sfdx texei:sharingcalc:recalculate"
Recalculated Sharing Rules
```

_See code: [src/commands/texei/sharingcalc/recalculate.ts](https://github.com/texei/texei-sfdx-plugin/blob/v1.6.3/src/commands/texei/sharingcalc/recalculate.ts)_

## `sfdx texei:sharingcalc:resume [-s <string>] [-u <string>] [--apiversion <string>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]`

resume sharing calculation

```
USAGE
$ sfdx texei:sharingcalc:resume [-s <string>] [-u <string>] [--apiversion <string>] [--json] [--loglevel
trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]
OPTIONS
-s, --scope=sharingRule|groupMembership [default: sharingRule] scope of
resumed calculations
-u, --targetusername=targetusername username or alias for the target
org; overrides default target org
--apiversion=apiversion override the api version used for
api requests made by this command
--json format output as json
--loglevel=(trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL) [default: warn] logging level for
this command invocation
EXAMPLE
$ sfdx texei:sharingcalc:resume"
Sharing calculations resumeed
```

_See code: [src/commands/texei/sharingcalc/suspend.ts](https://github.com/texei/texei-sfdx-plugin/blob/v1.6.3/src/commands/texei/sharingcalc/suspend.ts)_

## `sfdx texei:sharingcalc:suspend [-s <string>] [-u <string>] [--apiversion <string>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]`

suspend sharing calculation

```
USAGE
$ sfdx texei:sharingcalc:suspend [-s <string>] [-u <string>] [--apiversion <string>] [--json] [--loglevel
$ sfdx texei:sharingcalc:suspend [-s <string>] [-u <string>] [--apiversion <string>] [--json] [--loglevel
trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]
OPTIONS
Expand All @@ -340,7 +404,7 @@ OPTIONS
this command invocation
EXAMPLE
$ sfdx texei:sharingcalc:suspend"
$ sfdx texei:sharingcalc:suspend"
Sharing calculations suspended
```

Expand Down
4 changes: 4 additions & 0 deletions messages/sharingcalc-recalculate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"commandDescription": "recalculate sharing rules",
"scopeFlagDescription": "scope of recalculations"
}
4 changes: 4 additions & 0 deletions messages/sharingcalc-resume.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"commandDescription": "resumed sharing calculation",
"scopeFlagDescription": "scope of resumed calculations"
}
94 changes: 94 additions & 0 deletions src/commands/texei/sharingcalc/recalculate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import { flags, core, SfdxCommand } from "@salesforce/command";
import * as puppeteer from "puppeteer";

// Initialize Messages with the current plugin directory
core.Messages.importMessagesDirectory(__dirname);

// Load the specific messages for this file. Messages from @salesforce/command, @salesforce/core,
// or any library that is using the messages framework can also be loaded this way.
const messages = core.Messages.loadMessages(
"texei-sfdx-plugin",
"sharingcalc-recalculate"
);

const mapSharingLabel = new Map([
['sharingRule', 'Sharing Rule']
]);

export default class Recalculate extends SfdxCommand {
public static description = messages.getMessage("commandDescription");

public static examples = [
`$ sfdx texei:sharingcalc:recalculate" \nRecalculated Sharing Rules\n`
];

protected static flagsConfig = {
scope: flags.string({
char: "s",
description: messages.getMessage("scopeFlagDescription"),
required: false,
options: ["sharingRule"],
default: "sharingRule"
})
};

// Comment this out if your command does not require an org username
protected static requiresUsername = true;

// Comment this out if your command does not support a hub org username
protected static requiresDevhubUsername = false;

// Set this to true if your command requires a project workspace; 'requiresProject' is false by default
protected static requiresProject = false;

public async run(): Promise<any> {
let result = {};

await this.reclaculateSharing();

return result;
}

private async reclaculateSharing() {
const instanceUrl = this.org.getConnection().instanceUrl;

const SHARING_CALC_PATH = "/p/own/DeferSharingSetupPage";

this.ux.startSpinner(`Resuming ${mapSharingLabel.get(this.flags.scope)} Calculations`, null, { stdout: true });
this.debug(`DEBUG Login to Org`);

const browser = await puppeteer.launch({
args: ["--no-sandbox", "--disable-setuid-sandbox"],
headless: !(process.env.BROWSER_DEBUG === "true")
});
const page = await browser.newPage();
await page.goto(
`${instanceUrl}/secur/frontdoor.jsp?sid=${
this.org.getConnection().accessToken
}`,
{ waitUntil: ["domcontentloaded", "networkidle0"] }
);
const navigationPromise = page.waitForNavigation();

this.debug(`DEBUG Opening Defer Sharing Calculations page`);

await page.goto(`${instanceUrl + SHARING_CALC_PATH}`);
await navigationPromise;

this.debug(`DEBUG Clicking 'Recalculate' button`);

await page.click(
`#ep > .pbBody > .pbSubsection > .detailList > tbody > .detailRow > td > input[name="rule_recalc"].btn`
);

await navigationPromise;

this.debug(`DEBUG Closing browser`);

await browser.close();

this.ux.stopSpinner("Done.");

return { message: `Recalculated ${mapSharingLabel.get(this.flags.scope)}s` };
}
}
107 changes: 107 additions & 0 deletions src/commands/texei/sharingcalc/resume.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import { flags, core, SfdxCommand } from "@salesforce/command";
import * as puppeteer from "puppeteer";

// Initialize Messages with the current plugin directory
core.Messages.importMessagesDirectory(__dirname);

// Load the specific messages for this file. Messages from @salesforce/command, @salesforce/core,
// or any library that is using the messages framework can also be loaded this way.
const messages = core.Messages.loadMessages(
"texei-sfdx-plugin",
"sharingcalc-resume"
);

const mapSharingLabel = new Map([
['sharingRule', 'Sharing Rule'],
['groupMembership', 'Group Membership']
]);

export default class Resume extends SfdxCommand {
public static description = messages.getMessage("commandDescription");

public static examples = [
`$ sfdx texei:sharingcalc:resume" \nSharing calculations resumed\n`
];

protected static flagsConfig = {
scope: flags.string({
char: "s",
description: messages.getMessage("scopeFlagDescription"),
required: false,
options: ["sharingRule", "groupMembership"],
default: "sharingRule"
})
};

// Comment this out if your command does not require an org username
protected static requiresUsername = true;

// Comment this out if your command does not support a hub org username
protected static requiresDevhubUsername = false;

// Set this to true if your command requires a project workspace; 'requiresProject' is false by default
protected static requiresProject = false;

public async run(): Promise<any> {
let result = {};

await this.resumeSharingCalc();

return result;
}

private async resumeSharingCalc() {
const instanceUrl = this.org.getConnection().instanceUrl;

const SHARING_CALC_PATH = "/p/own/DeferSharingSetupPage";

this.ux.startSpinner(`Resuming ${mapSharingLabel.get(this.flags.scope)} Calculations`, null, { stdout: true });
this.debug(`DEBUG Login to Org`);

const browser = await puppeteer.launch({
args: ["--no-sandbox", "--disable-setuid-sandbox"],
headless: !(process.env.BROWSER_DEBUG === "true")
});
const page = await browser.newPage();
await page.goto(
`${instanceUrl}/secur/frontdoor.jsp?sid=${
this.org.getConnection().accessToken
}`,
{ waitUntil: ["domcontentloaded", "networkidle0"] }
);
const navigationPromise = page.waitForNavigation();

this.debug(`DEBUG Opening Defer Sharing Calculations page`);

await page.goto(`${instanceUrl + SHARING_CALC_PATH}`);
await navigationPromise;

this.debug(`DEBUG Clicking 'Resume' button`);

// Resume either Group Membership or Sharing Rules
if (this.flags.scope === "groupMembership") {
await page.click(
`#gmSect > .pbBody > .pbSubsection > .detailList > tbody > .detailRow > td > input[name="group_resume"].btn`
);

// click the yes button to recaulcate group memberships immediately
await page.click(
`div#group_resume_dialog_buttons > input[value=" Yes "]`
);
} else {
await page.click(
`#ep > .pbBody > .pbSubsection > .detailList > tbody > .detailRow > td > input[name="rule_resume"].btn`
);
}

await navigationPromise;

this.debug(`DEBUG Closing browser`);

await browser.close();

this.ux.stopSpinner("Done.");

return { message: `Resumed ${mapSharingLabel.get(this.flags.scope)} Calculations` };
}
}
2 changes: 1 addition & 1 deletion src/commands/texei/sharingcalc/suspend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,4 @@ export default class Suspend extends SfdxCommand {

return { message: `Suspended ${mapSharingLabel.get(this.flags.scope)} Calculations` };
}
}
}

0 comments on commit 5170280

Please sign in to comment.