diff --git a/README.md b/README.md index 395b3c3..a46d664 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,8 @@ Link the plugin: sfdx plugins:link . * [`sfdx texei:package:dependencies:install [-k ] [-b ] [-p ] [-s ] [-n ] [-w ] [-r] [-a ] [-v ] [-u ] [--apiversion ] [--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 ] [-p ] [--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 ] [--apiversion ] [--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 ] [-u ] [--apiversion ] [--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 ] [-u ] [--apiversion ] [--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 ] [-u ] [--apiversion ] [--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 ] [-v ] [-u ] [--apiversion ] [--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 -v [-p ] [--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) @@ -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 ] [--apiversion ] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]` + +suspend sharing calculation + +``` +USAGE + $ sfdx texei:sharingcalc:recalculatte [-s ] [-u ] [--apiversion ] [--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 ] [-u ] [--apiversion ] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]` + +resume sharing calculation + +``` +USAGE + $ sfdx texei:sharingcalc:resume [-s ] [-u ] [--apiversion ] [--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 ] [-u ] [--apiversion ] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]` suspend sharing calculation ``` USAGE - $ sfdx texei:sharingcalc:suspend [-s ] [-u ] [--apiversion ] [--json] [--loglevel + $ sfdx texei:sharingcalc:suspend [-s ] [-u ] [--apiversion ] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL] OPTIONS @@ -340,7 +404,7 @@ OPTIONS this command invocation EXAMPLE - $ sfdx texei:sharingcalc:suspend" + $ sfdx texei:sharingcalc:suspend" Sharing calculations suspended ``` diff --git a/messages/sharingcalc-recalculate.json b/messages/sharingcalc-recalculate.json new file mode 100644 index 0000000..6f4a953 --- /dev/null +++ b/messages/sharingcalc-recalculate.json @@ -0,0 +1,4 @@ +{ + "commandDescription": "recalculate sharing rules", + "scopeFlagDescription": "scope of recalculations" +} diff --git a/messages/sharingcalc-resume.json b/messages/sharingcalc-resume.json new file mode 100644 index 0000000..382e2c3 --- /dev/null +++ b/messages/sharingcalc-resume.json @@ -0,0 +1,4 @@ +{ + "commandDescription": "resumed sharing calculation", + "scopeFlagDescription": "scope of resumed calculations" +} diff --git a/src/commands/texei/sharingcalc/recalculate.ts b/src/commands/texei/sharingcalc/recalculate.ts new file mode 100644 index 0000000..b0fb3ad --- /dev/null +++ b/src/commands/texei/sharingcalc/recalculate.ts @@ -0,0 +1,98 @@ +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 { + 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`); + + try { + await page.click( + `#ep > .pbBody > .pbSubsection > .detailList > tbody > .detailRow > td > input[name="rule_recalc"].btn` + ); + } catch (ex) { + console.log('Unable to recalculate sharing.', ex.message); + } + + await navigationPromise; + + this.debug(`DEBUG Closing browser`); + + await browser.close(); + + this.ux.stopSpinner("Done."); + + return { message: `Recalculated ${mapSharingLabel.get(this.flags.scope)}s` }; + } +} diff --git a/src/commands/texei/sharingcalc/resume.ts b/src/commands/texei/sharingcalc/resume.ts new file mode 100644 index 0000000..1070037 --- /dev/null +++ b/src/commands/texei/sharingcalc/resume.ts @@ -0,0 +1,111 @@ +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 { + 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`); + + try { + // 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` + ); + } + } catch (ex) { + console.log('Unable to resume sharing.', ex.message); + } + + await navigationPromise; + + this.debug(`DEBUG Closing browser`); + + await browser.close(); + + this.ux.stopSpinner("Done."); + + return { message: `Resumed ${mapSharingLabel.get(this.flags.scope)} Calculations` }; + } +} diff --git a/src/commands/texei/sharingcalc/suspend.ts b/src/commands/texei/sharingcalc/suspend.ts index c938f1d..e58b0cc 100644 --- a/src/commands/texei/sharingcalc/suspend.ts +++ b/src/commands/texei/sharingcalc/suspend.ts @@ -78,19 +78,23 @@ export default class Suspend extends SfdxCommand { this.debug(`DEBUG Clicking 'Suspend' button`); - // Suspend either Group Membership or Sharing Rules - if (this.flags.scope === "groupMembership") { - page.on("dialog", dialog => { - dialog.accept(); - }); - - await page.click( - "#gmSect > .pbBody > .pbSubsection > .detailList > tbody > .detailRow > td > .btn" - ); - } else { - await page.click( - "#ep > .pbBody > .pbSubsection > .detailList > tbody > .detailRow > td > .btn" - ); + try { + // Suspend either Group Membership or Sharing Rules + if (this.flags.scope === "groupMembership") { + page.on("dialog", dialog => { + dialog.accept(); + }); + + await page.click( + `#gmSect > .pbBody > .pbSubsection > .detailList > tbody > .detailRow > td > input[name="group_suspend"].btn` + ); + } else { + await page.click( + '#ep > .pbBody > .pbSubsection > .detailList > tbody > .detailRow > td > input[name="rule_suspend"].btn' + ); + } + } catch (ex) { + console.log('Unable to suspend sharing.', ex.message); } await navigationPromise; @@ -103,4 +107,4 @@ export default class Suspend extends SfdxCommand { return { message: `Suspended ${mapSharingLabel.get(this.flags.scope)} Calculations` }; } -} \ No newline at end of file +}