Add action Settings::SessionsController#index
This commit is contained in:
parent
da504901e2
commit
53e521bf49
12 changed files with 109 additions and 1 deletions
12
app/controllers/settings/sessions_controller.rb
Normal file
12
app/controllers/settings/sessions_controller.rb
Normal file
|
@ -0,0 +1,12 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Settings::SessionsController < ApplicationController
|
||||
before_action :skip_policy_scope, only: :index
|
||||
|
||||
# GET /settings/sessions
|
||||
def index
|
||||
authorize [:settings, Session]
|
||||
|
||||
@sessions = current_account.sessions.order(logged_at: :desc).limit(10)
|
||||
end
|
||||
end
|
7
app/policies/settings/session_policy.rb
Normal file
7
app/policies/settings/session_policy.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Settings::SessionPolicy < ApplicationPolicy
|
||||
def index?
|
||||
!!account
|
||||
end
|
||||
end
|
|
@ -17,4 +17,8 @@
|
|||
policy(%i[settings contact]).index?,
|
||||
settings_contacts_path,
|
||||
],
|
||||
sessions: [
|
||||
policy(%i[settings session]).index?,
|
||||
settings_sessions_path,
|
||||
],
|
||||
) %>
|
||||
|
|
21
app/views/settings/sessions/_table.html.erb
Normal file
21
app/views/settings/sessions/_table.html.erb
Normal file
|
@ -0,0 +1,21 @@
|
|||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">
|
||||
<%= Session.human_attribute_name :logged_at %>
|
||||
</th>
|
||||
<th scope="col">
|
||||
<%= Session.human_attribute_name :ip_address %>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
<% sessions.each do |session| %>
|
||||
<tr>
|
||||
<td><%= localize session.logged_at, format: :long %></td>
|
||||
<td><%= session.ip_address %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
11
app/views/settings/sessions/index.html.erb
Normal file
11
app/views/settings/sessions/index.html.erb
Normal file
|
@ -0,0 +1,11 @@
|
|||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-md-3 mb-4">
|
||||
<%= render partial: 'settings/nav_sidebar', locals: { tab: :sessions } %>
|
||||
</div>
|
||||
|
||||
<div class="col-md-9">
|
||||
<%= render partial: 'table', locals: { sessions: @sessions } %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
|
@ -27,7 +27,10 @@ en:
|
|||
many: Regional offices
|
||||
relationship:
|
||||
one: Party relation
|
||||
one: Party relations
|
||||
many: Party relations
|
||||
session:
|
||||
one: Session
|
||||
many: Sessions
|
||||
user:
|
||||
one: User
|
||||
many: Users
|
||||
|
@ -93,6 +96,11 @@ en:
|
|||
from_date: From date
|
||||
status: Status
|
||||
position: Position
|
||||
session:
|
||||
id: ID
|
||||
account: Account
|
||||
logged_at: Date & time (UTC timezone)
|
||||
ip_address: IP address
|
||||
user:
|
||||
id: ID
|
||||
confirmation_sent_at: Confirmation sent at
|
||||
|
|
|
@ -28,6 +28,9 @@ ru:
|
|||
relationship:
|
||||
one: Отношение с партией
|
||||
one: Отношения с партией
|
||||
session:
|
||||
one: Сессия
|
||||
many: Сессии
|
||||
user:
|
||||
one: Пользователь
|
||||
many: Пользователи
|
||||
|
@ -93,6 +96,11 @@ ru:
|
|||
from_date: Дата начала
|
||||
status: Статус
|
||||
position: Должность
|
||||
session:
|
||||
id: ID
|
||||
account: Аккаунт
|
||||
logged_at: Дата & время (часовой пояс UTC)
|
||||
ip_address: IP-адрес
|
||||
user:
|
||||
id: ID
|
||||
confirmation_sent_at: Дата отправки подтверждения
|
||||
|
|
|
@ -10,3 +10,4 @@ en:
|
|||
profile: Public profile
|
||||
person: Person
|
||||
contacts: Contacts
|
||||
sessions: Sessions
|
||||
|
|
|
@ -10,3 +10,4 @@ ru:
|
|||
profile: Публичный профиль
|
||||
person: Личность
|
||||
contacts: Контакты
|
||||
sessions: Сессии
|
||||
|
|
|
@ -34,6 +34,7 @@ Rails.application.routes.draw do
|
|||
resource :profile, only: %i[edit update]
|
||||
resource :person, only: %i[show new]
|
||||
resources :contacts, only: %i[index create destroy]
|
||||
resources :sessions, only: :index
|
||||
end
|
||||
|
||||
#########################
|
||||
|
|
7
spec/policies/settings/session_policy_spec.rb
Normal file
7
spec/policies/settings/session_policy_spec.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Settings::SessionPolicy do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
27
spec/requests/settings/sessions/index_spec.rb
Normal file
27
spec/requests/settings/sessions/index_spec.rb
Normal file
|
@ -0,0 +1,27 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'GET /settings/sessions' do
|
||||
before do
|
||||
sign_in current_account.user if current_account&.user
|
||||
|
||||
if current_account
|
||||
create_list :some_session, rand(1..3), account: current_account
|
||||
end
|
||||
|
||||
get '/settings/sessions'
|
||||
end
|
||||
|
||||
for_account_types nil do
|
||||
specify do
|
||||
expect(response).to have_http_status :forbidden
|
||||
end
|
||||
end
|
||||
|
||||
for_account_types :usual, :personal, :superuser do
|
||||
specify do
|
||||
expect(response).to have_http_status :ok
|
||||
end
|
||||
end
|
||||
end
|
Reference in a new issue