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

Migrate policy API to remove policy members #10452

Merged
merged 27 commits into from
Sep 30, 2022

Conversation

iwiznia
Copy link
Contributor

@iwiznia iwiznia commented Aug 18, 2022

Hold on https://github.com/Expensify/Web-Expensify/pull/34618

Needs:

Details

Fixed Issues

$ https://github.com/Expensify/Expensify/issues/211560
$ #11067

Tests

No QA:

  • Play around with the site, make sure all is working (create chat, send/edit/delete message, change profile settings, create/delete workspace, signout/in, change language, profile settings). This can be skipped in QA since it's covered by the regression testing
  • Debug the activeClients code and check it is working properly
  • Trigger an error by modifying the code, check the error is returned in all the appropriate rows and RBR is shown and the errors are dismissible

QA:

  • Invite a user to a workspace
  • Reload the page
  • On another browser window in incognito mode sign in as that user
  • On the window where you invited the user:
    • Remove the same user from the workspace
    • Check the user gets removed from the policy members list
    • Check the user gets removed from the members in the #announce channel of the workspace
    • Check the workspace chat for the expenses of the user is archived (you need to find this by email or have it selected before)
  • On the window of the user you removed:
    • Check the #announce channel of the policy is removed from the LHN and that if you were looking at it, you see the You don't have access to this chat message
    • Check the workspace chat for the expenses of the user is archived
  • Invite a new user (that does not exist in expensify) to the policy, check it works properly
  • Navigate to a report url with an invalidID like http://localhost:8080/r/hello, check you see the You don't have access to this chat message
  • Navigate to a report url with the ID of a report you don't have access to like http://localhost:8080/r/1, check you see the You don't have access to this chat message

image

PR Review Checklist

Contributor (PR Author) Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • iOS / native
    • Android / native
    • iOS / Safari
    • Android / Chrome
    • MacOS / Chrome
    • MacOS / Desktop
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product was added in all src/languages/* files
    • I verified any copy / text that was added to the app is correct English and approved by marketing by tagging the marketing team on the original GH to get the correct copy.
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • Any functional components have the displayName property
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG)
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • I have checked off every checkbox in the PR author checklist, including those that don't apply to this PR.

PR Reviewer Checklist

The Contributor+ will copy/paste it into a new comment and complete it after the author checklist is completed

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • I checked that screenshots or videos are included for tests on all platforms
  • I verified tests pass on all platforms & I tested again on:
    • iOS / native
    • Android / native
    • iOS / Safari
    • Android / Chrome
    • MacOS / Chrome
    • MacOS / Desktop
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I verified proper code patterns were followed (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick).
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product was added in all src/languages/* files
    • I verified any copy / text that was added to the app is correct English and approved by marketing by tagging the marketing team on the original GH to get the correct copy.
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • Any functional components have the displayName property
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG)
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

QA Steps

  • Verify that no errors appear in the JS console

Screenshots

Web

Screen.Recording.2022-09-28.at.7.57.11.PM.mov

Mobile Web

Desktop

iOS

Android

@iwiznia iwiznia self-assigned this Aug 18, 2022
@iwiznia iwiznia changed the title Remove unnneded code for DeleteMembersFromWorkspace Migrate policy API to remove policy members Sep 13, 2022
@iwiznia iwiznia changed the title Migrate policy API to remove policy members [HOLD web] Migrate policy API to remove policy members Sep 13, 2022
@iwiznia iwiznia marked this pull request as ready for review September 13, 2022 16:09
@iwiznia iwiznia requested a review from a team as a code owner September 13, 2022 16:09
@iwiznia
Copy link
Contributor Author

iwiznia commented Sep 13, 2022

This is on hold, but let's get it reviewed in the meantime

@melvin-bot melvin-bot bot requested review from tgolen and removed request for a team September 13, 2022 16:09
@@ -24,7 +24,9 @@ function isReady() {
Onyx.connect({
key: ONYXKEYS.ACTIVE_CLIENTS,
callback: (val) => {
activeClients = !val ? [] : val;
if (val) {
activeClients = _.unique(activeClients.concat(val));
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion: Use if (val && activeClients.indexOf(value) < 0) instead of _.unique(). I think it would be better to do if you're trying to prevent the same value being put into the array again.

(sorry, I'm jaded against _.unique() after learning that it's not very performant).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not that it matters much here, since at most there will be 20 items, but updated

@@ -1263,6 +1263,7 @@ function editReportComment(reportID, originalReportAction, textForNewComment) {
isEdited: true,
html: htmlForNewComment,
text: textForNewComment,
type: originalReportAction.message[0].type,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this change in this PR? It seems unrelated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is not. Messages is an array and we were not sending the type in the optimistic action (neither in the action from the server), so when we replace the message fully now, this property was not set and was causing issues (we would render the comment as fragment.text here

.value();
const policyMemberList = lodashGet(this.props, 'policyMemberList', {});
const removableMembers = [];
let data = _.map(policyMemberList, (value, email) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

value is very ambiguious. Name suggestion: policyMember

@iwiznia iwiznia requested a review from tgolen September 13, 2022 16:32
.value();
const policyMemberList = lodashGet(this.props, 'policyMemberList', {});
const removableMembers = [];
let data = _.map(policyMemberList, (policyMember, email) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

This logic is a bit weird. You are using a map to build data but also using it to generate removableMembers values. I feel like this would have been easier with a _.each to do different things.

Anyway besides that, I feel like data would be a lot cleaner with the chain. Its weird that it's doing some things here and then in the next line it does sortBy. Also its not doing filter so it can end up with empty values which will fail when lowerCase is done,
image

I think data should be generated via chain and removableMembers should keep its operations separate. Or use a _.each to build both but that's extra work which I feel is not worth it just yet here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated to use each

Copy link
Contributor

@chiragsalian chiragsalian left a comment

Choose a reason for hiding this comment

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

I found two issues. Besides those the rest LGTM

const policyMemberList = lodashGet(this.props, 'policyMemberList', {});
const removableMembers = [];
let data = [];
_.each(policyMemberList, (policyMember, email) => {
Copy link
Contributor

@chiragsalian chiragsalian Sep 15, 2022

Choose a reason for hiding this comment

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

The update here to each alone is not correct. Notice in the previous code we filter to remove empty values but that's not here.

So over here I think you should not update data if details is empty otherwise you'll still get the same error when testing locally because it cannot do lowercase if value is empty. Sample data provided here. This will result in an app crash when members page is clicked which is bad,
image

So my suggestion is to update this, to be,

if (details) {
    data.push({
        ...policyMember,
        ...details,
    });
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That was a hack that someone added because the app crashed and instead of fixing the real issue, they just removed the detail from the list, which is wrong. This works if you are using the latest version of auth, that returns personal details for all emails, even if they don't have explicitly set a name.

Well, at least I hope the crash you saw was due to outdated auth, sounds like it because it's the same I was getting before sending the auth fix.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, you also need the web PR of course

Copy link
Contributor

Choose a reason for hiding this comment

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

Odd, im sure i updates all repos and did a makeall yesterday. Maybe its buggy on an existing workspace, I'll try again on a fresh workspace.
If its buggy on existing data we still have to consider it so that users existing workspaces don't crash.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should not be buggy on existing data. Maybe.you need to sign out and back in though, not sure.

@@ -24,7 +24,9 @@ function isReady() {
Onyx.connect({
key: ONYXKEYS.ACTIVE_CLIENTS,
callback: (val) => {
activeClients = !val ? [] : val;
if (val && activeClients.indexOf(val) < 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Whats this change for? When i test your PR the command DeleteMembersFromWorkspace never gets called in the network tab and I think its because of the code here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had to refactor this a bit because this was using the array merging feature of onyx that we changed. It is not called in the flow of that api command.

@chiragsalian
Copy link
Contributor

Discussed 1:1 with ioni. The app still crashes and network requests are a bit broken.
We found out the crash occurred if a non-existing user was invited.
We were able to confirm the activeClients change is causing the network requests problem.

I believe he mentioned he'll debug both on Monday now that he has more clues on why its breaking.

@iwiznia
Copy link
Contributor Author

iwiznia commented Sep 30, 2022

ok, updated to fix that.

@Santhosh-Sellavel
Copy link
Collaborator

Screenshot 2022-09-30 at 10 46 09 PM

Error message text is not centered here

Copy link
Collaborator

@Santhosh-Sellavel Santhosh-Sellavel left a comment

Choose a reason for hiding this comment

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

Thanks, @iwiznia, all looks good now!

@iwiznia iwiznia merged commit 607f8e9 into main Sep 30, 2022
@iwiznia iwiznia deleted the ionatan_DeleteMembersFromWorkspace branch September 30, 2022 19:21
@melvin-bot melvin-bot bot added the Emergency label Sep 30, 2022
@melvin-bot
Copy link

melvin-bot bot commented Sep 30, 2022

@iwiznia looks like this was merged without passing tests. Please add a note explaining why this was done and remove the Emergency label if this is not an emergency.

@iwiznia
Copy link
Contributor Author

iwiznia commented Sep 30, 2022

Not true Melvin, go home, you are drunk
image

@iwiznia iwiznia removed the Emergency label Sep 30, 2022
@OSBotify
Copy link
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@OSBotify
Copy link
Contributor

🚀 Deployed to staging by @iwiznia in version: 1.2.11-0 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@OSBotify
Copy link
Contributor

OSBotify commented Oct 5, 2022

🚀 Deployed to production by @AndrewGable in version: 1.2.11-4 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@mananjadhav
Copy link
Collaborator

I am tagging this PR to highlight an issue fixed here. All conditions in ternary expressions or left-hand operands on conditional renders, should be boolean. This PR is one of the PRs that uses conditional render with string operands, hence I am tagging it here for the contributors to check.

We've also updated the item in the checklist with this PR to avoid this issue in the future.

style={[styles.flex1, styles.justifyContentEnd, styles.overflowHidden]}
onLayout={event => this.setState({skeletonViewContainerHeight: event.nativeEvent.layout.height})}
<FullPageNotFoundView
shouldShow={!this.props.report.reportID}
Copy link
Contributor

Choose a reason for hiding this comment

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

If we are viewing a report and it gets deleted we will get the not found view, this caused #28969. We should have taken into consideration if the report was previously accessible.

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.

10 participants