Merge branch 'refactored_moderator' into master
This commit is contained in:
@@ -436,6 +436,3 @@ DEPENDENCIES
|
||||
uglifier (>= 1.3.0)
|
||||
unicorn
|
||||
web-console (~> 2.0)
|
||||
|
||||
BUNDLED WITH
|
||||
1.10.6
|
||||
|
||||
33
app/controllers/admin/moderators_controller.rb
Normal file
33
app/controllers/admin/moderators_controller.rb
Normal file
@@ -0,0 +1,33 @@
|
||||
class Admin::ModeratorsController < Admin::BaseController
|
||||
|
||||
load_and_authorize_resource
|
||||
|
||||
def index
|
||||
@moderators = @moderators.page(params[:page])
|
||||
end
|
||||
|
||||
def search
|
||||
@user = User.find_by(email: params[:email])
|
||||
|
||||
respond_to do |format|
|
||||
if @user
|
||||
@moderator = Moderator.find_or_initialize_by(user: @user)
|
||||
format.js
|
||||
else
|
||||
format.js { render "user_not_found" }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@moderator.destroy
|
||||
redirect_to admin_moderators_path
|
||||
end
|
||||
|
||||
def create
|
||||
@moderator.user_id = params[:user_id]
|
||||
@moderator.save
|
||||
|
||||
redirect_to admin_moderators_path
|
||||
end
|
||||
end
|
||||
@@ -90,6 +90,8 @@ class Ability
|
||||
cannot :confirm_hide, User, hidden_at: nil
|
||||
|
||||
can :comment_as_administrator, [Debate, Comment]
|
||||
|
||||
can :manage, Moderator
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -46,7 +46,14 @@
|
||||
<% end %>
|
||||
</li>
|
||||
|
||||
<li <%= "class=active" if controller_name == "settings" %>>
|
||||
<li <%= 'class=active' if controller_name == 'moderators' %>>
|
||||
<%= link_to admin_moderators_path do %>
|
||||
<i class="icon-user"></i>
|
||||
<%= t('admin.menu.moderators') %>
|
||||
<% end %>
|
||||
</li>
|
||||
|
||||
<li <%= 'class=active' if controller_name == 'settings' %>>
|
||||
<%= link_to admin_settings_path do %>
|
||||
<i class="icon-settings"></i>
|
||||
<%= t("admin.menu.settings") %>
|
||||
|
||||
13
app/views/admin/moderators/_moderator.html.erb
Normal file
13
app/views/admin/moderators/_moderator.html.erb
Normal file
@@ -0,0 +1,13 @@
|
||||
<span><%= moderator.name %></span>
|
||||
<span class="bullet"> • </span>
|
||||
<span><%= moderator.email %></span>
|
||||
<% if moderator.persisted? %>
|
||||
<%= link_to t('admin.moderators.moderator.delete'),
|
||||
admin_moderator_path(moderator),
|
||||
method: :delete,
|
||||
class: "button tiny radius alert right"
|
||||
%>
|
||||
<% else %>
|
||||
<%= link_to t('admin.moderators.moderator.add'),{ controller: "admin/moderators", action: :create, user_id: moderator.user_id },
|
||||
method: :post, class: "button tiny radius success right" %>
|
||||
<% end %>
|
||||
24
app/views/admin/moderators/index.html.erb
Normal file
24
app/views/admin/moderators/index.html.erb
Normal file
@@ -0,0 +1,24 @@
|
||||
<h2><%= t("admin.moderators.index.title") %></h2>
|
||||
<div class="row">
|
||||
<div class="column">
|
||||
<%= form_tag search_admin_moderators_path, method: :get, remote: true do %>
|
||||
<div class="small-12 medium-6 column">
|
||||
<%= text_field_tag :email, '', placeholder: t('admin.moderators.search.email_placeholder') %>
|
||||
</div>
|
||||
<div class="small-12 medium-6 column">
|
||||
<%= submit_tag t('admin.moderators.search.search'), class: 'button radius' %>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
<div id="search-result" class="row small"></div>
|
||||
<h3><%= page_entries_info @moderators %></h3>
|
||||
<ul class="admin-list">
|
||||
<% @moderators.each do |moderator| %>
|
||||
<li>
|
||||
<%= render 'moderator', moderator: moderator %>
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
||||
|
||||
<%= paginate @moderators %>
|
||||
1
app/views/admin/moderators/search.js.erb
Normal file
1
app/views/admin/moderators/search.js.erb
Normal file
@@ -0,0 +1 @@
|
||||
$("#search-result").html("<div class=\"panel column\"><%= j render 'moderator', moderator: @moderator %></div>");
|
||||
1
app/views/admin/moderators/user_not_found.js.erb
Normal file
1
app/views/admin/moderators/user_not_found.js.erb
Normal file
@@ -0,0 +1 @@
|
||||
$("#search-result").html("<div class=\"panel column\"><%= j t('admin.moderators.search.user_not_found') %></div>");
|
||||
@@ -16,6 +16,7 @@ en:
|
||||
hidden_users: Hidden users
|
||||
organizations: Organizations
|
||||
officials: Officials
|
||||
moderators: Moderators
|
||||
stats: Statistics
|
||||
organizations:
|
||||
index:
|
||||
@@ -95,3 +96,14 @@ en:
|
||||
flash:
|
||||
official_updated: 'Official position saved!'
|
||||
official_destroyed: 'User is not an official anymore'
|
||||
moderators:
|
||||
index:
|
||||
title: Moderators
|
||||
search:
|
||||
email_placeholder: 'Search user by email'
|
||||
search: Search
|
||||
user_not_found: 'User not found'
|
||||
moderator:
|
||||
delete: Delete
|
||||
add: Add
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ es:
|
||||
hidden_users: Usuarios ocultos
|
||||
organizations: Organizaciones
|
||||
officials: Cargos públicos
|
||||
moderators: Moderadores
|
||||
stats: Estadísticas
|
||||
organizations:
|
||||
index:
|
||||
@@ -95,3 +96,13 @@ es:
|
||||
flash:
|
||||
official_updated: 'Datos del cargo público guardados'
|
||||
official_destroyed: 'Datos guardados: el usuario ya no es cargo público'
|
||||
moderators:
|
||||
index:
|
||||
title: Moderadores
|
||||
search:
|
||||
email_placeholder: 'Buscar usuario por email'
|
||||
search: Buscar
|
||||
user_not_found: 'Usuario no encontrado'
|
||||
moderator:
|
||||
delete: Borrar
|
||||
add: Añadir
|
||||
|
||||
@@ -87,6 +87,9 @@ Rails.application.routes.draw do
|
||||
end
|
||||
|
||||
resources :settings, only: [:index, :update]
|
||||
resources :moderators, only: [:index, :create, :destroy] do
|
||||
collection { get :search }
|
||||
end
|
||||
end
|
||||
|
||||
namespace :moderation do
|
||||
|
||||
36
spec/features/admin/moderators_spec.rb
Normal file
36
spec/features/admin/moderators_spec.rb
Normal file
@@ -0,0 +1,36 @@
|
||||
require 'rails_helper'
|
||||
|
||||
feature 'Admin moderators' do
|
||||
background do
|
||||
@user = create(:user, username: 'Jose Luis Balbin')
|
||||
@moderator = create(:moderator)
|
||||
@admin = create(:administrator)
|
||||
login_as(@admin.user)
|
||||
end
|
||||
|
||||
scenario 'Index' do
|
||||
visit admin_moderators_path
|
||||
expect(page).to have_content @moderator.name
|
||||
expect(page).to have_content @moderator.email
|
||||
expect(page).to_not have_content @user.name
|
||||
end
|
||||
|
||||
scenario 'Create Moderator', :js do
|
||||
visit admin_moderators_path
|
||||
fill_in 'email', with: @user.email
|
||||
click_button 'Search'
|
||||
|
||||
expect(page).to have_content @user.name
|
||||
click_link 'Add'
|
||||
|
||||
expect(page).to have_content @user.name
|
||||
end
|
||||
|
||||
scenario 'Delete Moderator' do
|
||||
visit admin_moderators_path
|
||||
click_link 'Delete'
|
||||
|
||||
expect(page).to_not have_content @moderator.name
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user