Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add scripts for creating a community user and adding profiles to community member groups #10

Merged
39 commits merged into from
Apr 22, 2020

Conversation

Julian88Tex
Copy link
Contributor

@Julian88Tex Julian88Tex commented Apr 13, 2020

Critical Changes

Changes

  • created a script to generate a contact & user that is able to log into the community
  • created an ETL flow which creates a NetworkMemberGroup for the "Customer Community Customer Community - Health Authority", "Customer Community - Hospital Administrator", and "Customer Community - Medical Staff" profiles

Issues Closed

@Julian88Tex Julian88Tex requested a review from jlantz April 13, 2020 07:16
@Julian88Tex
Copy link
Contributor Author

@jlantz this is definitely not ready for review since it's still messy and more a proof of concept right now, but could use your input on a couple of things.

Over this past weekend, I discovered that since a template is being used to create the community, I'm pretty sure I cannot load unpackaged Network Member Group metadata. Basically, this means I cannot give access to the community to the correct Permission Sets/Profiles.

As far as I can tell there are two ways to do this:

  1. I can use the SOAP API. I'm not as familiar with this API, so I was wondering if CumulusCI is capable using it. I noticed a class in the repo referencing but not much cci documentation on it so wasn't sure if it is even possible.
  2. I can use Bulk API with load_dataset task. I know cci can extract and load but can it easily transform the sql database after extraction? If not, I was thinking of writing a script to do this but seems pretty hacky so I was hoping there was a cleaner solution.

Thanks for any help!

sirgeoffrey and others added 27 commits April 13, 2020 14:06
Add Python Script to Automate Id pulling from SQL file
… authority to network memeber group; add a new task to reset the nmg load file to it's original state; switch automatic user creation to medical staff
@Julian88Tex Julian88Tex self-assigned this Apr 17, 2020
@Julian88Tex
Copy link
Contributor Author

@sgovindankutty this is ready for review whenever you get a chance

outside of the code review here are some good steps to test:

  1. pull this branch
  2. run cci flow run qa_org on a scratch org
  3. open org (cci org browser)
  4. navigate to Staff object (which is Contacts renamed)
  5. click on "Julian Joseph"
  6. click button in upper right "Log in to Community as User"
  7. verify community page loads properly with no error

@Julian88Tex Julian88Tex requested a review from prescod April 17, 2020 23:44
@Julian88Tex Julian88Tex changed the title add script for creating a community user and assigning member permission set Add scripts for creating a community user and adding profiles to community member groups Apr 17, 2020
Copy link
Contributor

@jlantz jlantz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good from a CumulusCI perspective. Would still be good to get a review from an Apex dev

localesidkey = 'en_US',
Contactid = newContact.Id,
timezonesidkey = 'Asia/Dubai',
username = newContact.email,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Org-scoped username uniqueness should in theory be on - any chance you've built two orgs with the same value here at the same time just to confirm?

@@ -0,0 +1,47 @@
from cumulusci.tasks.salesforce import BaseSalesforceApiTask

class NgmTransForm(BaseSalesforceApiTask):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't need to be a BaseSalesforceApiTask; it doesn't talk to the API. Looks like BaseTask should be fine here.

return line[index1:index2]

def createInsertLine(id, networkId, count):
insertLine = "INSERT INTO \"NetworkMemberGroup\" VALUES("
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An fstring could clean this up nicely to make it clearer what the method intends to do.

if 'Customer Community - Health Authority' in line:
ids.append(getId(line=line))
if '"Network" VALUES' in line:
networkId.append(getId(line=line))
Copy link
Contributor

@davidmreed davidmreed Apr 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could do something here like

lines_to_look_for = ['Customer Community - Medical Staff', 'Customer Community - Hospital Administrator', 'Customer Community - Health Authority']

if any(search in line for search in lines_to_look_for):
    ids.append(getId(line=line))

and just handle the network id separately.

@@ -0,0 +1,13 @@
from cumulusci.tasks.salesforce import BaseSalesforceApiTask

class NgmSqlReset(BaseSalesforceApiTask):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could also be a BaseTask.

loadFile.write( createInsertLine(id = id, networkId = networkId[0], count = count ))
loadFile.write('\n')

loadFile.close()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a blocker, but I'm wondering if this could be achieved more expeditiously just by talking to the REST API rather than doing a bulk extract/transform/load. Can't say as I've tried to load this particular object before.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davidmreed yeah that would have been ideal but unfortunately you cannot manipulate Network Member Group through Rest API. You can only use SOAP or bulk. If there is a SOAP way that is better I'm all ears!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is... Nuts. I had no idea there were such objects. Thanks for the enlightenment. Bulk it is!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davidmreed Yeah same here. I've learned so much about communities in the last week. It's a whole other world of metadata!

networkId.append(getId(line=line))

loadFile.write('\n')
for id in ids:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a nice function called "enumerate" that allows you to count items at the same time. It would look like:

for count, id in enumerate(ids, 1): ...

# profile you'd like to add a network member group for
if 'Customer Community - Medical Staff' in line:
ids.append(getId(line=line))
if 'Customer Community - Hospital Administrator' in line:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might use elif here?

# Replace 'Customer Community - Medical Staff' with the permission set or
# profile you'd like to add a network member group for
if 'Customer Community - Medical Staff' in line:
ids.append(getId(line=line))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might not need to use a keyword argument syntax for a single-argument function.

mapping: datasets/mapping-nmg-load.yml
sql_path: datasets/nmg-load.sql
4:
task: reset_nmg_sql
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something seems a bit weird about modifying a file and then resetting it. Can't you just make a brand new file and then delete or ignore it?

Why does the repository need to contain datasets/nmg-load.sql at all, if it is just a copy of the template? Instead of appending to it couldn't you read the template, write it, and then continue adding to it? I might miss something.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This way feels a bit risky because if the flow fails (which they often do) then the file could be in a weird state and you'd append to a file in the wrong state.

@Julian88Tex
Copy link
Contributor Author

@prescod @davidmreed @jlantz Thanks for all the feedback! Since none are blockers I'm gonna recommend this for merge, but I've captured the suggestions in #73 so these scripts can be improved down the line.

@Julian88Tex
Copy link
Contributor Author

Julian88Tex commented Apr 18, 2020

@camgood-trac the release engineering team at Salesforce.org has approved this org-setup related PR with non-blocker suggestions that I've captured in issue #73. Feel free to review and/or merge whenever you're ready :-)

@ghost ghost merged commit aef1e24 into master Apr 22, 2020
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants