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-247 Allow filtering out threads with visible tags with query -label:* #90

Merged
merged 5 commits into from
Oct 12, 2023

Conversation

mirrec
Copy link
Contributor

@mirrec mirrec commented Oct 10, 2023

No description provided.

@mirrec mirrec requested a review from jsuchal October 10, 2023 09:37

with_text = query.to_s

query.to_s.scan(/(-?label):\(([^)]+)\)/).each do |match|
raise "unexpected label case" if match.length != 2
query.to_s.scan(/(-?label):\(([^)]+)\)|(-label:\*)/).each do |match|
Copy link
Member

Choose a reason for hiding this comment

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

Ked si tu das takyto regular tak budes mat podporu aj pre bez zatvoriek aj * a vsetko najdes ako potrebujes a nemusis tu kuzlit. https://regex101.com/

((-?)label):(\(([^)]+)\)|([^ ]+)|\*)

image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jsuchal ok. upravim to teda takto. len tam tam vznika taka mensia haluz. kym -label:* ma specialny vyznam, tak label:* nema ziadny vyznam. za mna je to ok, ja len aby sa vedelo.

Copy link
Member

Choose a reason for hiding this comment

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

label:* asi znamena, ze to ma nejaky tag ale to by som asi neriesil.

@mirrec mirrec requested a review from jsuchal October 10, 2023 12:13
Comment on lines 61 to 60
Tag.where(tenant_id: tenant_id, name: label_names).pluck(:id)
end

def self.visible_tag_ids(tenant_id)
Tag.where(tenant_id: tenant_id, visible: true).pluck(:id)
if label_names.find { |name| name == "*" }.present?
[true, Tag.where(tenant_id: tenant_id, visible: true).pluck(:id)]
else
ids = Tag.where(tenant_id: tenant_id, name: label_names).pluck(:id)
[ids.length == label_names.length, ids]
end
Copy link
Member

Choose a reason for hiding this comment

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

nemalo by toto byt nad Tag ako nejake tenant.tags.find_by_names(names).pluck(:id) a do metody posielame tenant a nie tenant_id?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

moze byt aj tak. tak, ako to je tu, to ale mame prakticky vsade v XxxPolicy.

Admin::UserPolicy < Struct.new(:user) # to som spravil umelo prezjednodusenie
  class Scope < Scope
    def resolve
      if @user.site_admin?
        scope.all
      else
        scope.where(tenant_id: @user.tenant_id)
      end
    end
  end

v com vidis rozdiel to pisat tak, ako navrhujes?

Copy link
Member

Choose a reason for hiding this comment

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

Za mna je best-practice

  1. specialne v pripadoch kedy sa obmedzuje viditelnost pouzivat parent asociaciu ako zaciatok
  2. primitive obsession - s idckami by sa malo babrat primarne na top level urovni, alebo v jasne definovanych interfacoch. Inak bude vsade _id a .id namiesto objektu samotneho.
  3. je to domenovy jazyk, to vyssie je taky implementacny jazyk.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jsuchal nahradit to v tom Query za tenant je v pohode. len teda tu
https://github.com/solver-it-sro/govbox-pro/blob/main/app/models/searchable/message_thread.rb#L32

potrebujem tenant_id. a neviem ist cez tenant takto pekne, predoze tam mi prichadza uz nejaky scope. cize tam je jedina moznost mat tam fetch(:tenant).id (ak si tam teda nechcem posiet aj tenant a aj tenant_id).

Copy link
Member

Choose a reason for hiding this comment

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

Smerom na search je podla mna ok kontrakt cez idcka lebo to su ine domeny.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

tak nakoniec som tam nechal tenant, lebo som si uvedomil, ze where(tenant_id: tenant) pekne nacita id z daneho objektu.

@mirrec mirrec requested a review from jsuchal October 12, 2023 08:15
result = { tenant_id: Current.tenant }
result[:box_id] = Current.box if Current.box
result = { tenant: Current.tenant }
result[:box] = Current.box if Current.box
result[:tag_ids] = policy_scope(Tag).pluck(:id) unless Current.user.admin?
Copy link
Member

@jsuchal jsuchal Oct 12, 2023

Choose a reason for hiding this comment

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

Myslim, ze tu podmienku mozeme vyhodit, momentalne adminom uz davame pristupy na vsetky tagy default, ze @luciajanikova ?

Copy link
Member

Choose a reason for hiding this comment

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

Comment on lines +35 to +36
found_all, filter_tag_ids = label_names_to_tag_ids(tenant, filter_labels)
_, filter_out_tag_ids = label_names_to_tag_ids(tenant, filter_out_labels)
Copy link
Member

Choose a reason for hiding this comment

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

Tu daj TODO, ze toto by sa dalo aj jednou query vybavit.

@mirrec mirrec merged commit 10dc26b into main Oct 12, 2023
@mirrec mirrec deleted the query-for-no-visible-tags branch October 12, 2023 09:26
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.

3 participants