-
Notifications
You must be signed in to change notification settings - Fork 10
SavedScenario User Management via Engine #1686
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
base: master
Are you sure you want to change the base?
Conversation
ded041a to
2e950cc
Compare
29cf8e2 to
ec68d83
Compare
ec68d83 to
a180647
Compare
noracato
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding all CRUD operations is a great idea.
Let's get a clear grip on who does what, and who holds the truth in the end. Like you said for SavedScenarios it should be myETM who's in control. Maybe we can draft a diagram about interactions and which app has which initiative.
| def copy_roles_from_saved_scenario | ||
| saved_scenario_id = fetch_saved_scenario_id_for(parent.id) | ||
| return false unless saved_scenario_id | ||
|
|
||
| users_data = fetch_saved_scenario_users(saved_scenario_id) | ||
| return false unless users_data | ||
|
|
||
| users_data.each do |user_data| | ||
| scenario_users.create( | ||
| user_id: user_data['user_id'], | ||
| user_email: user_data['user_email'], | ||
| role_id: user_data['role_id'] | ||
| ) | ||
| end | ||
|
|
||
| true | ||
| rescue StandardError | ||
| false | ||
| end | ||
|
|
||
| def fetch_saved_scenario_id_for(scenario_id) | ||
| scenario = Scenario.find_by(id: scenario_id) | ||
| scenario&.metadata&.dig('saved_scenario_id') | ||
| end | ||
|
|
||
| def fetch_saved_scenario_users(saved_scenario_id) | ||
| response = ETEngine::MyEtm.client.get("/api/v1/saved_scenarios/#{saved_scenario_id}/users") | ||
| response.success? ? response.body : nil | ||
| rescue Faraday::Error | ||
| nil | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's rethink this.
- This feels more like a service or job, not core to the model. Mainly because it includes an API call to a resource which is potentially not owned by the user.
- The scenario can possibly belong to multiple saved scenarios. Where lies the truth: like you said this should be dictated by myETM, and indications about roles should then come from myETM, not from within the engine.
| module ETEngine | ||
| # Handles communication with MyETM API. | ||
| module MyEtm | ||
| module_function | ||
|
|
||
| # Returns a Faraday client configured to communicate with MyETM. | ||
| def client | ||
| @client ||= Faraday.new(url: Settings.identity.issuer) do |conn| | ||
| conn.request(:json) | ||
| conn.response(:json) | ||
| conn.response(:raise_error) | ||
| conn.options.timeout = 5 | ||
| end | ||
| end | ||
| end | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wondering about the use case of interacting with myETM not on behalf of the user.
Description
Implements a pass-through API that proxies SavedScenario user management requests to MyETM.
These changes, along with this Myetm PR allow users to manage roles on SavedScenarios via the Engine, and solidify the user coupling functionality so accounts are properly coupled based on the callback actions in MyETM.
Key changes:
/api/v3/saved_scenarios/:id/users)my_etm_clientfor other similar Faraday calls)Still to do
Relevant for this pyetm PR
Closes #1687