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

Labels #146

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 21 additions & 23 deletions assets/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion assets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"flatpickr": "^4.6.13",
"phoenix": "^1.7.1",
"phoenix_html": "^3.3.1",
"phoenix_live_view": "^0.18.17",
"phoenix_live_view": "^0.19.0",
"prop-types": "^15.8.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand Down
12 changes: 6 additions & 6 deletions assets/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -984,18 +984,18 @@ path-type@^4.0.0:

phoenix@^1.7.1:
version "1.7.1"
resolved "https://registry.yarnpkg.com/phoenix/-/phoenix-1.7.1.tgz#99a2f697eb8e0a95c64e5756829621c52966069c"
resolved "https://registry.npmjs.org/phoenix/-/phoenix-1.7.1.tgz"
integrity sha512-DORpAOHp8XdQDs6WT2yD65fhUQXhzrD+CTZCKqWQ9g0G/fyM8EKsSDhtOwl54Nr2DDBu8JARMR97OfLYCiKAoQ==

phoenix_html@^3.3.1:
version "3.3.1"
resolved "https://registry.yarnpkg.com/phoenix_html/-/phoenix_html-3.3.1.tgz#87461c879a075cad6a7340e434e40f69a815f11b"
resolved "https://registry.npmjs.org/phoenix_html/-/phoenix_html-3.3.1.tgz"
integrity sha512-t/9Saqpe8vznZYHMDim7HS32Dd2/rKf3+uxuKKNRADLpGXVIDjselOY6pK8aNaLiY2gnlqsoz6yIpUBuoLT63w==

phoenix_live_view@^0.18.17:
version "0.18.17"
resolved "https://registry.yarnpkg.com/phoenix_live_view/-/phoenix_live_view-0.18.17.tgz#978bf017e8b250f9e70e276e09ea271fedf6662d"
integrity sha512-ORVy7K1Fihn8sxhwpJRfPZTINsq0DQhtWbiCz6t8h5D/uwURDUUWV1KBFeB+2HhyjqdnWF9DqqAYlt7luNSp1g==
phoenix_live_view@^0.19.0:
version "0.19.0"
resolved "https://registry.npmjs.org/phoenix_live_view/-/phoenix_live_view-0.19.0.tgz"
integrity sha512-A5csAJh8wHqhconanS2BI/5vhCSRKvdrEqLc+FF8BaKGm1xu00f3rC/mENT7Aen+jeKP9jjy028fDMMYWk4F+w==

pify@^2.3.0:
version "2.3.0"
Expand Down
2 changes: 2 additions & 0 deletions config/cy.exs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ config :active_storage, :secret_key_base, "xxxxxxxxxxx"
config :active_job, repo: Rauversion.Repo
config :active_storage, repo: Rauversion.Repo

config :rauversion, :domain, "http://localhost:4002"

config :mogrify,
mogrify_command: [
path: "mogrify",
Expand Down
3 changes: 3 additions & 0 deletions config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ config :rauversion, google_analytics_id: System.get_env("GA_ID")

config :rauversion, disabled_registrations: System.get_env("DISABLED_REGISTRATIONS", "false")

config :rauversion,
disabled_label_registrations: System.get_env("LABEL_REGISTRATION_CLOSED", "false")

config :ueberauth, Ueberauth.Strategy.Zoom.OAuth,
client_id: System.get_env("ZOOM_CLIENT_ID"),
client_secret: System.get_env("ZOOM_CLIENT_SECRET")
Expand Down
54 changes: 48 additions & 6 deletions lib/rauversion/accounts.ex
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ defmodule Rauversion.Accounts do
|> where([u], not is_nil(u.username))
end

def search_by_username(query, term) do
query |> where([u], like(u.username, ^"#{term}%"))
end

def artists() do
from(u in User,
where: [type: ^"artist"],
Expand Down Expand Up @@ -146,6 +150,11 @@ defmodule Rauversion.Accounts do
"""
def get_user!(id), do: Repo.get!(User, id)

def not_in(query, id) do
query
|> where([u], u.id != ^id)
end

## User registration

@doc """
Expand Down Expand Up @@ -207,6 +216,15 @@ defmodule Rauversion.Accounts do
|> Repo.update()
end

def is_label?(user) do
user.label
end

def update_label(user, attrs \\ %{}) do
User.label_changeset(user, attrs)
|> Repo.update()
end

def update_notifications(user, attrs \\ %{}) do
User.notifications_changeset(user, attrs)
|> Repo.update()
Expand Down Expand Up @@ -593,11 +611,12 @@ defmodule Rauversion.Accounts do
end

def user_host_events(user) do
from p in Rauversion.Events.Event,
from(p in Rauversion.Events.Event,
join: c in assoc(p, :event_hosts),
where: c.user_id == ^user.id,
preload: [:user],
select: p
)
end

def find_managed_event(user, event_id) do
Expand Down Expand Up @@ -718,8 +737,9 @@ defmodule Rauversion.Accounts do
q = track_orders_query(current_user)

query =
from [p, c] in q,
from([p, c] in q,
where: c.state == "paid" or c.state == "free_access"
)

query
|> Repo.all()
Expand All @@ -740,8 +760,9 @@ defmodule Rauversion.Accounts do
q = album_orders_query(current_user)

query =
from [p, c] in q,
from([p, c] in q,
where: c.state == "paid" or c.state == "free_access"
)

query
|> Repo.all()
Expand All @@ -751,8 +772,9 @@ defmodule Rauversion.Accounts do
q = album_orders_query(current_user)

query =
from [p, c] in q,
from([p, c] in q,
where: c.state == "pending"
)

query
|> Repo.all()
Expand Down Expand Up @@ -780,8 +802,9 @@ defmodule Rauversion.Accounts do
|> order_by([c], desc: c.id)

query =
from [p, c] in q,
from([p, c] in q,
where: c.state == "paid"
)

query
end
Expand All @@ -799,9 +822,28 @@ defmodule Rauversion.Accounts do
|> order_by([c], desc: c.id)

query =
from [p, c] in q,
from([p, c] in q,
where: c.state == "paid"
)

query
end

### connected accounts

def active_connected_accounts(user) do
from(p in Rauversion.ConnectedAccounts.ConnectedAccount)
|> where(parent_id: ^user.id)
|> where(state: "active")
|> Rauversion.Repo.all()
|> Repo.preload(:user)
end

def is_child_of?(user, child_user_id) do
from(p in Rauversion.ConnectedAccounts.ConnectedAccount)
|> where(parent_id: ^user.id)
|> where(state: "active")
|> where([c], ^child_user_id == c.user_id)
|> Rauversion.Repo.one()
end
end
12 changes: 12 additions & 0 deletions lib/rauversion/accounts/user.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ defmodule Rauversion.Accounts.User do
field :city, :string
field :bio, :string
field :invitations_count, :integer, default: 10
field :label, :boolean

belongs_to :invited_by_user, Rauversion.Accounts.User, foreign_key: :invited_by

Expand Down Expand Up @@ -62,6 +63,13 @@ defmodule Rauversion.Accounts.User do
has_many :purchased_tickets, Rauversion.PurchasedTickets.PurchasedTicket,
on_delete: :delete_all

has_many :connected_accounts,
Rauversion.ConnectedAccounts.ConnectedAccount,
on_delete: :delete_all,
foreign_key: :parent_id

has_many :child_accounts, through: [:connected_accounts, :user]

has_one(:avatar_attachment, ActiveStorage.Attachment,
where: [record_type: "User", name: "avatar"],
foreign_key: :record_id
Expand Down Expand Up @@ -178,6 +186,10 @@ defmodule Rauversion.Accounts.User do
|> unique_constraint(:username)
end

def label_changeset(user, attrs, _opts \\ []) do
user |> cast(attrs, [:label])
end

defp validate_contact_fields(changeset, attrs) do
changeset
|> cast(attrs, [:username, :first_name, :last_name, :country, :bio, :city])
Expand Down
30 changes: 15 additions & 15 deletions lib/rauversion/album_purchase_orders/album_purchase_order.ex
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,20 @@ defmodule Rauversion.AlbumPurchaseOrders.AlbumPurchaseOrder do
Rauversion.Playlists.get_playlist!(order.playlist_id)
|> Rauversion.Repo.preload([:user, :cover_blob, [track_playlists: [track: [:audio_blob]]]])

# {:ok, fd, file_path} = Temp.open("my-file")
#
# text = """
# <h1>#{playlist.title}</h1>
# <p>#{playlist.description}</p>
# <p>Visit: <a href="#{Application.get_env(:rauversion, :domain) <> "/playlists/#{playlist.slug}"}">#{playlist.title}</a> on #{Application.get_env(:rauversion, :domain)}</p>
# """
#
# IO.write(fd, text)
# charlist = String.to_charlist(text)
# IO.write(fd, charlist)
## File.close(fd) ## close file?
#
# file_entry = [source: {:file, file_path}, path: "/#{playlist.slug}/#{playlist.slug}.html"]
{:ok, fd, file_path} = Temp.open("my-file")

text = """
<h1>#{playlist.title}</h1>

<p>#{playlist.description}</p>

<p>Visit: <a href="#{Application.get_env(:rauversion, :domain) <> "/playlists/#{playlist.slug}"}">#{playlist.title}</a> on #{Application.get_env(:rauversion, :domain)}</p>
"""

IO.write(fd, text)
# File.close(fd) ## close file?

file_entry = [source: {:file, file_path}, path: "/#{playlist.slug}/#{playlist.slug}.html"]

entries =
Enum.map(playlist.track_playlists, fn item ->
Expand All @@ -65,7 +65,7 @@ defmodule Rauversion.AlbumPurchaseOrders.AlbumPurchaseOrder do
]
end)

# entries = entries ++ [file_entry]
entries = entries ++ [file_entry]

cover = Rauversion.BlobUtils.blob_proxy_url(playlist, :cover)

Expand Down
39 changes: 39 additions & 0 deletions lib/rauversion/auto_context.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
defmodule Rauversion.AutoContext do
defmacro __using__(opts) do
quote bind_quoted: [opts: opts] do
import Ecto.Query, warn: false
alias Rauversion.Repo

def list do
Repo.all(unquote(opts))
end

def get!(id), do: Repo.get!(unquote(opts), id)

def create(attrs \\ %{}) do
%unquote(opts){}
|> unquote(opts).changeset(attrs)
|> Repo.insert()
end

def update(%unquote(opts){} = connected_account, attrs) do
connected_account
|> unquote(opts).changeset(attrs)
|> Repo.update()
end

def delete(%unquote(opts){} = connected_account) do
Repo.delete(connected_account)
end

def change(
%unquote(opts){} = connected_account,
attrs \\ %{}
) do
unquote(opts).changeset(connected_account, attrs)
end

defoverridable list: 0, get!: 1, create: 1, update: 2, delete: 1, change: 1
end
end
end
Loading