Skip to content
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
6 changes: 6 additions & 0 deletions backend/app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@

class ApplicationController < ActionController::Base
before_action :set_paper_trail_whodunnit

def after_sign_in_path_for(resource)
return admin_root_path if resource.is_a?(User) && resource.admin?

super
end
end
2 changes: 1 addition & 1 deletion backend/app/dashboards/user_dashboard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class UserDashboard < Administrate::BaseDashboard
# which determines how the attribute is displayed
# on pages throughout the dashboard.
ATTRIBUTE_TYPES = {
id: Field::Number,
id: Field::String,
admin: Field::Boolean,
email: Field::String,
password: Field::String,
Expand Down
29 changes: 29 additions & 0 deletions backend/spec/requests/sessions_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# frozen_string_literal: true

require "rails_helper"

RSpec.describe "Sessions" do
describe "POST /users/sign_in" do
let(:password) { "password" }

context "when the user is an admin" do
let(:user) { create(:user, admin: true, password: password) }

before do
post user_session_path, params: { user: { email: user.email, password: password } }
end

it { expect(response).to redirect_to(admin_root_path) }
end

context "when the user is not an admin" do
let(:user) { create(:user, password: password) }

before do
post user_session_path, params: { user: { email: user.email, password: password } }
end

it { expect(response).not_to redirect_to(admin_root_path) }
end
end
end
Loading