Skip to content

Commit edbfb9a

Browse files
committed
Merge branch 'develop'
2 parents 3e755d8 + 0ca4a76 commit edbfb9a

File tree

91 files changed

+885
-455
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+885
-455
lines changed

Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ RUN cd assets && \
3939
COPY config/config.exs config/
4040
COPY config/prod.exs config/
4141

42+
# ensure mime is recompiled later with our additional mime types
43+
RUN mix deps.clean mime --build
44+
4245
RUN mix phx.digest
4346

4447
COPY config/*.exs config/

assets/css/_base.scss

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,14 @@ body, main {
8787
}
8888
}
8989

90+
.c-page {
91+
main {
92+
h1 {
93+
margin-top: 4rem;
94+
}
95+
}
96+
}
97+
9098
.c-page .container > h1 {
9199
margin-bottom: 2rem;
92100
}
@@ -177,22 +185,6 @@ form {
177185
}
178186
}
179187

180-
.c-doc {
181-
main {
182-
h1 {
183-
margin-top: 0;
184-
margin-bottom: 1em;
185-
}
186-
}
187-
188-
.content {
189-
h2 {
190-
margin-top: 2em;
191-
margin-bottom: 1em;
192-
}
193-
}
194-
}
195-
196188
body pre {
197189
background-color: #fff;
198190
border-color: #ddd;

assets/css/_recording_card.scss

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,12 @@ div.asciicast-card {
8888

8989
h3 {
9090
margin: 0 0 6px 0;
91-
font-size: 20px;
91+
font-size: 18px;
92+
display: flex;
9293

9394
.duration {
94-
float: right;
95+
margin: auto 0 auto auto;
96+
padding-left: 1em;
9597
font-size: 14px;
9698
}
9799
}
@@ -104,6 +106,10 @@ div.asciicast-card {
104106
abbr {
105107
border-bottom: 0;
106108
}
109+
110+
.special-label {
111+
float: right;
112+
}
107113
}
108114
}
109115
}

assets/css/_user_edit.scss

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,15 @@
1212
opacity: 0.7;
1313
}
1414
}
15+
16+
.danger-zone {
17+
margin-top: 2em;
18+
}
19+
}
20+
21+
.c-user.a-delete {
22+
h1 {
23+
margin-top: 2rem;
24+
margin-bottom: 2rem;
25+
}
1526
}

config/config.exs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,16 @@ config :asciinema, AsciinemaWeb.Endpoint,
3131
]
3232
],
3333
url: [host: "localhost"],
34-
render_errors: [view: AsciinemaWeb.ErrorView, accepts: ~w(html json), layout: false],
34+
render_errors: [
35+
formats: [
36+
html: AsciinemaWeb.ErrorHTML,
37+
json: AsciinemaWeb.ErrorJSON,
38+
txt: AsciinemaWeb.ErrorTEXT,
39+
svg: AsciinemaWeb.ErrorTEXT,
40+
xml: AsciinemaWeb.ErrorTEXT
41+
],
42+
layout: false
43+
],
3544
live_view: [signing_salt: "F3BMP7k9SZ-Y2SMJ"],
3645
pubsub_server: Asciinema.PubSub
3746

@@ -53,7 +62,17 @@ config :logger,
5362
config :phoenix, :json_library, Jason
5463

5564
config :phoenix, :template_engines, md: PhoenixMarkdown.Engine
56-
config :phoenix_template, :format_encoders, svg: Phoenix.HTML.Engine, xml: Phoenix.HTML.Engine
65+
66+
config :phoenix_template, :format_encoders,
67+
cast: Jason,
68+
svg: Phoenix.HTML.Engine,
69+
xml: Phoenix.HTML.Engine
70+
71+
config :mime, :types, %{
72+
"application/x-asciicast" => ["cast"]
73+
}
74+
75+
config :asciinema, Asciinema.Emails.Mailer, adapter: Swoosh.Adapters.Local
5776

5877
config :sentry,
5978
dsn: "https://public:secret@sentry.io/1",
@@ -68,8 +87,6 @@ config :asciinema, Asciinema.FileStore.Local, path: "uploads/"
6887

6988
config :asciinema, Asciinema.FileCache, path: "cache/"
7089

71-
config :asciinema, Asciinema.Emails.Mailer, adapter: Bamboo.LocalAdapter
72-
7390
config :asciinema, :png_generator, Asciinema.PngGenerator.Rsvg
7491

7592
config :asciinema, Asciinema.PngGenerator.Rsvg,

config/runtime.exs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,19 @@ if config_env() in [:prod, :dev] do
9595
config :asciinema, Asciinema.FileCache, path: cache_path
9696
end
9797

98+
config :ex_aws,
99+
region: [{:system, "S3_REGION"}, {:system, "AWS_REGION"}],
100+
access_key_id: [
101+
{:system, "S3_ACCESS_KEY_ID"},
102+
{:system, "AWS_ACCESS_KEY_ID"},
103+
:instance_role
104+
],
105+
secret_access_key: [
106+
{:system, "S3_SECRET_ACCESS_KEY"},
107+
{:system, "AWS_SECRET_ACCESS_KEY"},
108+
:instance_role
109+
]
110+
98111
if bucket = env.("S3_BUCKET") do
99112
config :asciinema, Asciinema.FileStore.S3,
100113
bucket: bucket,
@@ -110,19 +123,6 @@ if config_env() in [:prod, :dev] do
110123
config :asciinema, Asciinema.FileStore.Local,
111124
path: Path.join(cache_path || "/var/cache/asciinema", "uploads")
112125

113-
config :ex_aws,
114-
region: [{:system, "S3_REGION"}, {:system, "AWS_REGION"}],
115-
access_key_id: [
116-
{:system, "S3_ACCESS_KEY_ID"},
117-
{:system, "AWS_ACCESS_KEY_ID"},
118-
:instance_role
119-
],
120-
secret_access_key: [
121-
{:system, "S3_SECRET_ACCESS_KEY"},
122-
{:system, "AWS_SECRET_ACCESS_KEY"},
123-
:instance_role
124-
]
125-
126126
if endpoint = env.("S3_ENDPOINT") do
127127
uri = URI.parse(endpoint)
128128

@@ -143,8 +143,8 @@ if config_env() in [:prod, :dev] do
143143

144144
if smtp_host = env.("SMTP_HOST") do
145145
config :asciinema, Asciinema.Emails.Mailer,
146-
adapter: Bamboo.SMTPAdapter,
147-
server: smtp_host,
146+
adapter: Swoosh.Adapters.SMTP,
147+
relay: smtp_host,
148148
port: String.to_integer(env.("SMTP_PORT") || "587")
149149

150150
if username = env.("SMTP_USERNAME") do

config/test.exs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ if db_url = System.get_env("TEST_DATABASE_URL") do
1313
System.put_env("DATABASE_URL", db_url)
1414
end
1515

16+
# In test we don't send emails.
17+
config :asciinema, Asciinema.Emails.Mailer, adapter: Swoosh.Adapters.Test
18+
1619
# Print only errors during test
1720
config :logger, level: :error
1821

@@ -37,6 +40,4 @@ config :asciinema, :snapshot_updater, Asciinema.Recordings.SnapshotUpdater.Noop
3740

3841
config :asciinema, Oban, testing: :manual
3942

40-
config :asciinema, Asciinema.Emails.Mailer, adapter: Bamboo.TestAdapter
41-
4243
config :asciinema, Asciinema.Telemetry, enabled: false

lib/asciinema.ex

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,24 @@ defmodule Asciinema do
1818
end
1919
end
2020

21-
def send_login_email(identifier, sign_up_enabled?, routes) do
22-
case Accounts.generate_login_url(identifier, sign_up_enabled?, routes) do
23-
{:ok, {type, url, email}} ->
24-
Emails.send_email(type, email, url)
21+
def send_login_email(identifier, sign_up_enabled? \\ true)
22+
23+
def send_login_email(identifier, sign_up_enabled?) do
24+
case Accounts.generate_login_token(identifier, sign_up_enabled?) do
25+
{:ok, {type, token, email}} ->
26+
Emails.send_email(type, email, token)
2527

2628
{:error, _reason} = result ->
2729
result
2830
end
2931
end
3032

33+
def send_account_deletion_email(user) do
34+
token = Accounts.generate_deletion_token(user)
35+
36+
Emails.send_email(:account_deletion, user.email, token)
37+
end
38+
3139
defdelegate verify_login_token(token), to: Accounts
3240

3341
def merge_accounts(src_user, dst_user) do

lib/asciinema/accounts.ex

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ defmodule Asciinema.Accounts do
55
alias Asciinema.Accounts.{User, ApiToken}
66
alias Asciinema.{Fonts, Repo, Themes}
77
alias Ecto.Changeset
8+
alias Phoenix.Token
89

910
@valid_email_re ~r/^[A-Z0-9._%+-]+@([A-Z0-9-]+\.)+[A-Z]{2,}$/i
1011
@valid_username_re ~r/^[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9]$/
@@ -88,7 +89,7 @@ defmodule Asciinema.Accounts do
8889
:theme_name,
8990
:theme_prefer_original,
9091
:terminal_font_family,
91-
:asciicasts_private_by_default
92+
:default_asciicast_visibility
9293
])
9394
|> validate_required([:email])
9495
|> update_change(:email, &String.downcase/1)
@@ -123,24 +124,23 @@ defmodule Asciinema.Accounts do
123124
from(u in q, where: is_nil(u.email))
124125
end
125126

126-
def generate_login_url(identifier, sign_up_enabled?, routes) do
127+
def generate_login_token(identifier, sign_up_enabled? \\ true)
128+
129+
def generate_login_token(identifier, sign_up_enabled?) do
127130
case {lookup_user(identifier), sign_up_enabled?} do
128131
{{_, %User{email: nil}}, _} ->
129132
{:error, :email_missing}
130133

131134
{{_, %User{} = user}, _} ->
132-
url = user |> login_token() |> routes.login_url()
133-
134-
{:ok, {:login, url, user.email}}
135+
{:ok, {:login, login_token(user), user.email}}
135136

136137
{{:email, nil}, true} ->
137138
changeset = change_user(%User{}, %{email: identifier})
138139

139140
if changeset.valid? do
140141
email = changeset.changes.email
141-
url = email |> signup_token() |> routes.signup_url()
142142

143-
{:ok, {:signup, url, email}}
143+
{:ok, {:signup, signup_token(email), email}}
144144
else
145145
{:error, :email_invalid}
146146
end
@@ -158,8 +158,6 @@ defmodule Asciinema.Accounts do
158158
end
159159
end
160160

161-
alias Phoenix.Token
162-
163161
def signup_token(email) do
164162
Token.sign(config(:secret), "signup", email)
165163
end
@@ -210,6 +208,17 @@ defmodule Asciinema.Accounts do
210208
end
211209
end
212210

211+
def generate_deletion_token(%User{id: user_id}) do
212+
Token.sign(config(:secret), "acct-delete", user_id)
213+
end
214+
215+
def verify_deletion_token(token) do
216+
case Token.verify(config(:secret), "acct-delete", token, max_age: 3600) do
217+
{:ok, user_id} -> {:ok, user_id}
218+
{:error, _} -> {:error, :token_invalid}
219+
end
220+
end
221+
213222
def get_user_with_api_token(token, tmp_username \\ nil) do
214223
case get_api_token(token) do
215224
{:ok, %ApiToken{user: user}} ->

lib/asciinema/accounts/user.ex

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ defmodule Asciinema.Accounts.User do
1212
field :theme_name, :string
1313
field :theme_prefer_original, :boolean, default: true
1414
field :terminal_font_family, :string
15-
field :asciicasts_private_by_default, :boolean, default: true
15+
16+
field :default_asciicast_visibility, Ecto.Enum,
17+
values: [:private, :unlisted, :public],
18+
default: :unlisted
19+
1620
field :last_login_at, :utc_datetime_usec
1721
field :is_admin, :boolean
1822

0 commit comments

Comments
 (0)