Skip to content

Commit

Permalink
array union reproduced bug
Browse files Browse the repository at this point in the history
  • Loading branch information
revati committed May 18, 2024
1 parent 284c97b commit e1678a8
Show file tree
Hide file tree
Showing 10 changed files with 1,243 additions and 82 deletions.
195 changes: 113 additions & 82 deletions dev/resources/tickets/resources/ticket/ticket.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,188 +13,219 @@ defmodule Demo.Tickets.Ticket do

admin do
show_action :read
table_columns [:id, :representative, :reporter, :reporter_id, :subject, :status, :description, :reporter_name]
format_fields [
description: {AdminFieldFormats, :format_field, [:description]}

table_columns [
:id,
:representative,
:reporter,
:reporter_id,
:subject,
:status,
:description,
:reporter_name
]

format_fields description: {AdminFieldFormats, :format_field, [:description]}

form do
field :description, type: :markdown
end
end

policies do
bypass always() do
authorize_if actor_attribute_equals(:admin, true)
authorize_if(actor_attribute_equals(:admin, true))
end

policy action_type(:read) do
authorize_if actor_attribute_equals(:representative, true)
authorize_if relates_to_actor_via(:reporter)
authorize_if(actor_attribute_equals(:representative, true))
authorize_if(relates_to_actor_via(:reporter))
end

policy changing_relationship(:reporter) do
authorize_if relating_to_actor(:reporter)
authorize_if(relating_to_actor(:reporter))
end
end

actions do
default_accept :*
default_accept(:*)

read :reported do
filter reporter: actor(:id)
filter(reporter: actor(:id))

pagination offset?: true, countable: true, required?: false, default_limit: 25
pagination(offset?: true, countable: true, required?: false, default_limit: 25)
end

read :assigned do
filter representative: actor(:id)
pagination offset?: true, countable: true, required?: false, default_limit: 25
filter(representative: actor(:id))
pagination(offset?: true, countable: true, required?: false, default_limit: 25)
end

read :read do
primary? true
pagination [
primary?(true)

pagination(
offset?: true,
keyset?: true,
default_limit: 10,
countable: :by_default
]
)
end

read :keyset do
pagination [
pagination(
keyset?: true,
default_limit: 10
]
)
end

create :open do
accept [:subject, :metadata]
primary? true
argument :representative, :map, allow_nil?: false
argument :organization, :map, allow_nil?: false
argument :tickets, {:array, :map}
accept([:subject, :metadata])
primary?(true)
argument(:representative, :map, allow_nil?: false)
argument(:organization, :map, allow_nil?: false)
argument(:tickets, {:array, :map})

change(
manage_relationship(:organization,
on_no_match: :create,
on_lookup: :relate,
on_match: :ignore
)
)

change(manage_relationship(:representative, type: :append))

change manage_relationship(:organization, on_no_match: :create, on_lookup: :relate, on_match: :ignore)
change manage_relationship(:representative, type: :append)
change manage_relationship(:tickets, :source_links, on_lookup: {:relate_and_update, :create, :read, :all})
change(
manage_relationship(:tickets, :source_links,
on_lookup: {:relate_and_update, :create, :read, :all}
)
)
end

update :update do
primary? true
argument :organization_id, :uuid
require_atomic? false
primary?(true)
argument(:organization_id, :uuid)
require_atomic?(false)

change manage_relationship(:organization_id, :organization, type: :append_and_remove)
change(manage_relationship(:organization_id, :organization, type: :append_and_remove))
end

update :assign do
accept []
require_atomic? false
argument :representative, :map
argument :reassignment_comment, :map, allow_nil?: false
accept([])
require_atomic?(false)
argument(:representative, :map)
argument(:reassignment_comment, :map, allow_nil?: false)

change manage_relationship(:representative, type: :append)
change manage_relationship(:reassignment_comment, :comments, type: :create)
change(manage_relationship(:representative, type: :append))
change(manage_relationship(:reassignment_comment, :comments, type: :create))
end

update :link do
accept []
require_atomic? false
argument :tickets, {:array, :map}, allow_nil?: false
argument :link_comment, :map
accept([])
require_atomic?(false)
argument(:tickets, {:array, :map}, allow_nil?: false)
argument(:link_comment, :map)

# Uses the defult create action of the join table, which accepts the `type`
change manage_relationship(:tickets, :source_links, on_lookup: {:relate_and_update, :create, :read, :all})
change manage_relationship(:link_comment, :comments, type: :create)
change(
manage_relationship(:tickets, :source_links,
on_lookup: {:relate_and_update, :create, :read, :all}
)
)

change(manage_relationship(:link_comment, :comments, type: :create))
end

update :nested_example do
accept [:subject]
argument :tickets, {:array, :map}
require_atomic? false

change manage_relationship(
:tickets,
:source_links,
type: :direct_control,
on_match: {:update, :nested_example, :update, [:type]},
on_no_match: {:create, :open, :create, [:type]}
accept([:subject])
argument(:tickets, {:array, :map})
require_atomic?(false)

change(
manage_relationship(
:tickets,
:source_links,
type: :direct_control,
on_match: {:update, :nested_example, :update, [:type]},
on_no_match: {:create, :open, :create, [:type]}
)
)
end

destroy :destroy do
primary? true
primary?(true)
end
end

postgres do
table "tickets"
repo Demo.Repo
table("tickets")
repo(Demo.Repo)
end

attributes do
uuid_primary_key :id
uuid_primary_key(:id)

attribute :subject, :string do
allow_nil? false
public? true
constraints min_length: 5
allow_nil?(false)
public?(true)
constraints(min_length: 5)
end

attribute :metadata, Demo.Tickets.Ticket.Types.Metadata do
public? true
attribute :metadata, {:array, Demo.Tickets.Ticket.Types.Metadata} do
public?(true)
end

attribute :description, :string do
public? true
public?(true)
end

attribute :response, :string do
public? true
public?(true)
end

attribute :status, :atom do
public? true
allow_nil? false
default "new"
constraints one_of: [:new, :investigating, :closed]
public?(true)
allow_nil?(false)
default("new")
constraints(one_of: [:new, :investigating, :closed])
end

timestamps()
end

aggregates do
first :reporter_name, [:reporter], :first_name
first(:reporter_name, [:reporter], :first_name)
end

relationships do
belongs_to :reporter, Demo.Tickets.Customer, public?: true
belongs_to(:reporter, Demo.Tickets.Customer, public?: true)

belongs_to(:representative, Demo.Tickets.Representative, public?: true)

belongs_to :representative, Demo.Tickets.Representative, public?: true
belongs_to :organization, Demo.Tickets.Organization do
public? true
allow_nil? false
public?(true)
allow_nil?(false)
end

has_many :comments, Demo.Tickets.Comment do
public? true
relationship_context %{data_layer: %{table: "ticket_comments"}}
destination_attribute :resource_id
public?(true)
relationship_context(%{data_layer: %{table: "ticket_comments"}})
destination_attribute(:resource_id)
end

many_to_many :source_links, Demo.Tickets.Ticket do
public? true
through Demo.Tickets.TicketLink
source_attribute_on_join_resource :source_id
destination_attribute_on_join_resource :destination_id
public?(true)
through(Demo.Tickets.TicketLink)
source_attribute_on_join_resource(:source_id)
destination_attribute_on_join_resource(:destination_id)
end

many_to_many :destination_links, Demo.Tickets.Ticket do
public? true
through Demo.Tickets.TicketLink
source_attribute_on_join_resource :destination_id
destination_attribute_on_join_resource :source_id
public?(true)
through(Demo.Tickets.TicketLink)
source_attribute_on_join_resource(:destination_id)
destination_attribute_on_join_resource(:source_id)
end
end
end
Loading

0 comments on commit e1678a8

Please sign in to comment.