Adds moderators config to admin console
This commit is contained in:
@@ -378,6 +378,3 @@ DEPENDENCIES
|
||||
uglifier (>= 1.3.0)
|
||||
unicorn
|
||||
web-console (~> 2.0)
|
||||
|
||||
BUNDLED WITH
|
||||
1.10.6
|
||||
|
||||
18
app/controllers/admin/moderators_controller.rb
Normal file
18
app/controllers/admin/moderators_controller.rb
Normal file
@@ -0,0 +1,18 @@
|
||||
class Admin::ModeratorsController < Admin::BaseController
|
||||
def index
|
||||
@moderators = User.joins(:moderator).page(params[:page])
|
||||
end
|
||||
def search
|
||||
@email = params[:email]
|
||||
@user = User.find_by(email: @email)
|
||||
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
def toggle
|
||||
@user = User.find(params[:id])
|
||||
@user.toggle_moderator
|
||||
redirect_to admin_moderators_path
|
||||
end
|
||||
end
|
||||
@@ -70,6 +70,10 @@ class User < ActiveRecord::Base
|
||||
e.present? ? where(email: e) : none
|
||||
end
|
||||
|
||||
def toggle_moderator
|
||||
moderator? ? self.moderator.destroy : create_moderator
|
||||
end
|
||||
|
||||
private
|
||||
def use_first_name?
|
||||
!organization? && !use_nickname?
|
||||
|
||||
@@ -46,6 +46,13 @@
|
||||
<% end %>
|
||||
</li>
|
||||
|
||||
<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>
|
||||
|
||||
18
app/views/admin/moderators/_moderator.html.erb
Normal file
18
app/views/admin/moderators/_moderator.html.erb
Normal file
@@ -0,0 +1,18 @@
|
||||
<% if moderator %>
|
||||
<span><%= moderator.name %></span>
|
||||
<span class="bullet"> • </span>
|
||||
<span><%= moderator.email %></span>
|
||||
<% if moderator.moderator? %>
|
||||
<%= link_to t('admin.moderators.moderator.delete'),
|
||||
toggle_admin_moderator_path(moderator),
|
||||
method: :post,
|
||||
class: "button tiny radius alert right" %>
|
||||
<% else %>
|
||||
<%= link_to t('admin.moderators.moderator.add'),
|
||||
toggle_admin_moderator_path(moderator),
|
||||
method: :post,
|
||||
class: "button tiny radius success right" %>
|
||||
<% end %>
|
||||
<% else%>
|
||||
<span><%= t('admin.moderators.search.user_not_found') %></span>
|
||||
<% end %>
|
||||
25
app/views/admin/moderators/index.html.erb
Normal file
25
app/views/admin/moderators/index.html.erb
Normal file
@@ -0,0 +1,25 @@
|
||||
<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="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\"><%= j render 'moderator', moderator: @user %></div>");
|
||||
@@ -16,6 +16,7 @@ en:
|
||||
hidden_users: Hidden users
|
||||
organizations: Organizations
|
||||
officials: Officials
|
||||
moderators: Moderators
|
||||
stats: Statistics
|
||||
organizations:
|
||||
index:
|
||||
@@ -91,3 +92,10 @@ 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'
|
||||
|
||||
@@ -16,6 +16,7 @@ es:
|
||||
hidden_users: Usuarios ocultos
|
||||
organizations: Organizaciones
|
||||
officials: Cargos públicos
|
||||
moderators: Moderadores
|
||||
stats: Estadísticas
|
||||
organizations:
|
||||
index:
|
||||
@@ -91,3 +92,10 @@ 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'
|
||||
|
||||
@@ -54,6 +54,10 @@ Rails.application.routes.draw do
|
||||
end
|
||||
|
||||
resources :settings, only: [:index, :update]
|
||||
resources :moderators, only: [:index] do
|
||||
member { post :toggle }
|
||||
collection { get :search }
|
||||
end
|
||||
end
|
||||
|
||||
namespace :moderation do
|
||||
|
||||
15
spec/features/admin/moderators_spec.rb
Normal file
15
spec/features/admin/moderators_spec.rb
Normal file
@@ -0,0 +1,15 @@
|
||||
require 'rails_helper'
|
||||
|
||||
feature 'Admin moderators' do
|
||||
background do
|
||||
@user = create(:user)
|
||||
@moderator = create(:moderator)
|
||||
@admin = create(:administrator)
|
||||
login_as(@admin)
|
||||
end
|
||||
|
||||
scenario 'Index' do
|
||||
visit admin_moderators_path
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user