Class: CollavreLinear::ProjectLink
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- CollavreLinear::ProjectLink
- Defined in:
- app/models/collavre_linear/project_link.rb
Class Method Summary collapse
-
.team_webhook_secret(team_id) ⇒ Object
The one signing secret a team's single Linear webhook uses, denormalized across the team's sibling ProjectLinks.
Instance Method Summary collapse
-
#update_webhook_secret!(secret) ⇒ Object
Store the signing secret the admin copied from Linear's webhook settings, propagating it to every sibling ProjectLink of the team.
Class Method Details
.team_webhook_secret(team_id) ⇒ Object
The one signing secret a team's single Linear webhook uses, denormalized across the team's sibling ProjectLinks. Returns any non-blank sibling's value: a row created concurrently with the admin's paste can commit blank (adopt ran before the paste was visible), and webhook verification may resolve a delivery to that blank row — so the TEAM's secret, not one arbitrary row's column, is the authority. Reads the decrypted attribute (a raw pick would be ciphertext). Nil when the team has no secret yet.
56 57 58 59 60 |
# File 'app/models/collavre_linear/project_link.rb', line 56 def self.team_webhook_secret(team_id) return if team_id.blank? where(team_id: team_id).filter_map { |link| link.webhook_secret.presence }.first end |
Instance Method Details
#update_webhook_secret!(secret) ⇒ Object
Store the signing secret the admin copied from Linear's webhook settings, propagating it to every sibling ProjectLink of the team. Linear signs all of a team's deliveries with the one secret its single webhook carries, and find_project_link resolves a delivery to an arbitrary team sibling, so all must hold the same value or a sibling 401s. update_column applies encryption (a raw write would leak plaintext); assign self last so its in-memory attribute reflects the pasted value.
41 42 43 44 45 46 47 |
# File 'app/models/collavre_linear/project_link.rb', line 41 def update_webhook_secret!(secret) self.class.where(team_id: team_id).where.not(id: id).find_each do |sibling| sibling.update_column(:webhook_secret, secret) end update_column(:webhook_secret, secret) secret end |