You've already forked tribes-plugin-sender
forked from tribes/tribes-plugin-template
1fb848b8cb
Adopt canonical plugin id/slug manifest fields, vendor-prefixed OTP app naming, and fully-qualified capability ids for Sender.
109 lines
2.1 KiB
Elixir
109 lines
2.1 KiB
Elixir
defmodule TribeOne.TribesPlugin.Sender.Streaming.StreamKey do
|
|
@moduledoc false
|
|
|
|
use Ash.Resource,
|
|
otp_app: :tribe_one_sender,
|
|
domain: TribeOne.TribesPlugin.Sender.Streaming,
|
|
data_layer: AshPostgres.DataLayer,
|
|
authorizers: [Ash.Policy.Authorizer],
|
|
extensions: [AshNostrSync]
|
|
|
|
@statuses [:active, :revoked]
|
|
|
|
postgres do
|
|
table("sender_stream_keys")
|
|
repo(Tribes.Repo)
|
|
|
|
custom_indexes do
|
|
index([:stream_id])
|
|
index([:status])
|
|
end
|
|
end
|
|
|
|
nostr_sync do
|
|
namespace("plugins.sender.stream_key")
|
|
lane(:control)
|
|
publish?(true)
|
|
consume?(true)
|
|
end
|
|
|
|
actions do
|
|
defaults([:read])
|
|
|
|
create :create do
|
|
accept([:stream_id, :label, :key_hash, :status, :last_used_at])
|
|
change(AshNostrSync.PublishChange)
|
|
end
|
|
|
|
create :sync_upsert do
|
|
accept([:id, :stream_id, :label, :key_hash, :status, :last_used_at])
|
|
upsert?(true)
|
|
end
|
|
|
|
update :update do
|
|
require_atomic?(false)
|
|
accept([:label, :status, :last_used_at])
|
|
change(AshNostrSync.PublishChange)
|
|
end
|
|
|
|
destroy :destroy do
|
|
require_atomic?(false)
|
|
soft?(true)
|
|
soft_delete()
|
|
change(AshNostrSync.PublishChange)
|
|
end
|
|
end
|
|
|
|
policies do
|
|
bypass Tribes.Checks.SyncInteraction do
|
|
authorize_if(always())
|
|
end
|
|
|
|
bypass Tribes.Checks.SystemInteraction do
|
|
authorize_if(always())
|
|
end
|
|
|
|
policy action_type(:read) do
|
|
authorize_if(always())
|
|
end
|
|
end
|
|
|
|
attributes do
|
|
attribute :id, :uuid do
|
|
allow_nil?(false)
|
|
primary_key?(true)
|
|
public?(true)
|
|
writable?(true)
|
|
default(&Ash.UUID.generate/0)
|
|
end
|
|
|
|
attribute :stream_id, :uuid do
|
|
allow_nil?(false)
|
|
public?(true)
|
|
end
|
|
|
|
attribute :label, :string do
|
|
allow_nil?(false)
|
|
public?(true)
|
|
end
|
|
|
|
attribute :key_hash, :string do
|
|
allow_nil?(false)
|
|
public?(true)
|
|
end
|
|
|
|
attribute :status, :atom do
|
|
constraints(one_of: @statuses)
|
|
allow_nil?(false)
|
|
default(:active)
|
|
public?(true)
|
|
end
|
|
|
|
attribute :last_used_at, :utc_datetime do
|
|
public?(true)
|
|
end
|
|
|
|
timestamps(type: :utc_datetime)
|
|
end
|
|
end
|