-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds ability to resume group membership or sharing calculations and r…
…ecalculate sharing rule calculations
- Loading branch information
Kyle Thornton
committed
Sep 15, 2020
1 parent
824d121
commit 5170280
Showing
6 changed files
with
276 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"commandDescription": "recalculate sharing rules", | ||
"scopeFlagDescription": "scope of recalculations" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"commandDescription": "resumed sharing calculation", | ||
"scopeFlagDescription": "scope of resumed calculations" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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` }; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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` }; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters