Skip to content

mgr/dashboard: fix error while accessing roles tab when policy attached - #55462

Merged
nizamial09 merged 1 commit into
ceph:mainfrom
afreen23:fix-64270
Feb 9, 2024
Merged

nizamial09 merged 1 commit into
ceph:mainfrom
afreen23:fix-64270

Conversation

@afreen23

@afreen23 afreen23 commented Feb 6, 2024

Copy link
Copy Markdown
Contributor

Fixes https://tracker.ceph.com/issues/64270

Issue:

Accessing Object->Users-Roles tab causing 500 internal servor error. This is due to the "PermissionPolicies" which are attached to role and backend was not handling this field for rgw roles.
image

Fix:

Added "PermissionPolicies" as the valid field in backend and updated frontend to render the attached policy in formatted JSON
Screenshot from 2024-02-06 14-46-12

Checklist

  • Tracker (select at least one)
    • References tracker ticket
    • Very recent bug; references commit where it was introduced
    • New feature (ticket optional)
    • Doc update (no ticket needed)
    • Code cleanup (no ticket needed)
  • Component impact
    • Affects Dashboard, opened tracker ticket
    • Affects Orchestrator, opened tracker ticket
    • No impact that needs to be tracked
  • Documentation (select at least one)
    • Updates relevant documentation
    • No doc update is appropriate
  • Tests (select at least one)
Show available Jenkins commands
  • jenkins retest this please
  • jenkins test classic perf
  • jenkins test crimson perf
  • jenkins test signed
  • jenkins test make check
  • jenkins test make check arm64
  • jenkins test submodules
  • jenkins test dashboard
  • jenkins test dashboard cephadm
  • jenkins test api
  • jenkins test docs
  • jenkins render docs
  • jenkins test ceph-volume all
  • jenkins test ceph-volume tox
  • jenkins test windows
  • jenkins test rook e2e

@afreen23
afreen23 requested a review from a team as a code owner February 6, 2024 09:55
@afreen23
afreen23 requested review from aaSharma14 and ivoalmeida and removed request for a team February 6, 2024 09:55
@afreen23

afreen23 commented Feb 6, 2024

Copy link
Copy Markdown
Contributor Author

jenkins test make check

@afreen23

afreen23 commented Feb 6, 2024

Copy link
Copy Markdown
Contributor Author

jenkins retest this please

@nizamial09 nizamial09 Feb 7, 2024 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

it is generally not advised to use the function calls in templates because of the way angular change detection is triggered. You can test this out by putting a console log in the function and see how many times its getting called

Maybe we can move this logic or call this from processMeta function instead and do the processing if its required and update the meta.detail_columns with the newer values and then pass these updated value to the template?

Also this change means that we are passing expandedRow[column] through the json stringify even if it is not meant to be. Can we do this conditionally?

@afreen23 afreen23 Feb 7, 2024 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

it is generally not advised to use the function calls in templates because of the way angular change detection is triggered. You can test this out by putting a console log in the function and see how many times its getting called

Maybe we can move this logic or call this from processMeta function instead and do the processing if its required and update the meta.detail_columns with the newer values and then pass these updated value to the template?

I can check that surely.. makes sense if its not efficient.
I liked the idea of moving to processMeta and I can look into that...

Also this change means that we are passing expandedRow[column] through the json stringify even if it is not meant to be. Can we do this conditionally?

I have changed the JSON.stringify replacer function, If you check the other file, if its a non-string, non-json, it will be returned as is.

The reason for doing this was first I tried json pipe which actually not taking care of escape sequences and was rendering them as it is. In a nutshell, it was non formatted json
I tried conditional way as well, and it was hardcoding certain fields or checking type of objects..
The expandedRow[column] is something coming as array of objects or strings, or objects.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

 /**
   * Checks strings for JSON value
   * If yes, returns the parsed value
   * If no, returns the original string
   *
   * For non-strings, return as it is
   **/
  customJSONStringify(rowValue: any) {
    return JSON.stringify(
      rowValue,
      (_key: string, value: any) => {
        if (typeof value === 'string') {
          try {
            const parsedValue = JSON.parse(value); 
            return parsedValue; 
          } catch (e) {
            return value; // returns string but non-json object as it is
          }
        }
        return value; // returns non-string values as it is
      },
      2
    );
  }
}

I have added a custom replacer function, so only valid values which are meant to be parsed will go through..

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

PS: Just one thing more since we are discussing this here, we can have a custom json pipe for our full dashboard or a generic function that can be used across all since this is a very common use case.
But since this is a very specific it did not amke sense to me to make a very prominent change..
We have json dump required at buckets page as well... and perhaps more in future as its a very common thing that comes from entities.

Thanks for the review!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

yup, i agree. probably a generic pipe could be useful later on for us.

@afreen23

afreen23 commented Feb 7, 2024

Copy link
Copy Markdown
Contributor Author

Hi @nizamial09 ,

I have updated the PR , combining all of your comments. PTAL and suggest if there is a better approach, I have come up with this current working now!

Summary of changes:

  • processMeta is processing only meta data like column names, actions, etc.
  • we are processing live data asynchronously in html file
  • The only place where we have access to live data is in this.expandedRow . Therefore I moved data formatting inside that function.
  • JSON.stringifywith the replacer function is recursively checking for objects and stringifying them so I kept it.
    That is helpful for proper formatting on UI. I am also amazed at that since without replacer function its not going for objects properties and leaves them as it is [See below screenshot, PolicyValues are not formatted when used without a replacer function]
    Screenshot from 2024-02-07 21-14-26
    I assume its the JSON.stringify algorithm, one of the many weird things with js..

Still, if there is any better approach for formatting deep nested json objects on UI let me know.
Will be glad to know!

Thanks!

@afreen23

afreen23 commented Feb 7, 2024

Copy link
Copy Markdown
Contributor Author

jenkins retest this please

@nizamial09 nizamial09 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you @afreen23. LGTM!

One thing that we need to do later on is to implement the ability to attach policies to a role from the UI. While testing it, I saw that we are missing that feature.

@nizamial09

Copy link
Copy Markdown
Member

and btw, since you are fixing the bug here I think the title of the PR should clearly represent that.
mgr/dashboard: fix error while accessing roles tab when policy attached.

and there are some unit-test failures.

[lint:html    ] 
[lint:html    ] [htmllint] found 0 errors out of 212 files
[lint:html    ] All files pass linting
[lint:prettier] src/app/shared/datatable/crud-table/crud-table.component.ts
[lint:eslint  ] 
[lint:eslint  ] Linting "ceph-dashboard"...
[lint:eslint  ] 
[lint:eslint  ] All files pass linting.
[lint:eslint  ] 

Try running 'npm run fix' to fix some linting errors. Some errors might need a manual fix.

@afreen23

afreen23 commented Feb 8, 2024

Copy link
Copy Markdown
Contributor Author

One thing that we need to do later on is to implement the ability to attach policies to a role from the UI. While testing it, I saw that we are missing that feature.

Cool! I will create a tracker for this..so as to not miss this..

Fixes https://tracker.ceph.com/issues/64270

Issue:
======
Accessing Object->Users-Roles tab causing 500 internal servor error.
This is due to the "PermissionPolicies" which are attached to role and
backend was not handling this field for rgw roles.

Fix:
====
Added "PermissionPolicies" as the valid field in backend and updated
frontend to render the attached policy in formatted JSON

Signed-off-by: Afreen <[email protected]>
@afreen23 afreen23 changed the title mgr/dashboard: Internal Server Error while accessing the RGW roles tab when policy are attached to roles mgr/dashboard: fix error while accessing roles tab when policy attached Feb 8, 2024
@afreen23

afreen23 commented Feb 8, 2024

Copy link
Copy Markdown
Contributor Author

and btw, since you are fixing the bug here I think the title of the PR should clearly represent that. mgr/dashboard: fix error while accessing roles tab when policy attached.

and there are some unit-test failures.

[lint:html    ] 
[lint:html    ] [htmllint] found 0 errors out of 212 files
[lint:html    ] All files pass linting
[lint:prettier] src/app/shared/datatable/crud-table/crud-table.component.ts
[lint:eslint  ] 
[lint:eslint  ] Linting "ceph-dashboard"...
[lint:eslint  ] 
[lint:eslint  ] All files pass linting.
[lint:eslint  ] 

Try running 'npm run fix' to fix some linting errors. Some errors might need a manual fix.

Done with these...thanks!

@afreen23

afreen23 commented Feb 8, 2024

Copy link
Copy Markdown
Contributor Author

jenkins test make check arm64

@afreen23

afreen23 commented Feb 8, 2024

Copy link
Copy Markdown
Contributor Author

jenkins test dashboard cephadm

@afreen23

afreen23 commented Feb 8, 2024

Copy link
Copy Markdown
Contributor Author

jenkins test dashboard

1 similar comment
@afreen23

afreen23 commented Feb 9, 2024

Copy link
Copy Markdown
Contributor Author

jenkins test dashboard

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants