Bug 561 api keys issues missing org_token_permissions #2966
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
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)