Skip to content

Commit 5e2a120

Browse files
committed
Remove roles
1 parent e3b410a commit 5e2a120

File tree

20 files changed

+44
-256
lines changed

20 files changed

+44
-256
lines changed

template/docs/{{app_name}}/auth.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ Authentication is the process of verifying the credentials of a user. We use AWS
1313

1414
Authorization is the process of determining whether a user has access to a specific resource. We use [Pundit](https://github.com/varvet/pundit) for authorization.
1515

16-
- User roles are defined in the `user_roles` table
1716
- Policies (`app/policies`) are created for each model to define who can perform what actions
1817
- Policies are used in controllers to authorize actions
1918
- Policies are used in views to show/hide elements based on user permissions

template/{{app_name}}/app/controllers/application_controller.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@ def after_sign_in_path_for(resource)
2424
return users_mfa_preference_path
2525
end
2626

27-
if resource.employer?
28-
return dev_sandbox_path
29-
end
30-
3127
users_account_path
3228
end
3329
end

template/{{app_name}}/app/controllers/users/registrations_controller.rb

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,8 @@ class Users::RegistrationsController < ApplicationController
44
layout "users"
55
skip_after_action :verify_authorized
66

7-
def new_applicant
8-
@form = Users::RegistrationForm.new(role: "applicant")
9-
render :new
10-
end
11-
12-
def new_employer
13-
@form = Users::RegistrationForm.new(role: "employer")
7+
def new
8+
@form = Users::RegistrationForm.new()
149
render :new
1510
end
1611

@@ -23,7 +18,7 @@ def create
2318
end
2419

2520
begin
26-
auth_service.register(@form.email, @form.password, @form.role)
21+
auth_service.register(@form.email, @form.password)
2722
rescue Auth::Errors::BaseAuthError => e
2823
flash.now[:errors] = [ e.message ]
2924
return render :new, status: :unprocessable_entity
@@ -77,7 +72,7 @@ def auth_service
7772
end
7873

7974
def registration_params
80-
params.require(:users_registration_form).permit(:email, :password, :password_confirmation, :role, :spam_trap)
75+
params.require(:users_registration_form).permit(:email, :password, :password_confirmation, :spam_trap)
8176
end
8277

8378
def verify_account_params

template/{{app_name}}/app/forms/users/registration_form.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
class Users::RegistrationForm
44
include ActiveModel::Model
55

6-
attr_accessor :email, :password, :password_confirmation, :role, :spam_trap
6+
attr_accessor :email, :password, :password_confirmation, :spam_trap
77

8-
validates :email, :password, :role, presence: true
8+
validates :email, :password, presence: true
99
validates :email, format: { with: URI::MailTo::EMAIL_REGEXP }, if: -> { email.present? }
1010

1111
validates :password, confirmation: true, if: -> { password.present? }

template/{{app_name}}/app/models/user.rb

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,11 @@ class User < ApplicationRecord
88

99
# == Relationships ========================================================
1010
has_many :tasks
11-
has_one :user_role, dependent: :destroy
1211

1312
# == Validations ==========================================================
1413
validates :provider, presence: true
1514

1615
# == Methods ==============================================================
17-
def applicant?
18-
user_role&.applicant?
19-
end
20-
21-
def employer?
22-
user_role&.employer?
23-
end
24-
25-
def superadmin?
26-
email.include?("+admin")
27-
end
2816

2917
# Check if the access token is expired or will expire within the next `minutes` minutes.
3018
# Access token is only stored in the session, so it needs passed in, rather than accessed from the model.

template/{{app_name}}/app/models/user_role.rb

Lines changed: 0 additions & 8 deletions
This file was deleted.

template/{{app_name}}/app/services/auth_service.rb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ def respond_to_auth_challenge(code, challenge = {})
3434
handle_auth_result(response, challenge[:email])
3535
end
3636

37-
def register(email, password, role)
37+
def register(email, password)
3838
# @TODO: Handle errors from the auth service, like when the email is already taken
3939
# See https://github.com/navapbc/template-application-rails/issues/15
4040
account = @auth_adapter.create_account(email, password)
4141

42-
create_db_user(account[:uid], email, account[:provider], role)
42+
create_db_user(account[:uid], email, account[:provider])
4343
end
4444

4545
# Verify the code sent to the user as part of their initial sign up process.
@@ -72,15 +72,14 @@ def disable_software_token(user)
7272

7373
private
7474

75-
def create_db_user(uid, email, provider, role = "applicant")
76-
Rails.logger.info "Creating User uid: #{uid}, and UserRole: #{role}"
75+
def create_db_user(uid, email, provider)
76+
Rails.logger.info "Creating User uid: #{uid}"
7777

7878
user = User.create!(
7979
uid: uid,
8080
email: email,
8181
provider: provider,
8282
)
83-
user_role = UserRole.create!(user: user, role: role)
8483
user
8584
end
8685

template/{{app_name}}/app/views/home/index.html.erb

Lines changed: 8 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -7,66 +7,11 @@
77
<p class="usa-intro">
88
<%= t('.intro') %>
99
</p>
10-
11-
<div class="grid-row">
12-
<ul class="usa-card-group">
13-
<li class="usa-card grid-col-12 mobile-lg:grid-col-6">
14-
<div class="usa-card__container">
15-
<div class="usa-card__header">
16-
<h2 class="usa-card__heading">
17-
<%= t('.applicant_heading') %>
18-
</h2>
19-
</div>
20-
<div class="usa-card__media">
21-
<div class="usa-card__img">
22-
<%= image_tag 'applicant.jpg', alt: "Man with two younger children" %>
23-
</div>
24-
</div>
25-
<div class="usa-card__body">
26-
<p>
27-
<%= t('.applicant_body') %>
28-
</p>
29-
</div>
30-
<div class="usa-card__footer">
31-
<a href="<%= users_new_applicant_registration_path %>" class="usa-button">
32-
<%= t('.applicant_signup') %>
33-
</a>
34-
<p>
35-
<a class="usa-link" href="<%= new_user_session_path %>">
36-
<%= t('.or_sign_in') %>
37-
</a>
38-
</p>
39-
</div>
40-
</div>
41-
</li>
42-
<li class="usa-card grid-col-12 mobile-lg:grid-col-6">
43-
<div class="usa-card__container">
44-
<div class="usa-card__header">
45-
<h2 class="usa-card__heading">
46-
<%= t('.employer_heading') %>
47-
</h2>
48-
</div>
49-
<div class="usa-card__media">
50-
<div class="usa-card__img">
51-
<%= image_tag 'employer.jpg', alt: "Person at a desk using a laptop" %>
52-
</div>
53-
</div>
54-
<div class="usa-card__body">
55-
<p>
56-
<%= t('.employer_body') %>
57-
</p>
58-
</div>
59-
<div class="usa-card__footer">
60-
<a href="<%= users_new_employer_registration_path %>" class="usa-button">
61-
<%= t('.employer_signup') %>
62-
</a>
63-
<p>
64-
<a class="usa-link" href="<%= new_user_session_path %>">
65-
<%= t('.or_sign_in') %>
66-
</a>
67-
</p>
68-
</div>
69-
</div>
70-
</li>
71-
</ul>
72-
</div>
10+
<a href="<%= users_new_registration_path %>" class="usa-button">
11+
<%= t('.signup') %>
12+
</a>
13+
<p>
14+
<a class="usa-link" href="<%= new_user_session_path %>">
15+
<%= t('.or_sign_in') %>
16+
</a>
17+
</p>
Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
<% content_for :title, t(".title_#{@form.role}") %>
2-
<% icon = @form.role == "applicant" ? "local_library" : "local_library" %>
3-
<% icon_color = @form.role == "applicant" ? "violet" : "mint" %>
1+
<% content_for :title, t(".title") %>
2+
<% icon = "local_library" %>
3+
<% icon_color = "violet" %>
44

55
<div class="bg-white padding-top-3 padding-bottom-5 padding-x-5 border border-base-lighter">
66
<div class="text-center margin-bottom-2 padding-bottom-2 border-bottom border-base-lighter">
77
<svg class="usa-icon usa-icon--size-6 text-<%= icon_color %>" aria-hidden="true" focusable="false" role="img">
88
<use xlink:href="<%= asset_path "@uswds/uswds/dist/img/sprite.svg##{icon}" %>"></use>
99
</svg>
1010

11-
<h1 class="font-heading-xl margin-y-0"><%= t(".title_#{@form.role}") %></h1>
11+
<h1 class="font-heading-xl margin-y-0"><%= t(".title") %></h1>
1212
</div>
1313

1414
<%= us_form_with model: @form, url: users_registrations_path, local: true do |f| %>
15-
<%= f.hidden_field :role %>
1615
<%= f.honeypot_field %>
1716
<%= f.email_field :email %>
1817

@@ -29,7 +28,7 @@
2928

3029
<%= f.password_field :password_confirmation, autocomplete: "new-password", id: "new-password-confirmation" %>
3130

32-
<%= f.submit t(".title_#{@form.role}") %>
31+
<%= f.submit t(".title") %>
3332
<% end %>
3433
</div>
3534

@@ -39,27 +38,3 @@
3938
<%= t ".login" %>
4039
</a>
4140
</p>
42-
43-
<%= content_for :sidebar do %>
44-
<% if @form.role == "applicant" %>
45-
<h2 class="font-heading-lg"><%= t('.are_employer_heading') %></h2>
46-
<div class="usa-prose">
47-
<p><%= t('.are_employer_body') %></p>
48-
<p>
49-
<a class="usa-button usa-button--outline" href="<%= users_new_employer_registration_path %>">
50-
<%= t('.are_employer_action') %>
51-
</a>
52-
</p>
53-
</div>
54-
<% else %>
55-
<h2 class="font-heading-lg"><%= t('.are_applicant_heading') %></h2>
56-
<div class="usa-prose">
57-
<p><%= t('.are_applicant_body') %></p>
58-
<p>
59-
<a class="usa-button usa-button--outline" href="<%= users_new_applicant_registration_path %>">
60-
<%= t('.are_applicant_action') %>
61-
</a>
62-
</p>
63-
</div>
64-
<% end %>
65-
<% end %>

template/{{app_name}}/app/views/users/sessions/new.html.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
<p class="text-center">
3131
<%= t('.no_account') %>
32-
<a class="usa-link" href="<%= url_for users_new_applicant_registration_path %>">
32+
<a class="usa-link" href="<%= url_for users_new_registration_path %>">
3333
<%= t('.create_account') %>
3434
</a>.
35-
</p>
35+
</p>

0 commit comments

Comments
 (0)