Skip to content
Snippets Groups Projects
Commit fc28b9bb authored by Mateus Rambo Strey's avatar Mateus Rambo Strey
Browse files

Merge branch 'suspend-object' into 'master'

Suspend object



See merge request !174
parents 2488a50b 0eb80e49
No related branches found
No related tags found
No related merge requests found
Showing
with 221 additions and 19 deletions
...@@ -24,6 +24,13 @@ $checked_icon: 'icons/checked.png'; ...@@ -24,6 +24,13 @@ $checked_icon: 'icons/checked.png';
padding: 2px; padding: 2px;
} }
.learning-object-icon-suspended {
color: red;
top: calc(50% - 41px) ;
left: calc(50% - 31px) ;
position: absolute;
}
.learning-object-actions { .learning-object-actions {
position: absolute; position: absolute;
bottom: 10px; bottom: 10px;
......
...@@ -2,16 +2,21 @@ require 'uri' ...@@ -2,16 +2,21 @@ require 'uri'
class LearningObjectsController < ApplicationController class LearningObjectsController < ApplicationController
include Reportable include Reportable
include Pundit
rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized
before_action :authenticate_user!, except: [:index, :show] before_action :authenticate_user!, except: [:index, :show]
before_action :set_learning_object, only: [:show, :edit, :update, before_action :set_learning_object, only: [:show, :edit, :update,
:destroy, :like, :bookmarks, :destroy, :like, :bookmarks,
:collections, :upload, :upload_link, :download] :collections, :upload, :upload_link, :download,
:user_not_authorized]
after_action :increment_learning_object_views, only: [:show] after_action :increment_learning_object_views, only: [:show]
# GET /learning_objects/1 # GET /learning_objects/1
# GET /learning_objects/1.json # GET /learning_objects/1.json
def show def show
authorize @learning_object
@liked = !@learning_object.liked?(current_user) if user_signed_in? @liked = !@learning_object.liked?(current_user) if user_signed_in?
@reviews = Review.where(reviewable: @learning_object) @reviews = Review.where(reviewable: @learning_object)
end end
...@@ -74,7 +79,7 @@ class LearningObjectsController < ApplicationController ...@@ -74,7 +79,7 @@ class LearningObjectsController < ApplicationController
def like def like
if @learning_object.liked? current_user if @learning_object.liked? current_user
@learning_object.dislike current_user @learning_object.dislike current_user
elseg else
@learning_object.like current_user @learning_object.like current_user
end end
...@@ -128,4 +133,13 @@ class LearningObjectsController < ApplicationController ...@@ -128,4 +133,13 @@ class LearningObjectsController < ApplicationController
redirect_to upload_learning_object_path(id: id), notice: 'Seu objeto foi criado! Para que ele seja publicado é necessário enviar o arquivo.' redirect_to upload_learning_object_path(id: id), notice: 'Seu objeto foi criado! Para que ele seja publicado é necessário enviar o arquivo.'
end end
end end
private
def user_not_authorized
flash[:notice] = "Este objeto está suspenso!"
flash[:alert] = "Razões: #{Complaint.where(complaintable_id: @learning_object.id).map(&:reason).join(',').to_s}"
redirect_to (root_path)
end
end end
...@@ -27,13 +27,21 @@ class Management::ComplaintsController < ManagementController ...@@ -27,13 +27,21 @@ class Management::ComplaintsController < ManagementController
end end
def suspend_object def suspend_object
@learning_object = LearningObject.find (params[:object_id]) @learning_object = LearningObject.find params[:object_id]
@learning_object.update(state: 'suspended') @learning_object.update(state: 'suspended')
respond_to do |format| respond_to do |format|
format.html { redirect_to :back, notice: 'Objeto suspenso com sucesso.' } format.html { redirect_to :back, notice: 'Objeto suspenso com sucesso.' }
end end
end
def publish_object
@learning_object = LearningObject.find params[:object_id]
@learning_object.update(state: 'published')
respond_to do |format|
format.html { redirect_to :back, notice: 'Objeto publicado com sucesso.' }
end
end end
def destroy def destroy
......
class Management::LearningObjectsController < ManagementController
def index
@learning_objects = LearningObject.includes(:object_type).where(state: 'suspended')
end
end
class SearchController < ApplicationController class SearchController < ApplicationController
include LearningObjectsHelper include LearningObjectsHelper
include Pundit
def index def index
@types = ObjectType.all.map(&:name) @types = ObjectType.all.map(&:name)
...@@ -13,6 +14,7 @@ class SearchController < ApplicationController ...@@ -13,6 +14,7 @@ class SearchController < ApplicationController
end end
def fetch def fetch
params[:query] = "*" if params[:query].blank? params[:query] = "*" if params[:query].blank?
case params[:search_class] case params[:search_class]
...@@ -53,7 +55,7 @@ class SearchController < ApplicationController ...@@ -53,7 +55,7 @@ class SearchController < ApplicationController
def autocomplete_search(search_class, params_hash={}, get_thumbnail) def autocomplete_search(search_class, params_hash={}, get_thumbnail)
response = [] response = []
search_params = { limit: 10, misspellings: { below: 5 } } search_params = { limit: 10, misspellings: { below: 5 }, where: {state: validate_object} }
objs = search_class.search(params[:query], search_params.merge(params_hash)) objs = search_class.search(params[:query], search_params.merge(params_hash))
objs.each do |obj| objs.each do |obj|
hash = {} hash = {}
...@@ -80,6 +82,7 @@ class SearchController < ApplicationController ...@@ -80,6 +82,7 @@ class SearchController < ApplicationController
hash[:topics_name] = topics.split(', ') unless topics.nil? hash[:topics_name] = topics.split(', ') unless topics.nil?
hash[:object_type] = params[:type].split(', ') unless params[:type].blank? hash[:object_type] = params[:type].split(', ') unless params[:type].blank?
hash[:publisher] = params[:source].split("-s- ") unless params[:source].blank? hash[:publisher] = params[:source].split("-s- ") unless params[:source].blank?
hash[:state] = validate_object
# year = params[:year].blank? ? nil : params[:year].split('-').take(2) # year = params[:year].blank? ? nil : params[:year].split('-').take(2)
hash.blank? ? nil : hash hash.blank? ? nil : hash
...@@ -120,4 +123,11 @@ class SearchController < ApplicationController ...@@ -120,4 +123,11 @@ class SearchController < ApplicationController
{ name: {order: :asc, unmapped_type: :string} } { name: {order: :asc, unmapped_type: :string} }
end end
private
def validate_object
return 'published' if current_user.nil? || !current_user.is_admin?
return ['published', 'suspended', 'draft']
end
end end
class WelcomeController < ApplicationController class WelcomeController < ApplicationController
include Pundit
def index def index
@carousel = Carousel.all || [] @carousel = Carousel.all || []
@highlights = policy_scope(LearningObject).limit(8)
@highlights = LearningObject.limit(8)
end end
def faq def faq
......
...@@ -36,8 +36,9 @@ class LearningObject < ActiveRecord::Base ...@@ -36,8 +36,9 @@ class LearningObject < ActiveRecord::Base
object_type: type, object_type: type,
score: score, score: score,
published_at: published_at, published_at: published_at,
topics_name: topics.map(&:name),
source: source, source: source,
topics_name: topics.map(&:name) state: state
} }
end end
......
class ApplicationPolicy
attr_reader :user, :record
def initialize(user, record)
@user = user
@record = record
end
def index?
false
end
def show?
scope.where(:id => record.id).exists?
end
def create?
false
end
def new?
create?
end
def update?
false
end
def edit?
update?
end
def destroy?
false
end
def scope
Pundit.policy_scope!(user, record.class)
end
class Scope
attr_reader :user, :scope
def initialize(user, scope)
@user = user
@scope = scope
end
def resolve
scope
end
end
end
class LearningObjectPolicy < ApplicationPolicy
class Scope < Scope
def resolve
if user.nil?
scope.where(state: 'published')
elsif user.is_admin?
scope.all
else
scope.where(state: 'published')
end
end
end
def show?
if user.nil?
record.state == 'published'
elsif user.is_admin?
record
else
record.state == 'published'
end
end
end
class SearchPolicy < ApplicationPolicy
class Scope < Scope
def resolve
if user.nil?
scope.where(state: 'published')
elsif user.is_admin?
scope.all
else
scope.where(state: 'published')
end
end
end
end
class WelcomePolicy < ApplicationPolicy
class Scope < Scope
def resolve
if user.is_admin?
scope.all
else
scope.where(state: 'published')
end
end
end
end
...@@ -7,6 +7,12 @@ ...@@ -7,6 +7,12 @@
image_tag learning_object_thumbnail(learning_object), alt: learning_object_title(learning_object), class: "thumbnail" image_tag learning_object_thumbnail(learning_object), alt: learning_object_title(learning_object), class: "thumbnail"
end %> end %>
<% if learning_object.state == 'suspended' %>
<div class="learning-object-icon-suspended">
<i class="fa fa-times fa-5x fa-lg" ></i>
</div>
<% end %>
<% if user_signed_in? %> <% if user_signed_in? %>
<%= render 'learning_objects/actions_buttons', learning_object: learning_object %> <%= render 'learning_objects/actions_buttons', learning_object: learning_object %>
<% end %> <% end %>
......
...@@ -4,6 +4,9 @@ ...@@ -4,6 +4,9 @@
<%= link_to learning_object_path(id: learning_object.id) do <%= link_to learning_object_path(id: learning_object.id) do
image_tag learning_object_thumbnail(learning_object), alt: learning_object_title(learning_object), class: "thumbnail" image_tag learning_object_thumbnail(learning_object), alt: learning_object_title(learning_object), class: "thumbnail"
end %> end %>
<% if learning_object.state == 'suspended' %>
<i class="fa fa-times fa-5x fa-lg learning-object-icon-suspended" ></i>
<% end %>
<% if user_signed_in? %> <% if user_signed_in? %>
<%= render 'learning_objects/actions_buttons', learning_object: learning_object %> <%= render 'learning_objects/actions_buttons', learning_object: learning_object %>
<% end %> <% end %>
......
<% content_for(:body_attributes) do %>data-no-turbolink="true"<% end %> <% content_for(:body_attributes) do %>data-no-turbolink="true"<% end %>
<% if @learning_object.state == 'suspended' %>
<h2> Este conteúdo está suspenso! </h2>
<% end %>
<div class="row learning-object"> <div class="row learning-object">
<div class="col-md-7"> <div class="col-md-7">
<div class="view"> <div class="view">
...@@ -10,7 +15,7 @@ ...@@ -10,7 +15,7 @@
</div> </div>
<br/><br/> <br/><br/>
<h2 class="title"><%= @learning_object.name %></h2> <h2 class="title"><%= learning_object_title(@learning_object) %></h2>
<% unless @learning_object.description.nil? %> <% unless @learning_object.description.nil? %>
<p class="description"><%= @learning_object.description %></p> <p class="description"><%= @learning_object.description %></p>
<% end %> <% end %>
......
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
<div class="row"> <div class="row">
<div class="col-md-6 col-sm-6"><p>Número de vezes que os usuários marcaram objetos educacionais como spam.</p></div> <div class="col-md-6 col-sm-6"><p>Número de vezes que os usuários marcaram objetos educacionais como spam.</p></div>
<div class="col-md-6 col-sm-6"> <div class="col-md-6 col-sm-6">
<p class="ls-float-right ls-float-none-xs">Período selecionado: <strong><%= @date_limit %></strong></p></div> <p class="ls-float-right ls-float-none-xs">Período selecionado: <strong><%= @date %></strong></p></div>
</div> </div>
<div class="ls-clearfix"></div> <div class="ls-clearfix"></div>
...@@ -103,13 +103,17 @@ ...@@ -103,13 +103,17 @@
<a href="#" class="ls-btn-primary" aria-expanded="false" role="combobox">Administrar</a> <a href="#" class="ls-btn-primary" aria-expanded="false" role="combobox">Administrar</a>
<ul class="ls-dropdown-nav" aria-hidden="true"> <ul class="ls-dropdown-nav" aria-hidden="true">
<li> <li>
<% if complaint.complaintable.state == "published" %>
<%= link_to 'Suspender Objeto', management_complaint_suspend_object_path(complaint_id: complaint.id, object_id: complaint.complaintable_id), {method: :post, data: {confirm: 'Tem certeza que deseja suspender este objeto?'}, title: 'Suspender Objeto', class: 'ls-btn ls-btn-sm', role: 'option'} %> <%= link_to 'Suspender Objeto', management_complaint_suspend_object_path(complaint_id: complaint.id, object_id: complaint.complaintable_id), {method: :post, data: {confirm: 'Tem certeza que deseja suspender este objeto?'}, title: 'Suspender Objeto', class: 'ls-btn ls-btn-sm', role: 'option'} %>
<% else %>
<%= link_to 'Publicar Objeto', management_complaint_publish_object_path(complaint_id: complaint.id, object_id: complaint.complaintable_id), {method: :post, data: {confirm: 'Tem certeza que deseja publicar este objeto?'}, title: 'Suspender Objeto', class: 'ls-btn ls-btn-sm', role: 'option'} %>
<% end %>
</li> </li>
<li>
<% @complaints.select{ |x| x.complaintable.name == complaint.complaintable.name }.each do |complaint_ignore| %> <% @complaints.select{ |x| x.complaintable.name == complaint.complaintable.name }.each do |complaint_ignore| %>
<%= link_to 'Ignorar denúncia', management_complaint_path(id: complaint_ignore.id), {method: :delete, data: {confirm: 'Tem certeza que deseja ignorar esta denúncia?'}, title: 'Ignorar denúncia', class: 'ls-btn ls-btn-sm', role: 'option'} %> <li>
<% end %> <%= link_to "Ignorar denúncia de #{User.find(complaint_ignore.user_id).name}", management_complaint_path(id: complaint_ignore.id), {method: :delete, data: {confirm: 'Tem certeza que deseja ignorar esta denúncia?'}, title: 'Ignorar denúncia', class: 'ls-btn ls-btn-sm', role: 'option'} %>
</li> </li>
<% end %>
</ul> </ul>
</div> </div>
</div> </div>
......
<h1 class="ls-title-intro ls-ico-bullhorn">Conteúdos Suspensos</h1>
<div class="ls-clearfix"></div>
<div class="ls-board-box">
<div id="sending-stats" class="row ls-box-group">
<div class="col-sm-12 col-lg-7">
<div class="ls-box">
<div class="ls-box-head">
<h6 class="ls-title-4">Total de conteúdos suspensos</h6>
</div>
<div class="ls-box-body">
<strong class="ls-color-theme"><%= @learning_objects.size %></strong>
</div>
</div>
</div>
</div>
<% @learning_objects.sort{|x,y| x.name <=> y.name}.each do |learning_object| %>
<div class="ls-list">
<header class="ls-list-header">
<div class="ls-list-title col-md-9">
<%= link_to "#{learning_object.name}", learning_object_path(id: learning_object.id) %></a>
<small><%= learning_object.description %> </small>
</div>
<div class="col-md-3 ls-txt-right">
<%= link_to 'Publicar Objeto', management_complaint_publish_object_path(complaint_id: Complaint.where(complaintable_id: learning_object.id).first, object_id: learning_object.id), {method: :post, data: {confirm: 'Tem certeza que deseja publicar este objeto?'}, title: 'Suspender Objeto', class: 'ls-btn-primary ls-btn-sm', role: 'option'} %>
</div>
</header>
</div>
<% end %>
</div>
...@@ -29,9 +29,9 @@ ...@@ -29,9 +29,9 @@
<ul role="menu"> <ul role="menu">
<li><%= link_to "Denúncias", management_complaints_path, class: 'ls-submenu-item' %> <li><%= link_to "Denúncias", management_complaints_path, class: 'ls-submenu-item' %>
<li><%= link_to "Razões", management_complaint_reasons_path, class: 'ls-submenu-item' %> <li><%= link_to "Razões", management_complaint_reasons_path, class: 'ls-submenu-item' %>
<li><%= link_to "Conteúdos suspensos", management_learning_objects_path, class: 'ls-submenu-item' %>
</ul> </ul>
</li> </li>
<li> <%= link_to "Score", management_scores_path, class: 'ls-ico-bars' %> </li> <li> <%= link_to "Score", management_scores_path, class: 'ls-ico-bars' %> </li>
<li> <%= link_to "Voltar ao Portal", root_path, class: 'ls-ico-chevron-left' %> </li> <li> <%= link_to "Voltar ao Portal", root_path, class: 'ls-ico-chevron-left' %> </li>
</ul> </ul>
......
...@@ -11,6 +11,7 @@ Rails.application.routes.draw do ...@@ -11,6 +11,7 @@ Rails.application.routes.draw do
root 'welcome#index' root 'welcome#index'
resources :complaints do resources :complaints do
post '/suspend_object/:object_id', as: :suspend_object, action: :suspend_object post '/suspend_object/:object_id', as: :suspend_object, action: :suspend_object
post '/publish_object/:object_id', as: :publish_object, action: :publish_object
end end
resources :institutions do resources :institutions do
member do member do
...@@ -22,6 +23,7 @@ Rails.application.routes.draw do ...@@ -22,6 +23,7 @@ Rails.application.routes.draw do
resources :complaint_reasons resources :complaint_reasons
resources :highlights resources :highlights
resources :carousels resources :carousels
resources :learning_objects, only: [:index]
resources :scores, :score_user_categories, :user_categories resources :scores, :score_user_categories, :user_categories
resources :statistics do resources :statistics do
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment