Skip to content

Conversation

@johnpinto1
Copy link
Contributor

@johnpinto1 johnpinto1 commented Jul 8, 2021

Fixes # 561.

These changes were suggested by @briri . Will fix tests next week.

Changes proposed in this PR:
On save or update of an Org that is managed we add all the
token_permission_types for API access using a before_save callback.

NOTE: The Super Admin will need to go to Edit Org page and save (with no changes) for the token_permission_types to be added.

Test:

  • I have tested this by finding an Org that was managed and did not have token_permission_types set.
  • As Super Admin I went to Edit Org page and saved.
  • Then I checked if token_permission_types were set and they were.
  • Furthermore, I could make API calls now.

Here is the test on my local docker rails console.

irb(main):029:0> f1000 = Org.where(name: "F1000")[0]

Before editing Org
irb(main):031:0> f1000.token_permission_types
TokenPermissionType Load (1.1ms) SELECT "token_permission_types".* FROM "token_permission_types" INNER JOIN "org_token_permissions" ON "token_permission_types"."id" = "org_token_permissions"."token_permission_type_id" WHERE "org_token_permissions"."org_id" = $1 LIMIT $2 [["org_id", 1071570973], ["LIMIT", 11]]
=> #<ActiveRecord::Associations::CollectionProxy []> <---- (NO org_token_permissions for Org)

After editing Org
irb(main):032:0> f1000.token_permission_types
TokenPermissionType Load (1.7ms) SELECT "token_permission_types".* FROM "token_permission_types" INNER JOIN "org_token_permissions" ON "token_permission_types"."id" = "org_token_permissions"."token_permission_type_id" WHERE "org_token_permissions"."org_id" = $1 LIMIT $2 [["org_id", 1071570973], ["LIMIT", 11]]
=> #<ActiveRecord::Associations::CollectionProxy [#<TokenPermissionType id: 1, token_type: "guidances", text_description: "allows a user access to the guidances api endpoint", created_at: "2017-06-23 08:02:14", updated_at: "2017-06-23 08:02:14">, #<TokenPermissionType id: 2, token_type: "plans", text_description: "allows a user access to the plans api endpoint", created_at: "2017-06-23 08:02:14", updated_at: "2017-06-23 08:02:14">, #<TokenPermissionType id: 3, token_type: "templates", text_description: "allows a user access to the templates api endpoint", created_at: "2017-06-23 08:02:14", updated_at: "2017-06-23 08:02:14">, #<TokenPermissionType id: 4, token_type: "statistics", text_description: "allows a user access to the statistics api endpoin...", created_at: "2017-06-23 08:02:14", updated_at: "2017-06-23 08:02:14">]> <---- (Has all org_token_permissions for Org)

@johnpinto1 johnpinto1 force-pushed the bug_561_api_keys_issues_missing_org_token_permissions branch from 418c9e6 to 64e3677 Compare July 8, 2021 12:05
… a managed

Org.

Change:
 - On save or update of an Org that is managed we add all the
token_permission_types for API access using a before_save callback.
@johnpinto1 johnpinto1 force-pushed the bug_561_api_keys_issues_missing_org_token_permissions branch from 64e3677 to 3128e25 Compare July 8, 2021 13:28
Copy link
Contributor

@briri briri 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 @johnpinto1

@raycarrick-ed raycarrick-ed merged commit 206f7d5 into DMPRoadmap:master Jul 15, 2021
portagenetwork pushed a commit to portagenetwork/roadmap that referenced this pull request Feb 24, 2022
…_api_keys_issues_missing_org_token_permissions

Bug 561 api keys issues missing org_token_permissions
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.

3 participants