-
Notifications
You must be signed in to change notification settings - Fork 6
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
GO-370 Signing tags #227
GO-370 Signing tags #227
Conversation
mirrec
commented
Dec 4, 2023
- Nedaval som tu zatial ziadnu abstrakciu, len natvrdo sa zavola metoda v callbacku.
- Pridal som unique indexy, lebo cisto teoreticky by nam tam mohli nejako povznikat aj duplikaty a to by nas neskor mohlo strielat do nohy.
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.
Trosku treba este postruhat
app/models/tenant.rb
Outdated
|
||
has_many :boxes, dependent: :destroy | ||
has_many :automation_rules, class_name: "Automation::Rule", dependent: :destroy | ||
has_many :tags, dependent: :destroy | ||
has_many :signature_requested_to_tags |
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.
asi by som pouzil signature_requested_from_tags
aleb to_be_signed_by_tags
lebo toto znie divne.
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.
a tu sa bavime iba o nazve tej asociacie z pohladu tenanta? alebo riesis (aj) nazov classy?
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.
oboje
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.
signature_requested_from_tags
nie, lebo to hovori, ze od koho
ta poziadavka prisla a my chceme presne opacnu vec: na koho / ku komu
prisla. a tam je to request to
https://www.quora.com/Which-is-correct-request-to-or-request-for-in-English
to_be_signed_by_tags
mi dava zmysel. ale potom aj ten vseobecny podpisovaci stitok "na podpis" pomenujem ToBeSignedTag
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.
Podla mna to motas.
Signature Request From - ziadam podpis od niekoho
Signature Requested From - podpis bol od niekoho ziadany (minuly cas)
Signature Requested To - podla mna neznamena nic - ani tvoj link takyto tvar nepozna.
Request To Sign - o tomto sa pise v clanku co linkujes.
(Data) To Be Signed - toto je z autogramu z europskej kniznice DSS.
@@ -0,0 +1,26 @@ | |||
class AddUserIdToTags < ActiveRecord::Migration[7.0] | |||
def up | |||
add_column :tags, :user_id, :integer |
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.
Len taky napad, preco tu vlastne nevyuzijeme to, ze mame user groupy a naviazeme ich cez existujucu logiku?
app/models/signer_group.rb
Outdated
tag.save! | ||
end | ||
|
||
def self.user_removed_from_group(signer_group, user) |
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.
Toto je myslim, nestastne nazvane lebo v skutocnosti tu chces povedat, ze destroy_all_signature_requests_for(group_membership)
app/models/signer_group.rb
Outdated
@@ -14,4 +14,20 @@ class SignerGroup < Group | |||
def name | |||
I18n.t("group.names.signer") | |||
end | |||
|
|||
def self.user_added_to_group(signer_group, user) |
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.
Tu to je nestastne nazvane lebo chces skor povedat, ze create_signing_tags_for(group_membership)
a ten si to vyberie ako treba. Ja by som zvazil toto dat normalne do tej GroupMembership triedy. Je to Core a tu mi to uplne nesedi kedze to je naviazane vsade na group membership.
ssd_signature_requested: | ||
name: Na podpis | ||
type: SignatureRequestedTag | ||
visible: true | ||
tenant: ssd | ||
|
||
ssd_signed: | ||
name: Podpisane | ||
type: SignedTag | ||
visible: true | ||
tenant: ssd | ||
|
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.
Ak chceme testovat ze to vyrobi, tak to nedavajme do fixtures lebo sa popalime ako minule pri delivery tagu.
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.
toto su ale vseobecne podpisove stitky. nie su viazane na konkretneho usera. toto je to iste ako DraftTag
, cize za mna by to tu malo byt. lebo sa to vytvara, ked sa tvori tenant, a ten uz mame.
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.
Tak potom ale pridajme test co naozaj vytvori tenanta
app/models/group_membership.rb
Outdated
|
||
after_create do |group_membership| | ||
if group_membership.group.is_a?(SignerGroup) | ||
self.class.create_signing_tags_for(group_membership) |
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.
co keby sme toto hodili rovno do group_membership.create_signing_tags!
?
app/models/group_membership.rb
Outdated
|
||
after_destroy do |group_membership| | ||
if group_membership.group.is_a?(SignerGroup) | ||
self.class.destroy_all_signature_requests_for(group_membership) |
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.
aj toto mi sedi asi viac do group_membership priamo.
app/models/group_membership.rb
Outdated
find_or_create_signing_tag( | ||
tags_scope: tenant.signature_requested_from_tags, | ||
user_group: user_group, | ||
tag_name: "Na podpis - #{user.name}" |
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.
Vo figme myslim neboli pomlcky
app/models/group_membership.rb
Outdated
tag.destroy if tag | ||
end | ||
|
||
def self.find_or_create_signing_tag(tags_scope:, user_group:, tag_name:) |
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.
Toto je podla mna len strukturalna podobnost a nie skutocna abstrakcia biznisova. tag_scope nie je nic biznisove a matie ma to a zaroven tam mas skaredy || co tomu len pridava magiu.
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.
ja potrebujem poriesit dve veci.
- aby som nasiel tag, ktory ma userovu skupinu (lebo napriklad, ked niekto bol podpisovac, ale potom ho dali prec, tak chceme aby tam tie jeho podpisane tagy ostali zachovane. zaroven, ked ho znova niekto prida do skupiny, tak nechcem vytvarat duplicitnu skupinu, preto hladam podla user groupy)
- nazvy skupin musia byt unikatne, meno usera sa mohlo menit.
toto riesi oba pripady.
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.
v testoch je to inak vidno, ktore pripady to riesi.
app/models/group_membership.rb
Outdated
end | ||
end | ||
|
||
def self.create_signing_tags_for(group_membership) |
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.
Keby si tu nazval group_membership ako signer_group_membership
tak by sa kopec veci vyjasnilo. Inac je to tu sama skupina a user, nevyzna sa v tom ani diva svina.
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.
kedze to us je instancna metoda, tento problem odpada.
tenant = group_membership.group.tenant | ||
|
||
find_or_create_signing_tag( | ||
tags_scope: tenant.signature_requested_from_tags, |
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.
tejto magii uplne nerozumiem, co je zle na napr
tenant.signature_requested_from_tags.find_or_create_by!(...)
?
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.
vysvetlene vyssie v komente, potrebujem najst podla groupy, lebo stitok so skupinou moze existovat (pridanie / odobratie / pridanie toho isteho usera), a potom unique name podla nazvu (to teoreticky mozeme vypustit, len mne to vyskakovalo pri implementacii, ked som sa s tym hral a nieco sa nepodarilo uplne vytvorit).
app/models/signer_group.rb
Outdated
@@ -14,4 +14,8 @@ class SignerGroup < Group | |||
def name | |||
I18n.t("group.names.signer") | |||
end | |||
|
|||
def self.user_removed_from_group(signer_group, user) |
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.
Toto ti tu ostalo navyse? Nevidim to nikde naviazane na nic.
@@ -48,4 +48,8 @@ def gives_access? | |||
def destroyable? | |||
raise NotImplementedError | |||
end | |||
|
|||
def self.find_tag_containing_group(group) | |||
includes(:groups).to_a.find { |tag| tag.groups.include?(group) } |
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.
Toto je nejaka prasarna nie? Sice to budu self joiny a aliasy ale toto sa da normalne cez sql spravit. Minimalne cez nejaky where scope nad tag
to musi ist. Staci ti tam vlozit subquery
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.
ano, da sa to spravit vsetko cez sql. akurat mi to pride nateraz zbytocne. teraz to ma byt funkcne, a potom ked bude podpisovanie, tak pome optimalizovat query. navyse sa to bude volat velmi malo krat.
app/models/group_membership.rb
Outdated
after_create :create_signing_tags!, if: Proc.new { |membership| membership.group.is_a?(SignerGroup) } | ||
after_destroy :destroy_all_signature_requests!, if: Proc.new { |membership| membership.group.is_a?(SignerGroup) } |
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.
Myslim, ze drzime konvenciu
after_create :create_signing_tags!, if: Proc.new { |membership| membership.group.is_a?(SignerGroup) } | |
after_destroy :destroy_all_signature_requests!, if: Proc.new { |membership| membership.group.is_a?(SignerGroup) } | |
after_create :create_signing_tags!, if: ->(membership) { membership.group.is_a?(SignerGroup) } | |
after_destroy :destroy_all_signature_requests!, if: ->(membership) { membership.group.is_a?(SignerGroup) } |
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.
class GenerateSignersTags < ActiveRecord::Migration[7.0] | ||
def up | ||
SignerGroup.includes(group_memberships: [:group, :user]).find_each do |group| | ||
group.group_memberships.map(&:create_signing_tags!) |
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.
group.group_memberships.map(&:create_signing_tags!) | |
group.group_memberships.each(&:create_signing_tags!) |
require "test_helper" | ||
|
||
class TenantTest < ActiveSupport::TestCase | ||
test "all system tags and groups are created with tenant" do |
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.
❤️