forked from fixin.me/fixin.me
Only user can delete his profile
This commit is contained in:
parent
23b8c82602
commit
74965c5c0e
@ -90,6 +90,9 @@ input:read-only:hover {
|
|||||||
.nav-menu .right .image-button {
|
.nav-menu .right .image-button {
|
||||||
float: right;
|
float: right;
|
||||||
}
|
}
|
||||||
|
.nav-menu .left .image-button {
|
||||||
|
float: left;
|
||||||
|
}
|
||||||
.nav-menu .tab-button {
|
.nav-menu .tab-button {
|
||||||
border: none;
|
border: none;
|
||||||
border-radius: 0;
|
border-radius: 0;
|
||||||
@ -131,6 +134,10 @@ input[type=submit]:hover {
|
|||||||
color: white;
|
color: white;
|
||||||
fill: white;
|
fill: white;
|
||||||
}
|
}
|
||||||
|
.image-button.dangerous:hover {
|
||||||
|
background-color: #ff1f5b;
|
||||||
|
border-color: #ff1f5b;
|
||||||
|
}
|
||||||
.image-button:focus-visible,
|
.image-button:focus-visible,
|
||||||
.image-button.active:focus-visible,
|
.image-button.active:focus-visible,
|
||||||
input[type=submit]:focus-visible {
|
input[type=submit]:focus-visible {
|
||||||
@ -142,6 +149,10 @@ input[type=submit]:hover:focus-visible {
|
|||||||
background-color: #006c9b;
|
background-color: #006c9b;
|
||||||
border-color: #006c9b;
|
border-color: #006c9b;
|
||||||
}
|
}
|
||||||
|
.image-button.dangerous:hover:focus-visible {
|
||||||
|
background-color: #b21237;
|
||||||
|
border-color: #b21237;
|
||||||
|
}
|
||||||
|
|
||||||
.flashes {
|
.flashes {
|
||||||
height: 2.1rem;
|
height: 2.1rem;
|
||||||
|
@ -1,17 +1,20 @@
|
|||||||
class UsersController < ApplicationController
|
class UsersController < ApplicationController
|
||||||
before_action :find_user, only: [:destroy]
|
before_action :find_user, only: [:destroy]
|
||||||
before_action do
|
before_action do
|
||||||
raise AccessForbidden unless (current_user == @user) || current_user.at_least(:admin)
|
raise AccessForbidden unless current_user.at_least(:admin)
|
||||||
end
|
end
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@users = User.all
|
@users = User.all
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
# TODO: add #show and #update to change user status
|
||||||
@user.destroy
|
# TODO: remove admin dependent fields from registrations#edit and move them to
|
||||||
redirect_to action: :index, notice: t(".success")
|
# #show
|
||||||
end
|
|
||||||
|
# NOTE: limited actions availabe to :admin by design. Users are meant to
|
||||||
|
# manage their accounts by themselves through registrations. In future :admin
|
||||||
|
# may be allowed to sing-in as user and make changes there.
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
@ -5,21 +5,18 @@
|
|||||||
<th><%= User.human_attribute_name(:status).capitalize %></th>
|
<th><%= User.human_attribute_name(:status).capitalize %></th>
|
||||||
<th><%= User.human_attribute_name(:created_at).capitalize %> <sup>UTC</sup></th>
|
<th><%= User.human_attribute_name(:created_at).capitalize %> <sup>UTC</sup></th>
|
||||||
<th><%= User.human_attribute_name(:confirmed_at).capitalize %></th>
|
<th><%= User.human_attribute_name(:confirmed_at).capitalize %></th>
|
||||||
<th><%= t :actions %></th>
|
<!-- <th><%#= t :actions %></th> -->
|
||||||
</tr>
|
</tr>
|
||||||
<% @users.each do |user| %>
|
<% @users.each do |user| %>
|
||||||
<tr>
|
<tr>
|
||||||
<%# TODO: add user edit link %>
|
<%# TODO: add user show link %>
|
||||||
<td><%= user.email %></td>
|
<td><%= user.email %></td>
|
||||||
<td><%= user.status %></td>
|
<td><%= user.status %></td>
|
||||||
<td><%= user.created_at.to_fs(:db_without_sec) %></td>
|
<td><%= user.created_at.to_fs(:db_without_sec) %></td>
|
||||||
<td class="svg">
|
<td class="svg">
|
||||||
<%= svg_tag "pictograms/checkbox-marked-outline" if user.confirmed_at.present? %>
|
<%= svg_tag "pictograms/checkbox-marked-outline" if user.confirmed_at.present? %>
|
||||||
</td>
|
</td>
|
||||||
<td class="actions">
|
<!-- <td class="actions"></td> -->
|
||||||
<%= image_link_to t(:delete), "account-remove-outline", user_path(user),
|
|
||||||
data: { turbo: true, turbo_method: :delete } %>
|
|
||||||
</td>
|
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
</table>
|
</table>
|
||||||
|
@ -1,6 +1,13 @@
|
|||||||
<% content_for :navigation, flush: true do %>
|
<% content_for :navigation, flush: true do %>
|
||||||
<%= image_link_to t(:back), "arrow-left-bold-outline",
|
<div class="left">
|
||||||
request.referer.present? ? :back : root_url %>
|
<%= image_link_to t(".back"), "arrow-left-bold-outline",
|
||||||
|
request.referer.present? ? :back : root_url %>
|
||||||
|
</div>
|
||||||
|
<div class="right">
|
||||||
|
<%= image_link_to t(".delete"), "account-remove-outline", user_registration_path,
|
||||||
|
class: "dangerous",
|
||||||
|
data: { turbo: true, turbo_method: :delete, turbo_confirm: t(".confirm_delete") } %>
|
||||||
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<%= tabular_form_for resource, url: registration_path(resource), html: {method: :patch} do |f| %>
|
<%= tabular_form_for resource, url: registration_path(resource), html: {method: :patch} do |f| %>
|
||||||
|
@ -18,6 +18,10 @@ en:
|
|||||||
new:
|
new:
|
||||||
password_confirmation: Retype password
|
password_confirmation: Retype password
|
||||||
edit:
|
edit:
|
||||||
|
back: Back
|
||||||
|
confirm_delete: Are you sure you want to delete profile?
|
||||||
|
All data will be irretrievably lost.
|
||||||
|
delete: Delete profile
|
||||||
unconfirmed_email_hint: (since %{timestamp})
|
unconfirmed_email_hint: (since %{timestamp})
|
||||||
blank_password_hint_html: leave blank to keep unchanged%{subhint}
|
blank_password_hint_html: leave blank to keep unchanged%{subhint}
|
||||||
minimum_length_hint_html:
|
minimum_length_hint_html:
|
||||||
@ -27,14 +31,12 @@ en:
|
|||||||
sessions:
|
sessions:
|
||||||
new:
|
new:
|
||||||
remember_me: Remember me
|
remember_me: Remember me
|
||||||
destroy:
|
|
||||||
success: User has been successfully deleted.
|
|
||||||
layouts:
|
layouts:
|
||||||
application:
|
application:
|
||||||
users: Users
|
users: Users
|
||||||
actions: Actions
|
actions: Actions
|
||||||
delete: Delete
|
|
||||||
or: or
|
or: or
|
||||||
|
profile: Profile
|
||||||
register: Register
|
register: Register
|
||||||
sign_in: Sign in
|
sign_in: Sign in
|
||||||
sign_out: Sign out
|
sign_out: Sign out
|
||||||
|
@ -2,7 +2,7 @@ Rails.application.routes.draw do
|
|||||||
devise_for :users, path: '', path_names: {registration: 'profile'},
|
devise_for :users, path: '', path_names: {registration: 'profile'},
|
||||||
controllers: {registrations: :registrations}
|
controllers: {registrations: :registrations}
|
||||||
|
|
||||||
resources :users, only: [:index, :destroy]
|
resources :users, only: [:index]
|
||||||
|
|
||||||
devise_scope :user do
|
devise_scope :user do
|
||||||
root to: "devise/sessions#new"
|
root to: "devise/sessions#new"
|
||||||
|
@ -93,21 +93,30 @@ class UsersTest < ApplicationSystemTestCase
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test "delete user" do
|
test "show profile" do
|
||||||
sign_in user: users.select(&:admin?).select(&:confirmed?).sample
|
sign_in user: users.select(&:admin?).select(&:confirmed?).sample
|
||||||
click_link t('layouts.application.users')
|
click_link t('layouts.application.users')
|
||||||
|
#all('tr').drop(1).sample.click_link t(:view)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "destroy profile" do
|
||||||
|
sign_in user: users.select(&:confirmed?).sample
|
||||||
|
click_link t(:profile)
|
||||||
assert_difference ->{ User.count }, -1 do
|
assert_difference ->{ User.count }, -1 do
|
||||||
all('tr').drop(1).sample.click_link t(:delete)
|
accept_confirm { click_link t('users.registrations.edit.delete') }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test "users index forbidden for non admin" do
|
test "index forbidden for non admin" do
|
||||||
sign_in user: users.reject(&:admin?).select(&:confirmed?).sample
|
sign_in user: users.reject(&:admin?).select(&:confirmed?).sample
|
||||||
visit users_path
|
visit users_path
|
||||||
assert has_no_link?t('layouts.application.users')
|
assert has_no_link?t('layouts.application.users')
|
||||||
assert_title "Access is forbidden to this page (403)"
|
assert_title "Access is forbidden to this page (403)"
|
||||||
end
|
end
|
||||||
|
|
||||||
test "update e-mail" do
|
test "update profile" do
|
||||||
|
end
|
||||||
|
|
||||||
|
test "update status forbidded for non admin" do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user