Skip to content

Commit

Permalink
Pagination and search on conflicts page (decidim#13154)
Browse files Browse the repository at this point in the history
* Included conflicts pagination and search

* Added test

* Lint

* Completed test

* Fixed view and lint

* Improved test

* Lint

* Deleted partials
  • Loading branch information
alexrlpz authored Jul 29, 2024
1 parent 208f44d commit 4b83f83
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# frozen_string_literal: true

require "active_support/concern"

module Decidim
module Admin
module VerificationConflicts
module Filterable
extend ActiveSupport::Concern

included do
include Decidim::Admin::Filterable

private

def base_query
collection
end

def search_field_predicate
:current_user_name_or_current_user_nickname_or_current_user_email_cont
end

def filters
[]
end
end
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,16 @@
module Decidim
module Admin
class ConflictsController < Decidim::Admin::ApplicationController
include Decidim::Admin::VerificationConflicts::Filterable

layout "decidim/admin/users"

helper_method :context_breadcrumb_items
helper_method :context_breadcrumb_items, :conflicts

add_breadcrumb_item_from_menu :impersonate_menu

def index
enforce_permission_to :index, :impersonatable_user

@conflicts = Decidim::Verifications::Conflict.joins(:current_user).where(
decidim_users: { decidim_organization_id: current_organization.id }
)
end

def edit
Expand Down Expand Up @@ -66,6 +64,16 @@ def impersonations_breadcrumb_item
url: decidim_admin.impersonatable_users_path
}
end

def collection
@collection ||= Decidim::Verifications::Conflict.joins(:current_user).where(
decidim_users: { decidim_organization_id: current_organization.id }
)
end

def conflicts
@conflicts ||= filtered_collection.order(created_at: :desc)
end
end
end
end
35 changes: 29 additions & 6 deletions decidim-admin/app/views/decidim/admin/conflicts/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,32 @@
<% add_decidim_page_title(t("title", scope: "decidim.admin.conflicts")) %>
<div class="card">
<div class="item_show__header">
<h1 class="item_show__header-title">
<%= t("title", scope: "decidim.admin.conflicts") %>
</h1>
<div class="item_show__header">
<h1 class="item_show__header-title">
<%= t("title", scope: "decidim.admin.conflicts") %>
</h1>
</div>

<div class="filters__section">
<div class="fcell search">
<%= search_form_for(query, url: url_for) do |form| %>
<%= applied_filters_hidden_field_tags %>
<div class="input-group">
<%= form.search_field(
search_field_predicate,
class: "input-group-field",
label: false,
placeholder: t(".text")
) %>
<div class="input-group-button">
<button type="submit" class="text-secondary" aria-label="<%= t("decidim.search.term_input_placeholder") %>">
<%= icon "search-line", class: "fill-secondary w-4 h-4" %>
</button>
</div>
</div>
<% end %>
</div>
</div>

<div class="card">
<div class="table-scroll">
<table class="table-list">
<thead>
Expand All @@ -17,7 +39,7 @@
</tr>
</thead>
<tbody>
<% @conflicts.each do |conflict| %>
<% conflicts.each do |conflict| %>
<tr>
<td><%= conflict.current_user.name %></td>
<td><%= conflict.managed_user.name %></td>
Expand All @@ -30,3 +52,4 @@
</table>
</div>
</div>
<%= decidim_paginate conflicts %>
2 changes: 2 additions & 0 deletions decidim-admin/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,8 @@ en:
conflicts:
attempts: Attempts
'false': 'No'
index:
text: Search by current user email, name or nickname.
managed_user_name: Managed User
solved: Solved
title: Verification conflicts
Expand Down
58 changes: 58 additions & 0 deletions decidim-admin/spec/system/admin_checks_conflicts_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# frozen_string_literal: true

require "spec_helper"

describe "Admin checks conflicts" do
let(:organization) { create(:organization) }
let(:resource_controller) { Decidim::Admin::ConflictsController }

let!(:user) { create(:user, :admin, :confirmed, organization:) }
let!(:first_conflictive_user) { create(:user, :admin, :confirmed, organization:) }
let!(:second_conflictive_user) { create(:user, :admin, :confirmed, organization:) }

let!(:first_user_conflicts) { create_list(:conflict, 15, current_user: first_conflictive_user) }
let!(:second_user_conflicts) { create_list(:conflict, 15, current_user: second_conflictive_user) }

before do
switch_to_host(organization.host)
login_as user, scope: :user
visit decidim_admin.root_path
click_on "Participants"
click_on "Verification conflicts"
end

include_context "with filterable context"

context "when listing conflicts" do
before { visit current_path }

it_behaves_like "paginating a collection" do
let!(:collection) { create_list(:conflict, 50, current_user: first_conflictive_user) }
end
end

context "when searching by current user name, nickname or email" do
before { visit current_path }

it "can be searched by name" do
search_by_text(first_conflictive_user.name)

expect(page).to have_content(first_conflictive_user.name)
expect(page).to have_no_content(second_conflictive_user.name)
end

it "can be searched by nickname" do
search_by_text(first_conflictive_user.nickname)

expect(page).to have_content(first_conflictive_user.name)
expect(page).to have_no_content(second_conflictive_user.name)
end

it "can be searched by email" do
search_by_text(first_conflictive_user.email)

expect(page).to have_content(first_conflictive_user.name)
expect(page).to have_no_content(second_conflictive_user.name)
end
end
end

0 comments on commit 4b83f83

Please sign in to comment.