Skip to content

Commit

Permalink
Add and delete tenant users via devise_invitable
Browse files Browse the repository at this point in the history
  • Loading branch information
tdonohue committed Sep 15, 2017
1 parent 43f969a commit cab54e2
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 3 deletions.
23 changes: 23 additions & 0 deletions app/controllers/admin/users_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module Admin
class UsersController < AdminController
before_action :load_user, only: [:destroy]

# NOTE: User creation/invitations handled by devise_invitable

# Delete a user from the site
def destroy
if @user.destroy
redirect_to hyrax.admin_users_path, notice: t('hyrax.admin.users.destroy.success', user: @user.email)
else
logger.error("Hyku::User #{@user.email} could not be destroyed")
redirect_to hyrax.admin_users_path flash: { error: t('hyrax.admin.users.destroy.success', user: @user.email) }
end
end

private

def load_user
@user = User.from_url_component(params[:id])
end
end
end
9 changes: 9 additions & 0 deletions app/controllers/hyku/invitations_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Hyku
class InvitationsController < Devise::InvitationsController
# For devise_invitable, specify post-invite path to be 'Manage Users' form
# (as the user invitation form is also on that page)
def after_invite_path_for(_resource)
hyrax.admin_users_path
end
end
end
71 changes: 71 additions & 0 deletions app/views/hyrax/admin/users/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<% provide :page_header do %>
<h1><span class="fa fa-user"></span> <%= t('hyrax.admin.users.index.title') %></h1>
<% end %>

<div class="panel panel-default users-invite">
<div class="panel-heading">
<%= t('.invite_users') %>
</div>
<div class="panel-body">
<%# user_invitation_path is provided by devise_invitable %>
<%= simple_form_for :user, url: main_app.user_invitation_path, html: { class: 'form-inline pull-left' } do |f| %>
<div class="form-group">
<%= f.hint :email %>
<%= f.label :email, class: "control-label", required: false %>
<%= f.input_field :email, class: "form-control", value: "" %>
<%= f.submit t('.add'), class: 'btn btn-primary' %>
</div>
<% end %>
</div>
</div>

<div class="panel panel-default users-listing">
<div class="panel-heading">
<%= t('hyrax.admin.users.index.describe_users_html', count: @presenter.user_count) %>
</div>

<div class="panel-body">
<div class="table-responsive">
<table class="table table-striped datatable">
<thead>
<tr>
<th></th>
<th><%= t('.id_label') %></th>
<th><%= t('.role_label') %></th>
<th><%= t('.access_label') %></th>
<th><%= t('.status_label') %></th>
<th><%= t('.action_label') %></th>
</tr>
</thead>
<tbody>
<% @presenter.users.each do |user| %>
<tr>
<td><%= link_to hyrax.user_path(user) do %>
<%= image_tag(user.avatar.url(:thumb), width: 30) if user.avatar.file %>
<% end %>
</td>
<td><%= link_to user.email, hyrax.user_path(user) %></td>
<td><% roles = @presenter.user_roles(user) %>
<ul><% roles.each do |role| %>
<li><%= role %></li>
<% end %>
</ul>
</td>
<td>
<%# in the case that a user is created who never signs in, this is necessary %>
<relative-time datetime="<%= @presenter.last_accessed(user).getutc.iso8601 %>" title="<%= @presenter.last_accessed(user).to_formatted_s(:standard) %>">
<%= @presenter.last_accessed(user).to_formatted_s(:long_ordinal) %>
</relative-time>
</td>
<%# If user accepted invite or was a self-signup, they are active. Otherwise pending %>
<td><%= user.accepted_or_not_invited? ? t('.status.active') : t('.status.pending') %></td>
<td>
<%= link_to t('.delete'), main_app.admin_user_path(user), class: 'btn btn-danger btn-sm action-delete', method: :delete, data: { confirm: t('hyrax.admin.users.destroy.confirmation', user: user.email) } %>
</td>
</tr>
<% end %>
</tbody>
</table>
</div>
</div>
</div>
16 changes: 15 additions & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ en:
submit: 'Go'
hyku:
splash:
account_denied: You are not authorized to create tenants
account_denied: You are not authorized to create tenants
account_login: Login to get started
account_signup: Get Started
left_heading: Easy
Expand Down Expand Up @@ -142,6 +142,20 @@ en:
roles_and_permissions: 'Users and groups'
system_status: 'System status'
technical: 'Technical'
users:
index:
action_label: Action
add: Invite user
delete: Delete
invite_users: 'Add or Invite user via email'
status_label: Status
status:
active: Active
pending: Pending
destroy:
confirmation: 'Are you sure you wish to delete the user "%{user}"? This action is irreversible.'
success: 'User "%{user}" has been successfully deleted.'
failure: 'User "%{user}" could not be deleted.'
proprietor:
accounts:
index:
Expand Down
4 changes: 4 additions & 0 deletions config/locales/simple_form.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ en:
user_ids: 'User ID'
page_size:
per: 'Show'
user:
email: 'Email address'
# defaults:
# password: 'Password'
# user:
Expand All @@ -49,6 +51,8 @@ en:
admin_emails: 'Enter one email address at a time'
hyku_group:
description: 'A brief summary of the role of the group'
user:
email: 'Enter one email address at a time. You may also resend an invitation via this form.'
# defaults:
# username: 'User name to sign in.'
# password: 'No special characters, please.'
Expand Down
4 changes: 2 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

root 'hyrax/homepage#index'

devise_for :users, controllers: { registrations: 'hyku/registrations' }
devise_for :users, controllers: { invitations: 'hyku/invitations', registrations: 'hyku/registrations' }
mount Qa::Engine => '/authorities'

mount Blacklight::Engine => '/'
Expand Down Expand Up @@ -58,6 +58,7 @@

namespace :admin do
resource :account, only: [:edit, :update]
resources :users, only: [:destroy]
resources :groups do
member do
get :remove
Expand All @@ -74,5 +75,4 @@

mount Peek::Railtie => '/peek'
mount Riiif::Engine => '/images', as: 'riiif'

end

0 comments on commit cab54e2

Please sign in to comment.