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

Refactored auth #30

Merged
merged 14 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ gem "sentry-sidekiq"
gem 'http_accept_language'
gem 'listen'
gem 'config'
gem 'rack-cors', require: 'rack/cors'

# Views and CSS
gem 'haml'
Expand All @@ -56,6 +57,7 @@ gem 'local_time'
gem 'erb-formatter'



# Testing
gem 'capybara'

Expand Down
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,8 @@ GEM
nio4r (~> 2.0)
racc (1.8.1)
rack (3.1.8)
rack-cors (2.0.2)
rack (>= 2.0.0)
rack-session (2.0.0)
rack (>= 3.0.0)
rack-test (2.1.0)
Expand Down Expand Up @@ -505,6 +507,7 @@ DEPENDENCIES
local_time
mysql2 (~> 0.5)
puma (>= 5.0)
rack-cors
rails (~> 7.2.1)
rails-controller-testing
rake
Expand Down
6 changes: 4 additions & 2 deletions Guardfile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# TODO: Check this, just copied from Engine

guard 'rspec', :version => 2 do
guard 'rspec', version: 2 do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }
Expand All @@ -13,7 +13,9 @@
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m|
[ "spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb",
"spec/acceptance/#{m[1]}_spec.rb" ] }
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
watch('spec/spec_helper.rb') { "spec" }
watch('config/routes.rb') { "spec/routing" }
Expand Down
1 change: 0 additions & 1 deletion app/assets/config/manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@
//= link_tree ../../javascript .js
//= link_tree ../../../vendor/javascript .js
//= link_tree ../builds
//= link auth.css
Binary file added app/assets/images/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 0 additions & 4 deletions app/assets/stylesheets/auth.css

This file was deleted.

2 changes: 2 additions & 0 deletions app/components/admin/user_row/component.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module Admin::UserRow
class Component < ApplicationComponent
include ButtonHelper

option :user
option :confirmed, default: proc { true }
option :confirm_path
Expand Down
2 changes: 1 addition & 1 deletion app/components/css_classes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ module CssClasses
private

def merge_attributes(attributes)
attributes.merge(class: [attributes[:class], *self.class::DEFAULT_CLASSES].compact.join(' '))
attributes.merge(class: [ attributes[:class], *self.class::DEFAULT_CLASSES ].compact.join(" "))
end
end
2 changes: 1 addition & 1 deletion app/components/hovercard/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ module Hovercard
class Component < ApplicationComponent
option :path
option :text, default: proc { "" }
option :placement_class, default: proc { 'right-2' }
option :placement_class, default: proc { "right-2" }
end
end
2 changes: 1 addition & 1 deletion app/components/identity/sidebar_item_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class Identity::SidebarItemComponent < ApplicationComponent
option :title
option :explanation
option :active, default: proc { false }
option :icon, default: proc { 'identification' }
option :icon, default: proc { "identification" }

def css_classes
if @active
Expand Down
4 changes: 2 additions & 2 deletions app/components/identity/token_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ class Identity::TokenComponent < ApplicationComponent
include ButtonHelper
include Turbo::FramesHelper

# TODO: Move this to a proper token generator class.
TOKEN_PREFIX = Rails.env.staging? ? 'etm_beta_' : 'etm_'
# TODO: this should not be here
TOKEN_PREFIX = Rails.env.staging? ? "etm_beta_" : "etm_"

def initialize(token:)
@token = token
Expand Down
2 changes: 1 addition & 1 deletion app/components/login/action_arrow_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Login
class ActionArrowComponent < ApplicationComponent
def call
heroicon @icon, options: { class: 'flex-shrink-0 ml-1 mt-px group-hover:translate-x-1 group-active:translate-x-1 transition duration-300', aria_hidden: true }
heroicon(@icon, options: { class: "flex-shrink-0 ml-1 mt-px group-hover:translate-x-1 group-active:translate-x-1 transition duration-300", aria_hidden: true })
end
end
end
6 changes: 3 additions & 3 deletions app/components/login/action_button_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ module Login
class ActionButtonComponent < ApplicationComponent
include ButtonHelper

BASE_CLASSES = 'text-base flex items-center justify-center group'
BASE_CLASSES = "text-base flex items-center justify-center group"

def initialize(form:, color: :default, size: :base, **attributes)
@form = form

additional_classes = [BASE_CLASSES, attributes.delete(:class)].compact.join(' ')
additional_classes = [ BASE_CLASSES, attributes.delete(:class) ].compact.join(" ")

@attributes = attributes.merge(
class: button_classes(additional_classes, color:, size:),
type: attributes[:type] || 'submit'
type: attributes[:type] || "submit"
)
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/components/login/button_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Login
class ButtonComponent < ActionButtonComponent
def initialize(form:)
super(form:, type: :submit, color: :primary, size: :lg, class: 'w-full !py-3 mt-5 bg-midnight-600')
super(form:, type: :submit, color: :primary, size: :lg, class: "w-full !py-3 mt-5 bg-midnight-600")
end
end
end
10 changes: 5 additions & 5 deletions app/components/modal_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ def stimulus
@stimulus ||=
if turbo_modal?
StimulusConfig.new(
controller: 'modal',
controller: "modal",
turbo_frame_id: :modal,
button_close_action: 'click->modal#close',
backdrop_close_action: 'mousedown->modal#closeWithBackdrop',
keyboard_close_action: 'keyup@window->modal#closeWithKeyboard'
button_close_action: "click->modal#close",
backdrop_close_action: "mousedown->modal#closeWithBackdrop",
keyboard_close_action: "keyup@window->modal#closeWithKeyboard"
)
else
StimulusConfig.new(turbo_frame_id: :static_modal)
Expand All @@ -44,6 +44,6 @@ def close_link(inline_content, url = nil, **kwargs)
private

def turbo_modal?
request.headers['Turbo-Frame'] == 'modal'
request.headers["Turbo-Frame"] == "modal"
end
end
2 changes: 1 addition & 1 deletion app/components/notice_banner/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ class Component < ApplicationComponent
option :text
option :path, default: proc { "" }
option :button_text, default: proc { "" }
option :icon, default: proc { 'information-circle' }
option :icon, default: proc { "information-circle" }
end
end
4 changes: 2 additions & 2 deletions app/components/saved_scenario_user/user_row/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
end

def disabled_classes
@destroyable ? "text-sm hover:cursor-pointer" : "text-sm bg-none bg-midnight-300 border-midnight-300"

Check failure on line 22 in app/components/saved_scenario_user/user_row/component.rb

View workflow job for this annotation

GitHub Actions / lint

Layout/LineLength: Line is too long. [107/100]
end

def destroy_classes
Expand All @@ -28,9 +28,9 @@

def destroy_text
if @destroyable
t('saved_scenario_users.confirm_destroy.button')
t("saved_scenario_users.confirm_destroy.button")
else
t('saved_scenario_users.confirm_destroy.not_possible')
t("saved_scenario_users.confirm_destroy.not_possible")
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions app/components/toast_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ def initialize(message:, type: :notice)
@type = type

if message.is_a?(Hash)
@title = no_break_on_hyphen(message[:title] || message['title'])
@message = no_break_on_hyphen(message[:message] || message['message'])
@title = no_break_on_hyphen(message[:title] || message["title"])
@message = no_break_on_hyphen(message[:message] || message["message"])
else
@message = no_break_on_hyphen(message)
end
Expand All @@ -16,6 +16,6 @@ def initialize(message:, type: :notice)

# Replaces any hyphen in the message with a character taht won't trigger line breaks.
def no_break_on_hyphen(string)
string.tr('-', '‑')
string.tr("-", "‑")
end
end
2 changes: 1 addition & 1 deletion app/controllers/admin/saved_scenarios_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class SavedScenariosController < ApplicationController
def index
@saved_scenarios = SavedScenario.available
.includes(:featured_scenario, :users)
.order('updated_at DESC')
.order("updated_at DESC")
end
end
end
15 changes: 11 additions & 4 deletions app/controllers/admin/staff_applications_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: true
require 'myetm/staff_applications'

require "myetm/staff_applications"

module Admin
# Updates a staff application with a new URI.
Expand All @@ -14,17 +15,23 @@ def index
def update
result = CreateStaffApplication.call(
current_user,
MyEtm::StaffApplications.find(params[:format]),
uri: params[:uri].presence
MyEtm::StaffApplications.find(staff_application_params[:format]),
uri: staff_application_params[:uri].presence
)

if result.success?
flash[:notice] = 'The application was updated.'
flash[:notice] = "The application was updated."
else
flash[:alert] = result.failure.errors.full_messages.to_sentence
end

redirect_to admin_applications_path
end

private

def staff_application_params
params.permit(:format, :uri)
end
end
end
23 changes: 11 additions & 12 deletions app/controllers/admin/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,27 @@

# All users
def all
@users = User.all.includes(:saved_scenarios)#, :collections)
@users = User.all.includes(:saved_scenarios) # , :collections)
end

# Instant confirmation for our users that struggel with their spam
# Instant confirmation for our users that struggle with their spam
def confirm
@user.confirm!
flash[:notice] = "User confirmed."
end

def edit; end

def update
if @user.update!(user_params.compact_blank)
flash[:notice] = t('admin.users.edit.success')
if @user.update(user_params.compact_blank)
flash[:notice] = t("admin.users.edit.success")

respond_to do |format|
format.html { redirect_to(admin_users_path) }

format.turbo_stream do
render turbo_stream: [
turbo_stream.update(:modal, ''),
turbo_stream.update(:modal, ""),
turbo_user,
turbo_notice
]
Expand All @@ -48,19 +49,17 @@
end

def user_params
params.require(:user).permit(:name, :email, :password, :admin)
attributes = [:name, :email, :password]

Check failure on line 52 in app/controllers/admin/users_controller.rb

View workflow job for this annotation

GitHub Actions / lint

Layout/SpaceInsideArrayLiteralBrackets: Use space inside array brackets.

Check failure on line 52 in app/controllers/admin/users_controller.rb

View workflow job for this annotation

GitHub Actions / lint

Layout/SpaceInsideArrayLiteralBrackets: Use space inside array brackets.
attributes << :admin if current_user&.admin?
params.require(:user).permit(*attributes)
end

def turbo_notice(message = nil)
if message.nil?
message = flash[:notice]
flash.delete(:notice)
end

message ||= flash.delete(:notice)
return if message.nil?

turbo_stream.update(
'toast',
"toast",
ToastComponent.new(type: :notice, message:).render_in(view_context)
)
end
Expand Down
Loading
Loading