Skip to content

Commit 94432af

Browse files
committed
Merge branch 'table-component' of https://github.com/yshmarov/moneygun into table-component
2 parents ed7b4ec + 98f5d6d commit 94432af

Some content is hidden

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

52 files changed

+841
-41
lines changed

Gemfile

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,23 @@ end
7171
# active record
7272
gem "sqids" # for obfuscating IDs
7373

74-
# authentication and authorization
74+
# authentication
7575
gem "devise", "~> 4.9"
7676
gem "devise_invitable", "~> 2.0"
77+
78+
# oauth
79+
gem "omniauth-google-oauth2"
80+
gem "omniauth-github"
81+
gem "omniauth-rails_csrf_protection" # for omniauth 2.0
82+
83+
# authorization
7784
gem "pundit", "~> 2.3"
7885

7986
# frontend
8087
gem "view_component"
8188
gem "inline_svg", "~> 1.9"
8289
gem "active_link_to", "~> 1.0"
90+
gem "turbo_power", "~> 0.7.0"
8391

8492
# admin
8593
gem "avo", ">= 3.2"
@@ -89,5 +97,3 @@ gem "ransack", "~> 4.2"
8997
gem "pay", "~> 8.0"
9098
gem "stripe", "~> 13.0"
9199
gem "profitable"
92-
93-
gem "turbo_power", "~> 0.7.0"

Gemfile.lock

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,12 @@ GEM
158158
erubi (1.13.1)
159159
et-orbi (1.2.11)
160160
tzinfo
161+
faraday (2.13.1)
162+
faraday-net_http (>= 2.0, < 3.5)
163+
json
164+
logger
165+
faraday-net_http (3.4.0)
166+
net-http (>= 0.5.0)
161167
ffi (1.17.2-aarch64-linux-gnu)
162168
ffi (1.17.2-arm-linux-gnu)
163169
ffi (1.17.2-arm64-darwin)
@@ -169,6 +175,7 @@ GEM
169175
raabro (~> 1.4)
170176
globalid (1.2.1)
171177
activesupport (>= 6.1)
178+
hashie (5.0.0)
172179
highline (3.1.2)
173180
reline
174181
i18n (1.14.7)
@@ -203,6 +210,8 @@ GEM
203210
actionview (>= 5.0.0)
204211
activesupport (>= 5.0.0)
205212
json (2.12.2)
213+
jwt (2.10.1)
214+
base64
206215
kamal (2.6.1)
207216
activesupport (>= 7.0)
208217
base64 (~> 0.2)
@@ -247,6 +256,10 @@ GEM
247256
stimulus-rails
248257
turbo-rails
249258
msgpack (1.8.0)
259+
multi_xml (0.7.2)
260+
bigdecimal (~> 3.1)
261+
net-http (0.6.0)
262+
uri
250263
net-imap (0.5.8)
251264
date
252265
net-protocol
@@ -275,6 +288,32 @@ GEM
275288
racc (~> 1.4)
276289
nokogiri (1.18.8-x86_64-linux-gnu)
277290
racc (~> 1.4)
291+
oauth2 (2.0.11)
292+
faraday (>= 0.17.3, < 4.0)
293+
jwt (>= 1.0, < 4.0)
294+
logger (~> 1.2)
295+
multi_xml (~> 0.5)
296+
rack (>= 1.2, < 4)
297+
snaky_hash (~> 2.0, >= 2.0.3)
298+
version_gem (>= 1.1.8, < 3)
299+
omniauth (2.1.3)
300+
hashie (>= 3.4.6)
301+
rack (>= 2.2.3)
302+
rack-protection
303+
omniauth-github (2.0.1)
304+
omniauth (~> 2.0)
305+
omniauth-oauth2 (~> 1.8)
306+
omniauth-google-oauth2 (1.2.1)
307+
jwt (>= 2.9.2)
308+
oauth2 (~> 2.0)
309+
omniauth (~> 2.0)
310+
omniauth-oauth2 (~> 1.8)
311+
omniauth-oauth2 (1.8.0)
312+
oauth2 (>= 1.4, < 3)
313+
omniauth (~> 2.0)
314+
omniauth-rails_csrf_protection (1.0.2)
315+
actionpack (>= 4.2)
316+
omniauth (~> 2.0)
278317
orm_adapter (0.5.0)
279318
ostruct (0.6.1)
280319
pagy (9.3.4)
@@ -310,6 +349,10 @@ GEM
310349
raabro (1.4.0)
311350
racc (1.8.1)
312351
rack (3.1.15)
352+
rack-protection (4.1.1)
353+
base64 (>= 0.1.0)
354+
logger (>= 1.6.0)
355+
rack (>= 3.0.0, < 4)
313356
rack-session (2.1.1)
314357
base64 (>= 0.1.0)
315358
rack (>= 3.0.0)
@@ -412,6 +455,9 @@ GEM
412455
simplecov-html (0.13.1)
413456
simplecov_json_formatter (0.1.4)
414457
smart_properties (1.17.0)
458+
snaky_hash (2.0.3)
459+
hashie (>= 0.1.0, < 6)
460+
version_gem (>= 1.1.8, < 3)
415461
solid_cable (3.0.8)
416462
actioncable (>= 7.2)
417463
activejob (>= 7.2)
@@ -469,6 +515,7 @@ GEM
469515
unicode-emoji (4.0.4)
470516
uri (1.0.3)
471517
useragent (0.16.11)
518+
version_gem (1.1.8)
472519
view_component (3.23.2)
473520
activesupport (>= 5.2.0, < 8.1)
474521
concurrent-ruby (~> 1)
@@ -514,6 +561,9 @@ DEPENDENCIES
514561
kamal
515562
mission_control-jobs
516563
nested_scaffold!
564+
omniauth-github
565+
omniauth-google-oauth2
566+
omniauth-rails_csrf_protection
517567
pay (~> 8.0)
518568
pg (~> 1.1)
519569
profitable

app/assets/images/svg/github.svg

Lines changed: 3 additions & 0 deletions
Loading

app/assets/images/svg/google.svg

Lines changed: 3 additions & 0 deletions
Loading

app/controllers/search_controller.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
class SearchController < ApplicationController
22
def index
33
@organizations = if params[:query].present?
4-
current_user.organizations.where("name ILIKE ?", "%#{params[:query]}%")
4+
# Combine user's organizations + public/restricted organizations
5+
Organization.where(id: [
6+
current_user.organizations.pluck(:id),
7+
Organization.not_privacy_setting_private.pluck(:id)
8+
].flatten.uniq)
9+
.where("name ILIKE ?", "%#{params[:query]}%")
510
else
611
Organization.none
712
end
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Users::ConnectedAccountsController < ApplicationController
2+
before_action :set_connected_account, only: %i[destroy]
3+
4+
def index
5+
@connected_accounts = current_user.connected_accounts
6+
end
7+
8+
def destroy
9+
@connected_account.destroy
10+
redirect_to user_connected_accounts_path, notice: I18n.t("connected_accounts.destroy.success")
11+
end
12+
13+
private
14+
15+
def set_connected_account
16+
@connected_account = current_user.connected_accounts.find(params[:id])
17+
end
18+
end
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
2+
Devise.omniauth_configs.keys.each do |provider|
3+
define_method provider do
4+
handle_auth provider
5+
end
6+
end
7+
8+
private
9+
10+
def handle_auth(kind)
11+
user = User.from_omniauth(request.env["omniauth.auth"])
12+
if user.persisted?
13+
session[:new_user] = true if user.saved_change_to_id?
14+
flash[:notice] = I18n.t "devise.omniauth_callbacks.success", kind: kind
15+
sign_in_and_redirect user, event: :authentication
16+
else
17+
session["devise.auth_data"] = request.env["omniauth.auth"].except(:extra)
18+
redirect_to new_user_registration_url, alert: user.errors.full_messages.join("\n")
19+
end
20+
end
21+
22+
def failure
23+
redirect_to new_user_registration_url, alert: I18n.t("devise.omniauth_callbacks.failure")
24+
end
25+
end

app/helpers/organizations_helper.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,26 @@ def privacy_setting_options(key)
1616
display_text: "Invite only",
1717
description_text: "People can join your server directly with an invite",
1818
# icon_path: "svg/lock.svg"
19-
icon_path: "🔐"
19+
icon_path: "🔒"
2020
}
2121
when "restricted"
2222
{
2323
display_text: "Apply to join",
2424
description_text: "People must submit an application to be approved to join",
2525
# icon_path: "svg/envelope.svg"
26-
icon_path: "📨"
26+
icon_path: "📩"
2727
}
2828
when "public"
2929
{
3030
display_text: "Discoverable",
3131
description_text: "Anyone can join your server directly through Server Discovery",
3232
# icon_path: "svg/globe.svg"
33-
icon_path: "🌐"
33+
icon_path: "🌍"
3434
}
3535
end
3636
end
37+
38+
def privacy_setting_icon(key)
39+
tag.span privacy_setting_options(key)[:icon_path], class: "text-lg", alt: key, title: key
40+
end
3741
end

app/helpers/user_helper.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
module UserHelper
22
def user_avatar(user)
3-
tag.div class: "du-avatar du-avatar-placeholder" do
4-
tag.div class: "bg-neutral text-neutral-content w-8 rounded-full" do
5-
tag.span user.email[0..1].upcase, class: "text-xs"
3+
if user.connected_accounts.any? && user.connected_accounts.first.image_url.present?
4+
image_tag user.connected_accounts.first.image_url, alt: user.connected_accounts.first.name, class: "w-8 h-8 rounded-full"
5+
else
6+
tag.div class: "du-avatar du-avatar-placeholder" do
7+
tag.div class: "bg-neutral text-neutral-content w-8 rounded-full" do
8+
tag.span user.email[0..1].upcase, class: "text-xs"
9+
end
610
end
711
end
812
end

app/models/concerns/user/authentication.rb

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,29 @@ module User::Authentication
33

44
included do
55
# Include default devise modules. Others available are:
6-
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
6+
# :confirmable, :lockable, :timeoutable, :trackable
77
devise :invitable, :database_authenticatable, :registerable,
8-
:recoverable, :rememberable, :validatable
8+
:recoverable, :rememberable, :validatable,
9+
:omniauthable, omniauth_providers: Devise.omniauth_configs.keys
10+
11+
has_many :connected_accounts, dependent: :destroy
12+
end
13+
14+
class_methods do
15+
def from_omniauth(auth_payload)
16+
email = auth_payload.info&.email
17+
email ||= auth_payload.uid if auth_payload.provider == "saml"
18+
19+
user = User.where(email: email).first_or_initialize do |user|
20+
user.email = email
21+
user.password = Devise.friendly_token[0, 20] if user.password.blank?
22+
end
23+
24+
if user.save
25+
ConnectedAccount.create_or_update_from_omniauth(auth_payload, user)
26+
end
27+
28+
user
29+
end
930
end
1031
end

0 commit comments

Comments
 (0)