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

Assign observers from observation report #477

Merged
merged 4 commits into from
Jan 24, 2024

Conversation

tsubik
Copy link
Collaborator

@tsubik tsubik commented Dec 21, 2023

Observation report should be the main source of observers for the observation.

Main changes:

  • Changing observers for observation report should update all report's observations relations.
  • When setting a different observation report for existing observation, we need to make sure observers will be taken from new report.
  • Disable changing observers for observation in admin panel
  • Enable changing observers for observation report in admin panel

We can keep the existing observation-observers relation for now, as changing this (removing that connection) could take a way more time. Changing API, and both applications to not seek observers in observation model but in observation report.

@santostiago
Copy link
Contributor

Mmm... interesting...
But I thought there was the possibility of an observer to make an observation without a report. That is no longer valid?

Copy link
Contributor

@santostiago santostiago left a comment

Choose a reason for hiding this comment

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

👍

@@ -25,17 +25,27 @@ class ObservationReport < ApplicationRecord
# API creating report fails as it's not providing user. Thing to investigate
belongs_to :user, inverse_of: :observation_reports, optional: true
has_many :observation_report_observers, dependent: :destroy
has_many :observers, through: :observation_report_observers
has_many :observers, through: :observation_report_observers, after_add: :self_touch, after_remove: :self_touch
Copy link
Contributor

Choose a reason for hiding this comment

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

mmmm.. I didn't know after_add and after_remove existed.
Cool!

touch unless destroyed? || new_record?
end

def sync_observation_observers
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm guessing in the future this won't be needed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes.

@@ -86,10 +47,10 @@
severity { build(:severity, subcategory: subcategory) }
operator { create(:operator, country: country) }
observation_type { "operator" }
observers { build_list(:observer, 1) }
species { build_list(:species, 1, name: "Species #{Faker::Lorem.sentence}") }
# species { build_list(:species, 1, name: "Species #{Faker::Lorem.sentence}") }
Copy link
Contributor

Choose a reason for hiding this comment

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

mmm.. I think we can remove this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Right. I forgot.

severity
country
governments { build_list(:government, 2) }
# species { build_list(:species, 1, name: "Species #{Faker::Lorem.sentence}") }
Copy link
Contributor

Choose a reason for hiding this comment

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

same

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

👍

@tsubik
Copy link
Collaborator Author

tsubik commented Jan 19, 2024

Observation without report is only possible in "Created" state, which I would say should be named as "Draft" lol. In fact, we are missing all those required fields validations in the backend.

@tsubik tsubik force-pushed the fix/observation_report_observers branch 2 times, most recently from dc17fa8 to 74673d0 Compare January 19, 2024 16:23
@tsubik tsubik force-pushed the fix/observation_report_observers branch from 74673d0 to f6858c4 Compare January 22, 2024 15:55
@tsubik tsubik force-pushed the fix/observation_report_observers branch from 1cfb9cf to 78f83e3 Compare January 23, 2024 17:00
@tsubik tsubik merged commit f390604 into develop Jan 24, 2024
3 checks passed
@tsubik tsubik deleted the fix/observation_report_observers branch January 24, 2024 17:47
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.

None yet

2 participants