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

GO-370 Signing tags #227

Merged
merged 14 commits into from
Dec 7, 2023
Merged

GO-370 Signing tags #227

merged 14 commits into from
Dec 7, 2023

Conversation

mirrec
Copy link
Contributor

@mirrec 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.

@mirrec mirrec requested a review from jsuchal December 4, 2023 15:41
Copy link
Member

@jsuchal jsuchal left a 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


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
Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Member

Choose a reason for hiding this comment

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

oboje

Copy link
Contributor Author

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

Copy link
Member

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
Copy link
Member

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?

tag.save!
end

def self.user_removed_from_group(signer_group, user)
Copy link
Member

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)

@@ -14,4 +14,20 @@ class SignerGroup < Group
def name
I18n.t("group.names.signer")
end

def self.user_added_to_group(signer_group, user)
Copy link
Member

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.

Comment on lines +71 to +82
ssd_signature_requested:
name: Na podpis
type: SignatureRequestedTag
visible: true
tenant: ssd

ssd_signed:
name: Podpisane
type: SignedTag
visible: true
tenant: ssd

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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

@mirrec mirrec requested a review from jsuchal December 6, 2023 15:26

after_create do |group_membership|
if group_membership.group.is_a?(SignerGroup)
self.class.create_signing_tags_for(group_membership)
Copy link
Member

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! ?


after_destroy do |group_membership|
if group_membership.group.is_a?(SignerGroup)
self.class.destroy_all_signature_requests_for(group_membership)
Copy link
Member

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.

find_or_create_signing_tag(
tags_scope: tenant.signature_requested_from_tags,
user_group: user_group,
tag_name: "Na podpis - #{user.name}"
Copy link
Member

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/signature_requested_from_tag.rb Show resolved Hide resolved
tag.destroy if tag
end

def self.find_or_create_signing_tag(tags_scope:, user_group:, tag_name:)
Copy link
Member

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.

Copy link
Contributor Author

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.

  1. 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)
  2. nazvy skupin musia byt unikatne, meno usera sa mohlo menit.

toto riesi oba pripady.

Copy link
Contributor Author

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.

end
end

def self.create_signing_tags_for(group_membership)
Copy link
Member

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.

Copy link
Contributor Author

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,
Copy link
Member

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!(...) ?

Copy link
Contributor Author

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).

@@ -14,4 +14,8 @@ class SignerGroup < Group
def name
I18n.t("group.names.signer")
end

def self.user_removed_from_group(signer_group, user)
Copy link
Member

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) }
Copy link
Member

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

Copy link
Contributor Author

@mirrec mirrec Dec 6, 2023

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.

@mirrec mirrec requested a review from jsuchal December 6, 2023 22:50
Comment on lines 17 to 18
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) }
Copy link
Member

Choose a reason for hiding this comment

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

Myslim, ze drzime konvenciu

Suggested change
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) }

Copy link
Contributor Author

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!)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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
Copy link
Member

Choose a reason for hiding this comment

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

❤️

@mirrec mirrec requested a review from jsuchal December 7, 2023 07:46
@mirrec mirrec merged commit 6040637 into main Dec 7, 2023
3 checks passed
@mirrec mirrec deleted the GO-370/signing-tags branch December 7, 2023 07:53
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.

2 participants