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

Allow association policy over base policy #2653

Open
Paul-Bob opened this issue Apr 2, 2024 · 5 comments
Open

Allow association policy over base policy #2653

Paul-Bob opened this issue Apr 2, 2024 · 5 comments
Assignees
Labels
Bug Something isn't working

Comments

@Paul-Bob
Copy link
Contributor

Paul-Bob commented Apr 2, 2024

Context

We should be able to block creation on User policy but allow users creation from the team policy.

From here https://discord.com/channels/740892036978442260/1224645956155342859

As a workaround on advanced licenses the create button can be hidden using the custom controls https://docs.avohq.io/3.0/customizable-controls.html#index_page

@Bergrebell
Copy link
Contributor

@Paul-Bob - i just noticed that the workaround is not really solving my issue. to give some context why this is so important i will try to outline an example:

i have a Competition-table with a column that specifys the disciplines that are available in this competition like this: t.text "disciplines", default: [], array: true.

now if you want to participate in a Competition you are only allowed to participate in some of the disciplines that were selected in the corresponsing Competition.

so what i do is on my CompetitionParticipation-resource is:

field :disciplines,
            as: :tags,
            delimiters: [","],
            suggestions: -> { record.competition.disciplines },
            enforce_suggestions: true,
            filterable: true

but now there comes the issue - when i try to create a new CompetitionParticipation outside of a Competition-resource, the competition is nil and the app throws an error.

so what i want to do is to hide the create-button on the index-view of the CompetitionParticipation but show it on the Competition-resource (since there i have access to the corresponding disciplines`.

when using the workaround:

self.index_controls = -> do
    actions_list exclude: [:create_button]
  end

it hides the create-button in both resources (and i cannot create a CompetitionParticipation-resource at all.

@Bergrebell
Copy link
Contributor

Bergrebell commented Apr 9, 2024

also for some reason, for:

# avo/resources/competition_participation.rb

self.index_controls = -> do
    if record.competition.present?
      create_button label: "I know the Competition"

    else
      actions_list exclude: [:create_button]
    end
  end

it seems as if it takes the first record from the list and the Competition is present.

then when clicking create, it throws an exception since inside the field record.competition is nil again.

@Paul-Bob
Copy link
Contributor Author

Paul-Bob commented Apr 9, 2024

@Bergrebell actions_list is for the action list button control
image

self.index_controls = -> do
  actions_list exclude: [:create_button]
end

Above code will render the action list excluding some action called created_button (that i believe doesn't exist and this is just a misunderstood)

This is what you need in order to satisfy the requirements:

  self.index_controls = -> do
    actions_list
    attach_button label: "Attach ..."
    # might exists better ways to check if we're on a association index, this is just an example for a workaround
    create_button label: "Create..." if params[:controller] == "avo/associations"
  end

@Paul-Bob Paul-Bob self-assigned this Apr 9, 2024
@Paul-Bob Paul-Bob added the Bug Something isn't working label Apr 9, 2024
@Bergrebell
Copy link
Contributor

Bergrebell commented Apr 9, 2024

okay, that works for now! thanks for the hint with checking the params! 👍

but its still strange that if record.competition.present? is true - right?

@Paul-Bob
Copy link
Contributor Author

Paul-Bob commented Apr 9, 2024

Yes resource is hydrated with the last item of the table to avoid some breaking changes, we're working in it on this PR https://github.com/avo-hq/avo/pull/2549/files#diff-d8698d47659420f473312cd3cca742b38aec454280864548bdcbd9b2a49379cd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
Status: Next up
Development

No branches or pull requests

2 participants