Commit 8417a876 authored by Israel Barreto Sant'Anna's avatar Israel Barreto Sant'Anna

Merge branch 'master' into issue/357

parents cb17ae53 f547a217
......@@ -51,7 +51,7 @@ module Paginator
if(model.columns_hash[key].type == :integer)
model = model.where("#{key}": value)
else
model = model.where("#{key} ILIKE ?", "%#{value}%")
model = model.where("#{key} ILIKE '%'|| ? || '%'", value)
end
end
end
......
......@@ -33,26 +33,36 @@ class V1::FeedController < ApplicationController
private
def activities_followed
query = "privacy = 'public' and ("
query = ""
values = [""]
# builds a query string to find all relevant activities
current_user.watching.each do |watching|
if !watching.respond_to?(:state) || watching.state == "published"
# Activities that are made by, owned by, or change the object you follow should be found
query += " (trackable_type = ? and trackable_id = ?) or (owner_type = ? and owner_id = ?) or (recipient_type = ? and recipient_id = ?) or"
3.times do
if (watching.class == Submission || watching.class == CuratorAssignment)
query += " ((trackable_type = ? and trackable_id = ?) and (owner_type = 'User' and owner_id = #{current_user.id})"
values << watching.class.to_s
values << watching.id
if watching.class == CuratorAssignment
query += " and (parameters is null or parameters not like '%ignored%')"
end
query += ")"
else
query += " (((trackable_type = ? and trackable_id = ?) or (owner_type = ? and owner_id = ?) or (recipient_type = ? and recipient_id = ?)) and (owner_type <> 'User' or (owner_type = 'User' and owner_id <> #{current_user.id})) and privacy = 'public')"
3.times do
values << watching.class.to_s
values << watching.id
end
end
query += " or"
# Activities that are made by, owned by, or change the object you follow should be found
end
end
if query[-1] == "("
query = query[0..-6]
else
values[0] = query[0..-3]+")" # remove trailing "or" on the query
if query[-1] == "r"
values[0] = query[0..-3] # remove trailing "or" on the query
end
return [] if query.blank?
return PublicActivity::Activity.where(key: activities_filter).where(values).order(created_at: :desc)
end
......
......@@ -28,8 +28,6 @@ module Trackable
after_update :new_update_activity
end
private
def new_update_activity
return nil if changed.blank?
return new_activity(:update) if ignore_changes == %w(updated_at)
......
......@@ -30,7 +30,7 @@
class CuratorAssignment < ApplicationRecord
include Trackable
enum status: [:assigned, :answered, :ignored]
belongs_to :submission
......@@ -38,11 +38,19 @@ class CuratorAssignment < ApplicationRecord
validates :submission, :user, presence: true
after_update :update_activities
def update_activities
if status_changed? && self.ignored?
PublicActivity::Activity.where(trackable: self).update(parameters: { status: status })
end
end
def activity_privacy
'private'
end
def activity_recipient
submission
submission.learning_object
end
end
......@@ -84,7 +84,7 @@ class LearningObject < ApplicationRecord
validates :id_dspace, presence: true, uniqueness: true, unless: :published?
before_destroy :delete_index
validates :terms_of_service, acceptance: true, unless: :draft?
default_scope { includes(:object_type, :attachment, :attachments) }
......@@ -135,7 +135,7 @@ class LearningObject < ApplicationRecord
end
def delete_index
LearningObject.searchkick_index.remove(self)
LearningObject.searchkick_index.remove(self)
end
def categories
......@@ -230,4 +230,8 @@ class LearningObject < ApplicationRecord
def complaint_reject(params)
self.published!
end
def activity_owner
proc { |controller, model| model.try(:publisher) || controller.try(:current_user) }
end
end
......@@ -59,7 +59,7 @@ class Submission < ApplicationRecord
status = answers.all? { |a| a.accepted? } ? :accepted : :rejected
self.update_columns(status: status, answered_at: Time.current)
new_activity(:update, {status: self.status})
new_activity(self.status)
end
end
......
......@@ -139,7 +139,7 @@ class User < ApplicationRecord
end
def delete_index
User.searchkick_index.remove(self)
User.searchkick_index.remove(self)
end
def is_admin?
......@@ -294,7 +294,7 @@ class User < ApplicationRecord
# ~~~~ end followable actions ~~~~ #
def default_role
roles << Role.teacher
roles << Role.submitter
end
def self.from_omniauth(access_token)
......@@ -357,7 +357,7 @@ class User < ApplicationRecord
if option == "blocked"
self.suspended_at = Time.current
self.reactivated_at = self.suspended_at + 7.day
self.increment(:times_blocked, 1)
self.increment(:times_blocked, 1)
self.blocked!
elsif option == "banished"
self.suspended_at = Time.current
......
......@@ -20,6 +20,18 @@
class SubmissionSerializer < ActiveModel::Serializer
cache key: 'submission', expires_in: 4.hours, except: [:status]
def curator
object.curator if is_curator?
end
def curator_assignments
object.curator_assignments if is_curator?
end
def is_curator?
!current_user.nil? && current_user != object.submitter && current_user.is_curator?
end
attributes :id, :status, :justification, :answered_at, :created_at
belongs_to :submitter
......
......@@ -21,9 +21,10 @@ module ActivitiesFilterService
def activities_filtered
if !self.try(:draft?)
acts = self.activities.where(key: activities_filter)
ret = acts.select { |a| a.trackable != nil || a.key =~ /.\.destroy/ }
ret
acts = self.activities.where(key: activities_filter).where.not(trackable: nil).where("key not like '%.destroy'")
# ret = acts.select { |a| a.trackable != nil || a.key =~ /.\.destroy/ }
# ret
acts
else
[]
end
......@@ -33,8 +34,8 @@ module ActivitiesFilterService
[ 'complaint.create',
'collection.create', 'collection.update', 'collection.destroy',
'collection_item.create', 'collection_item.update', 'collection_item.destroy',
'learning_object.create', 'learning_object.destroy',
'submission.update',
'learning_object.publish', 'learning_object.destroy',
'submission.accepted', 'submission.rejected',
'curator_assignment.create',
'review.create',
'download.create',
......
......@@ -57,6 +57,7 @@ class LearningObjectPublisher
end
# ThumbnailGenerateWorker.perform_async learning_object.id, learning_object.link if learning_object.link?
learning_object.save
learning_object.new_activity(:publish)
end
def update_dspace(object)
......
......@@ -58,7 +58,9 @@ module SearchService
when 'likes' then { likes: { order: :desc } }
when 'downloads' then { downloads: { order: :desc } }
when 'review_average' then { review_average: { order: :desc } }
else "_score"
else
{ score: {order: :desc} } if @search.query == '*'
"_score"
end
end
......
......@@ -66,7 +66,9 @@ module SearchService
when 'likes' then { likes: { order: :desc } }
when 'downloads' then { downloads: { order: :desc } }
when 'review_average' then { review_average: { order: :desc } }
else "_score"
else
{ score: {order: :desc} } if @search.query == '*'
"_score"
end
end
......
......@@ -39,6 +39,7 @@ module SearchService
def order_hash
return { name: { order: :asc, unmapped_type: :string } } if @search.order == 'title'
{ score: {order: :desc} } if @search.query == '*'
"_score"
end
end
......
# Copyright (C) 2015 Centro de Computacao Cientifica e Software Livre
# Departamento de Informatica - Universidade Federal do Parana
#
# This file is part of portalmec.
#
# portalmec is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# portalmec is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with portalmec. If not, see <http://www.gnu.org/licenses/>.
class AddStatusToComplaintReasons < ActiveRecord::Migration[5.0]
def change
add_column :complaint_reasons, :status, :integer, default: 0
......
# Copyright (C) 2015 Centro de Computacao Cientifica e Software Livre
# Departamento de Informatica - Universidade Federal do Parana
#
# This file is part of portalmec.
#
# portalmec is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# portalmec is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with portalmec. If not, see <http://www.gnu.org/licenses/>.
class AddStateAndSuspendedAtAndReactivatedAToUser < ActiveRecord::Migration[5.0]
def change
add_column :users, :state, :integer, default: 0
......
# Copyright (C) 2015 Centro de Computacao Cientifica e Software Livre
# Departamento de Informatica - Universidade Federal do Parana
#
# This file is part of portalmec.
#
# portalmec is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# portalmec is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with portalmec. If not, see <http://www.gnu.org/licenses/>.
class CreateJoinTableSearchSubject < ActiveRecord::Migration[5.0]
def change
create_join_table :searches, :subjects do |t|
......
# Copyright (C) 2015 Centro de Computacao Cientifica e Software Livre
# Departamento de Informatica - Universidade Federal do Parana
#
# This file is part of portalmec.
#
# portalmec is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# portalmec is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with portalmec. If not, see <http://www.gnu.org/licenses/>.
class CreateJoinTableEducationalStageSearch < ActiveRecord::Migration[5.0]
def change
create_join_table :educational_stages, :searches do |t|
......
# Copyright (C) 2015 Centro de Computacao Cientifica e Software Livre
# Departamento de Informatica - Universidade Federal do Parana
#
# This file is part of portalmec.
#
# portalmec is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# portalmec is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with portalmec. If not, see <http://www.gnu.org/licenses/>.
class CreateJoinTableObjectTypeSearch < ActiveRecord::Migration[5.0]
def change
create_join_table :object_types, :searches do |t|
......
# Copyright (C) 2015 Centro de Computacao Cientifica e Software Livre
# Departamento de Informatica - Universidade Federal do Parana
#
# This file is part of portalmec.
#
# portalmec is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# portalmec is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with portalmec. If not, see <http://www.gnu.org/licenses/>.
class CreateJoinTableSearchTag < ActiveRecord::Migration[5.0]
def change
create_join_table :searches, :tags do |t|
......
# Copyright (C) 2015 Centro de Computacao Cientifica e Software Livre
# Departamento de Informatica - Universidade Federal do Parana
#
# This file is part of portalmec.
#
# portalmec is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# portalmec is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with portalmec. If not, see <http://www.gnu.org/licenses/>.
class CreateJoinTableLanguageLearningObject < ActiveRecord::Migration[5.0]
def change
create_join_table :languages, :learning_objects do |t|
......
# Copyright (C) 2015 Centro de Computacao Cientifica e Software Livre
# Departamento de Informatica - Universidade Federal do Parana
#
# This file is part of portalmec.
#
# portalmec is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# portalmec is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with portalmec. If not, see <http://www.gnu.org/licenses/>.
class AddTimesBlockedToUser < ActiveRecord::Migration[5.0]
def change
add_column :users, :times_blocked, :integer, default: 0
......
# Copyright (C) 2015 Centro de Computacao Cientifica e Software Livre
# Departamento de Informatica - Universidade Federal do Parana
#
# This file is part of portalmec.
#
# portalmec is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# portalmec is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with portalmec. If not, see <http://www.gnu.org/licenses/>.
class CreateJoinTableLanguagesSearches < ActiveRecord::Migration[5.0]
def change
create_join_table :languages, :searches do |t|
......
# Copyright (C) 2015 Centro de Computacao Cientifica e Software Livre
# Departamento de Informatica - Universidade Federal do Parana
#
# This file is part of portalmec.
#
# portalmec is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# portalmec is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with portalmec. If not, see <http://www.gnu.org/licenses/>.
class AddNumberOfResultsColumnToSearches < ActiveRecord::Migration[5.0]
def change
add_column :searches, :number_of_results, :integer
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment