Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • portalmec/portalmec
  • rfhferreira/cleanning-portalmec
2 results
Show changes
Commits on Source (67)
Showing
with 639 additions and 644 deletions
......@@ -25,6 +25,7 @@ Gemfile.lock
/shared/*
dump.rdb
/public/system/*
/db/seeds/assets/*
# ignore server scripts
puma.sh
......@@ -37,4 +38,4 @@ autocomplete-server.service
# ignore configs
/config/database.yml
/config/sidekiq.yml
\ No newline at end of file
/config/sidekiq.yml
......@@ -145,7 +145,11 @@ gem 'activerecord-import'
# social connect
gem 'omniauth-facebook'
gem 'omniauth-twitter'
gem 'omniauth-google-oauth2', '~>0.8.2'
gem 'omniauth-google-oauth2', '0.8.2'
gem 'faraday'
gem 'net-http-persistent'
# get mime type
gem 'mimemagic'
......@@ -172,3 +176,9 @@ gem 'paranoia'
gem 'paper_trail'
gem 'acts_as_list'
gem 'faraday-net_http_persistent', '~> 2.0'
gem 'elasticsearch', '~> 8.6'
GIT
remote: https://github.com/c3sl/dspace-rest-client.git
revision: 07f49b52007160278e63b866a76e5f1cf800fa1b
branch: master
specs:
dspace_rest_client (3.1.0)
activesupport (>= 5.0)
faraday (>= 1.0.0)
json (>= 1.8.3, >= 1.8)
net-http-persistent (>= 2.9.4)
resource_kit (>= 0.1.4)
GIT
remote: https://github.com/kreeti/kt-paperclip.git
revision: ab1016d77336a8d7b9db72eb29b6bd19af4027fc
branch: master
specs:
kt-paperclip (6.4.1)
activemodel (>= 4.2.0)
activesupport (>= 4.2.0)
mime-types
mimemagic (~> 0.3.0)
terrapin (~> 0.6.0)
GIT
remote: https://github.com/lynndylanhurley/devise_token_auth.git
revision: 4c5245b88b39c1bb305e0cbdbfc2513eebdeda93
branch: master
specs:
devise_token_auth (1.2.0)
bcrypt (~> 3.0)
devise (> 3.5.2, < 5)
rails (>= 4.2.0, < 6.2)
GEM
remote: https://rubygems.org/
specs:
actioncable (6.1.4)
actionpack (= 6.1.4)
activesupport (= 6.1.4)
nio4r (~> 2.0)
websocket-driver (>= 0.6.1)
actionmailbox (6.1.4)
actionpack (= 6.1.4)
activejob (= 6.1.4)
activerecord (= 6.1.4)
activestorage (= 6.1.4)
activesupport (= 6.1.4)
mail (>= 2.7.1)
actionmailer (6.1.4)
actionpack (= 6.1.4)
actionview (= 6.1.4)
activejob (= 6.1.4)
activesupport (= 6.1.4)
mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 2.0)
actionpack (6.1.4)
actionview (= 6.1.4)
activesupport (= 6.1.4)
rack (~> 2.0, >= 2.0.9)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.2.0)
actiontext (6.1.4)
actionpack (= 6.1.4)
activerecord (= 6.1.4)
activestorage (= 6.1.4)
activesupport (= 6.1.4)
nokogiri (>= 1.8.5)
actionview (6.1.4)
activesupport (= 6.1.4)
builder (~> 3.1)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.1, >= 1.2.0)
active_model_serializers (0.10.12)
actionpack (>= 4.1, < 6.2)
activemodel (>= 4.1, < 6.2)
case_transform (>= 0.2)
jsonapi-renderer (>= 0.1.1.beta1, < 0.3)
activejob (6.1.4)
activesupport (= 6.1.4)
globalid (>= 0.3.6)
activemodel (6.1.4)
activesupport (= 6.1.4)
activerecord (6.1.4)
activemodel (= 6.1.4)
activesupport (= 6.1.4)
activerecord-import (1.1.0)
activerecord (>= 3.2)
activestorage (6.1.4)
actionpack (= 6.1.4)
activejob (= 6.1.4)
activerecord (= 6.1.4)
activesupport (= 6.1.4)
marcel (~> 1.0.0)
mini_mime (>= 1.1.0)
activesupport (6.1.4)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
tzinfo (~> 2.0)
zeitwerk (~> 2.3)
acts_as_list (1.0.4)
activerecord (>= 4.2)
addressable (2.7.0)
public_suffix (>= 2.0.2, < 5.0)
annotate (3.1.1)
activerecord (>= 3.2, < 7.0)
rake (>= 10.4, < 14.0)
ansi (1.5.0)
ast (2.4.2)
axiom-types (0.1.1)
descendants_tracker (~> 0.0.4)
ice_nine (~> 0.11.0)
thread_safe (~> 0.3, >= 0.3.1)
bcrypt (3.1.16)
benchmark-ips (2.9.1)
better_errors (2.8.3)
coderay (>= 1.0.0)
erubi (>= 1.0.0)
rack (>= 0.9.0)
bindex (0.8.1)
brakeman (5.0.1)
builder (3.2.4)
bullet (6.1.4)
activesupport (>= 3.0.0)
uniform_notifier (~> 1.11)
byebug (11.1.3)
case_transform (0.2)
activesupport
choice (0.2.0)
chronic (0.10.2)
climate_control (0.2.0)
coderay (1.1.3)
coercible (1.0.0)
descendants_tracker (~> 0.0.1)
concurrent-ruby (1.1.9)
connection_pool (2.2.5)
crass (1.0.6)
curb (0.9.11)
cvss (0.99.0)
dalli (2.7.11)
database_cleaner (2.0.1)
database_cleaner-active_record (~> 2.0.0)
database_cleaner-active_record (2.0.1)
activerecord (>= 5.a)
database_cleaner-core (~> 2.0.0)
database_cleaner-core (2.0.1)
dawnscanner (1.6.9)
cvss
haml
justify
logger-colors
ptools
ruby_parser
sqlite3
sys-uname
terminal-table
dead_end (1.1.7)
derailed_benchmarks (2.1.0)
benchmark-ips (~> 2)
dead_end
get_process_mem (~> 0)
heapy (~> 0)
memory_profiler (>= 0, < 2)
mini_histogram (>= 0.3.0)
rack (>= 1)
rack-test
rake (> 10, < 14)
ruby-statistics (>= 2.1)
thor (>= 0.19, < 2)
descendants_tracker (0.0.4)
thread_safe (~> 0.3, >= 0.3.1)
devise (4.8.0)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
railties (>= 4.1.0)
responders
warden (~> 1.2.3)
diff-lcs (1.4.4)
docile (1.4.0)
elasticsearch (7.13.0)
elasticsearch-api (= 7.13.0)
elasticsearch-transport (= 7.13.0)
elasticsearch-api (7.13.0)
multi_json
elasticsearch-transport (7.13.0)
faraday (~> 1)
multi_json
equalizer (0.0.11)
erubi (1.10.0)
erubis (2.7.0)
execjs (2.8.1)
factory_bot (6.2.0)
activesupport (>= 5.0.0)
factory_bot_rails (6.2.0)
factory_bot (~> 6.2.0)
railties (>= 5.0.0)
faker (2.18.0)
i18n (>= 1.6, < 2)
faraday (1.4.2)
faraday-em_http (~> 1.0)
faraday-em_synchrony (~> 1.0)
faraday-excon (~> 1.1)
faraday-net_http (~> 1.0)
faraday-net_http_persistent (~> 1.1)
multipart-post (>= 1.2, < 3)
ruby2_keywords (>= 0.0.4)
faraday-em_http (1.0.0)
faraday-em_synchrony (1.0.0)
faraday-excon (1.1.0)
faraday-net_http (1.0.1)
faraday-net_http_persistent (1.1.0)
feature (1.4.0)
ffi (1.15.1)
ffi-libarchive (1.0.17)
ffi (~> 1.0)
flamegraph (0.9.5)
flay (2.12.1)
erubis (~> 2.7.0)
path_expander (~> 1.0)
ruby_parser (~> 3.0)
sexp_processor (~> 4.0)
flog (4.6.4)
path_expander (~> 1.0)
ruby_parser (~> 3.1, > 3.1.0)
sexp_processor (~> 4.8)
get_process_mem (0.2.7)
ffi (~> 1.0)
gitlab (4.17.0)
httparty (~> 0.18)
terminal-table (~> 1.5, >= 1.5.1)
globalid (0.5.1)
activesupport (>= 5.0)
haml (5.2.1)
temple (>= 0.8.0)
tilt
hashie (4.1.0)
heapy (0.2.0)
thor
httparty (0.18.1)
mime-types (~> 3.0)
multi_xml (>= 0.5.2)
i18n (1.8.10)
concurrent-ruby (~> 1.0)
ice_nine (0.11.2)
immigrant (0.3.6)
activerecord (>= 3.0)
json (2.5.1)
jsonapi-renderer (0.2.2)
justify (1.0.2)
jwt (2.2.3)
kwalify (0.7.2)
launchy (2.5.0)
addressable (~> 2.7)
logger-colors (1.0.0)
loofah (2.10.0)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
mail (2.7.1)
mini_mime (>= 0.1.1)
marcel (1.0.1)
memory_profiler (1.0.0)
method_source (1.0.0)
mime-types (3.3.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2021.0225)
mimemagic (0.3.10)
nokogiri (~> 1)
rake
mina (1.2.3)
open4 (~> 1.3.4)
rake
mini_histogram (0.3.1)
mini_mime (1.1.0)
mini_portile2 (2.5.3)
minitest (5.14.4)
minitest-reporters (1.4.3)
ansi
builder
minitest (>= 5.0)
ruby-progressbar
multi_json (1.15.0)
multi_xml (0.6.0)
multipart-post (2.1.1)
mustache (1.1.1)
mustermann (1.1.1)
ruby2_keywords (~> 0.0.1)
net-http-persistent (4.0.1)
connection_pool (~> 2.2)
nio4r (2.5.7)
nokogiri (1.11.7)
mini_portile2 (~> 2.5.0)
racc (~> 1.4)
oauth (0.5.6)
oauth2 (1.4.7)
faraday (>= 0.8, < 2.0)
jwt (>= 1.0, < 3.0)
multi_json (~> 1.3)
multi_xml (~> 0.5)
rack (>= 1.2, < 3)
omniauth (2.0.4)
hashie (>= 3.4.6)
rack (>= 1.6.2, < 3)
rack-protection
omniauth-facebook (8.0.0)
omniauth-oauth2 (~> 1.2)
omniauth-google-oauth2 (1.0.0)
jwt (>= 2.0)
oauth2 (~> 1.1)
omniauth (~> 2.0)
omniauth-oauth2 (~> 1.7.1)
omniauth-oauth (1.2.0)
oauth
omniauth (>= 1.0, < 3)
omniauth-oauth2 (1.7.1)
oauth2 (~> 1.4)
omniauth (>= 1.9, < 3)
omniauth-twitter (1.4.0)
omniauth-oauth (~> 1.1)
rack
open4 (1.3.4)
orm_adapter (0.5.0)
paper_trail (12.0.0)
activerecord (>= 5.2)
request_store (~> 1.1)
parallel (1.20.1)
paranoia (2.4.3)
activerecord (>= 4.0, < 6.2)
parser (3.0.1.1)
ast (~> 2.4.1)
path_expander (1.1.0)
pg (1.2.3)
phantomjs (2.1.1.0)
psych (3.3.2)
ptools (1.4.2)
public_activity (1.6.4)
actionpack (>= 3.0.0)
activerecord (>= 3.0)
i18n (>= 0.5.0)
railties (>= 3.0.0)
public_suffix (4.0.6)
puma (5.3.2)
nio4r (~> 2.0)
pundit (2.1.0)
activesupport (>= 3.0.0)
racc (1.5.2)
rack (2.2.3)
rack-attack (6.5.0)
rack (>= 1.0, < 3)
rack-cors (1.1.1)
rack (>= 2.0.0)
rack-mini-profiler (2.3.2)
rack (>= 1.2.0)
rack-protection (2.1.0)
rack
rack-test (1.1.0)
rack (>= 1.0, < 3)
rails (6.1.4)
actioncable (= 6.1.4)
actionmailbox (= 6.1.4)
actionmailer (= 6.1.4)
actionpack (= 6.1.4)
actiontext (= 6.1.4)
actionview (= 6.1.4)
activejob (= 6.1.4)
activemodel (= 6.1.4)
activerecord (= 6.1.4)
activestorage (= 6.1.4)
activesupport (= 6.1.4)
bundler (>= 1.15.0)
railties (= 6.1.4)
sprockets-rails (>= 2.0.0)
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
nokogiri (>= 1.6)
rails-erd (1.6.1)
activerecord (>= 4.2)
activesupport (>= 4.2)
choice (~> 0.2.0)
ruby-graphviz (~> 1.2)
rails-html-sanitizer (1.3.0)
loofah (~> 2.3)
railties (6.1.4)
actionpack (= 6.1.4)
activesupport (= 6.1.4)
method_source
rake (>= 0.13)
thor (~> 1.0)
rainbow (3.0.0)
rake (13.0.6)
rdoc (6.3.1)
redis (4.2.5)
reek (6.0.4)
kwalify (~> 0.7.0)
parser (~> 3.0.0)
psych (~> 3.1)
rainbow (>= 2.0, < 4.0)
regexp_parser (2.1.1)
request_store (1.5.0)
rack (>= 1.4)
resource_kit (0.1.7)
addressable (>= 2.3.6, < 3.0.0)
responders (3.0.1)
actionpack (>= 5.0)
railties (>= 5.0)
rexml (3.2.5)
rmagick (4.2.2)
rspec (3.10.0)
rspec-core (~> 3.10.0)
rspec-expectations (~> 3.10.0)
rspec-mocks (~> 3.10.0)
rspec-core (3.10.1)
rspec-support (~> 3.10.0)
rspec-expectations (3.10.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.10.0)
rspec-mocks (3.10.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.10.0)
rspec-rails (5.0.1)
actionpack (>= 5.2)
activesupport (>= 5.2)
railties (>= 5.2)
rspec-core (~> 3.10)
rspec-expectations (~> 3.10)
rspec-mocks (~> 3.10)
rspec-support (~> 3.10)
rspec-support (3.10.2)
rspec_api_documentation (6.1.0)
activesupport (>= 3.0.0)
mustache (~> 1.0, >= 0.99.4)
rspec (~> 3.0)
rubocop (1.15.0)
parallel (~> 1.10)
parser (>= 3.0.0.0)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml
rubocop-ast (>= 1.5.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.6.0)
parser (>= 3.0.1.1)
ruby-graphviz (1.2.5)
rexml
ruby-progressbar (1.11.0)
ruby-statistics (2.1.3)
ruby2_keywords (0.0.4)
ruby_parser (3.16.0)
sexp_processor (~> 4.15, >= 4.15.1)
rubycritic (4.6.1)
flay (~> 2.8)
flog (~> 4.4)
launchy (>= 2.0.0)
parser (>= 2.6.0)
rainbow (~> 3.0)
reek (~> 6.0, < 7.0)
ruby_parser (~> 3.8)
simplecov (>= 0.17.0)
tty-which (~> 0.4.0)
virtus (~> 1.0)
rubyzip (2.3.0)
screencap (0.1.4)
phantomjs
sdoc (2.2.0)
rdoc (>= 5.0)
searchkick (4.4.4)
activemodel (>= 5)
elasticsearch (>= 6)
hashie
sexp_processor (4.15.3)
shoulda (4.0.0)
shoulda-context (~> 2.0)
shoulda-matchers (~> 4.0)
shoulda-context (2.0.0)
shoulda-matchers (4.5.1)
activesupport (>= 4.2.0)
sidekiq (6.2.1)
connection_pool (>= 2.2.2)
rack (~> 2.0)
redis (>= 4.2.0)
simplecov (0.21.2)
docile (~> 1.1)
simplecov-html (~> 0.11)
simplecov_json_formatter (~> 0.1)
simplecov-html (0.12.3)
simplecov_json_formatter (0.1.3)
sinatra (2.1.0)
mustermann (~> 1.0)
rack (~> 2.2)
rack-protection (= 2.1.0)
tilt (~> 2.0)
slim (4.1.0)
temple (>= 0.7.6, < 0.9)
tilt (>= 2.0.6, < 2.1)
spring (2.1.1)
sprockets (4.0.2)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
sprockets-rails (3.2.2)
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
sqlite3 (1.4.2)
stackprof (0.2.17)
streamio-ffmpeg (3.0.2)
multi_json (~> 1.8)
sys-uname (1.2.2)
ffi (~> 1.1)
temple (0.8.2)
terminal-table (1.6.0)
terrapin (0.6.0)
climate_control (>= 0.0.3, < 1.0)
thor (1.1.0)
thread_safe (0.3.6)
tilt (2.0.10)
tty-which (0.4.2)
tzinfo (2.0.4)
concurrent-ruby (~> 1.0)
unicode-display_width (2.0.0)
uniform_notifier (1.14.2)
virtus (1.0.5)
axiom-types (~> 0.1)
coercible (~> 1.0)
descendants_tracker (~> 0.0, >= 0.0.3)
equalizer (~> 0.0, >= 0.0.9)
warden (1.2.9)
rack (>= 2.0.9)
web-console (4.0.4)
actionview (>= 6.0.0)
activemodel (>= 6.0.0)
bindex (>= 0.4.0)
railties (>= 6.0.0)
websocket-driver (0.7.5)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
whenever (1.0.0)
chronic (>= 0.6.3)
zeitwerk (2.4.2)
PLATFORMS
ruby
DEPENDENCIES
active_model_serializers
activerecord-import
acts_as_list
annotate
bcrypt (>= 3.1.7)
better_errors (~> 2.8.0)
brakeman
bullet
byebug
connection_pool
curb (>= 0.8.8)
dalli
database_cleaner
dawnscanner
derailed_benchmarks
devise
devise_token_auth!
dspace_rest_client!
execjs
factory_bot_rails
faker
feature
ffi-libarchive
flamegraph
gitlab
immigrant
kt-paperclip!
mimemagic
mina
minitest-reporters
omniauth-facebook
omniauth-google-oauth2
omniauth-twitter
paper_trail
paranoia
pg
public_activity
puma
pundit
rack-attack
rack-cors
rack-mini-profiler
rails (>= 6.0.0)
rails-erd
rainbow
rdoc
rmagick
rspec-rails (>= 3.8)
rspec_api_documentation
rubocop
rubycritic
rubyzip
screencap
sdoc (>= 0.4.0)
searchkick
shoulda
sidekiq
sinatra
slim
spring
stackprof
streamio-ffmpeg (>= 1.0.0)
web-console (~> 4.0.4)
whenever
BUNDLED WITH
2.2.15
......@@ -104,6 +104,7 @@ After all gems were installed succesfuly. Please create the database using the f
* If you have the dump of the database, use it before db:migrate.
* To use the dump, run this commands: ```psql -U $DATABASE_USER -d $DATABASE_NAME < $DATABASE_PATH/dump_name.sql ```
* ``` rake db:migrate ```
* Then run `rake db:seed`.
``` Note ``` : You need to load the dump in the database_dev.
......
......@@ -28,8 +28,10 @@ class ApplicationController < ActionController::API
rescue_from Exception do |exception|
logger.fatal "The request raised an exception:"
http_request_headers = request.headers.select{|header_name, header_value| header_name.match("^HTTP.*")}
logger.fatal "#{request.method.inspect} request to #{request.url.inspect} from #{request.remote_ip.inspect} with headers #{http_request_headers.inspect} and params #{params.inspect} gave the following exception:"
logger.fatal exception
logger.fatal exception.backtrace.first(10).join("\n")
logger.fatal exception.backtrace.first(15).join("\n")
unless response_body
render status: :internal_server_error
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/>.
module ItemsFilter
extend ActiveSupport::Concern
def filter_items(items)
# filter by type
if !params[:item_type].blank?
items = items.where(item_type: params[:item_type])
end
# filter by price
if params[:op] == "lt" # less than
items = items.where("price < ?", params[:price])
elsif params[:op] == "gt" # greater than
items = items.where("price > ?", params[:price])
elsif params[:op] == "eq" # equals
items = items.where(price: params[:price])
end
# filter by the way it's unlocked
if params[:unlock_rule] == "achievement"
items = items.where.not(achievement_id: nil)
elsif params[:unlock_rule] == "purchase"
items = items.where(achievement_id: nil)
end
items
end
end
......@@ -27,6 +27,12 @@ module Paginator
return model[offset..limit]
end
#return paginate for select queries
def paginate_select(model, total)
total_count_select total
return model
end
private
def limit
......@@ -66,5 +72,8 @@ module Paginator
def total_count(model)
headers['X-Total-Count'] = model.count
end
def total_count_select(total)
headers['X-Total-Count'] = total
end
end
......@@ -28,7 +28,7 @@ module PublisherController
end
def show_all_drafts
learning_objects = paginate LearningObject.where(publisher: @publisher, state: LearningObject.states[:draft])
learning_objects = paginate LearningObject.where(publisher: @publisher, state: LearningObject.states[:draft]).order("created_at DESC")
render json: learning_objects
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 V1::AchievementsController < ApplicationController
include ::Paginator
before_action :set_achievement, only: [:show, :update, :destroy]
before_action :authenticate_user!, except: [:index, :show]
before_action :authorize!, only: [:update, :destroy]
# GET /v1/achievements
def index
achievements = paginate Achievement
render json: achievements
end
# GET /v1/achievements/1
def show
render json: @achievement
end
# POST /v1/achievements
def create
@achievement = Achievement.new(achievement_params)
authorize @achievement
if @achievement.save
@achievement.add_requirements(extra_params[:requirements])
render json: @achievement, status: :created
else
render json: @achievement.errors, status: :unprocessable_entity
end
end
# PUT/PATCH /v1/achievements/1
def update
if @achievement.update(achievement_params)
@achievement.update_requirements(extra_params[:requirements])
render json: @achievement, status: :ok
else
render json: @achievement.errors, status: :unprocessable_entity
end
end
# DELETE /v1/achievements/1
def destroy
if @achievement.update(state: 2)
render status: :ok, json: @achievement
else
render json: @achievement.errors, status: :unprocessable_entity
end
end
private
def set_achievement
@achievement ||= Achievement.find_by_id(params[:id])
if @achievement.blank?
render status: :not_found
end
end
def achievement_params
params.require(:achievement).permit(:name, :description, :reward_experience, :reward_points, :state, :repeatable, :resettable)
end
def extra_params
return {} if params[:achievement].nil?
params[:achievement].permit(requirements: [])
end
def authorize!
authorize @achievement
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 V1::ActionCountersController < ApplicationController
include ::Paginator
before_action :set_action_counter, only: :show
def index
action_counters = paginate ActionCounter
render json: action_counters
end
def show
render json: @action_counter
end
private
def set_action_counter
@action_counter ||= ActionCounter.find_by_id(params[:id])
if @action_counter.blank?
render status: :not_found
end
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 V1::ActionsController < ApplicationController
include ::Paginator
before_action :set_action, only: [:show, :update, :destroy]
before_action :authenticate_user!, except: [:index, :show]
before_action :authorize!, only: [:update, :destroy]
# GET /v1/actions
def index
actions = paginate Action
render json: actions
end
# GET /v1/actions/1
def show
render json: @action
end
# POST /v1/actions
def create
@action = Action.new(action_params)
authorize @action
if @action.save
render json: @action, status: :created
else
render json: @action.errors, status: :unprocessable_entity
end
end
# PUT/PATCH /v1/actions/1
def update
if @action.update(action_params)
render json: @action, status: :ok
else
render json: @action.errors, status: :unprocessable_entity
end
end
# DELETE /v1/actions/1
def destroy
@action.destroy
response = { 'status': 'deleted' }
render status: :ok, json: response
end
private
def set_action
@action ||= Action.find_by_id(params[:id])
if @action.blank?
render status: :not_found
end
end
def action_params
params.require(:action_params).permit(:name, :description, :reward_experience)
end
def authorize!
authorize @action
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 V1::ComplaintVotesController < ApplicationController
include ::DeletedObjectsController
include ::Paginator
before_action :set_complaint_vote, only: [:show, :update, :destroy]
# GET /v1/complaint_votes
def index
complaint_votes = paginate ComplaintVote
render json: complaint_votes
end
# GET /v1/complaint_votes/{id}
def show
render json: @complaint_vote
end
# POST /v1/complaint_votes
def create
@complaint_vote = ComplaintVote.new(complaint_vote_params)
if @complaint_vote.save
render json: @complaint_vote, status: :created
else
render json: @complaint_vote.errors, status: :unprocessable_entity
end
verify_votes(@complaint_vote)
end
# Set the params required for creating a complaint vote
def complaint_vote_params
params.require(:complaint_vote).permit(:complainable_type, :complainable_id, :pros, :cons, :user_id)
end
# PUT/PATCH /v1/complaint_votes/{id}
def update
if @complaint_vote.update(complaint_vote_params)
render json: @complaint_vote
else
render json: @complaint_vote.errors, status: :unprocessable_entity
end
end
# DELETE /v1/complaint_votes/{id}
def destroy
@complaint_vote.destroy
response = { 'status': 'deleted' }
render status: :ok, json: response
end
def set_complaint_vote
# @complaint_vote = ComplaintVote.where(id: params[:id]).first
# render status: :not_found if @complaint_vote.blank?
# @complaint_vote
@complaint_vote ||= ComplaintVote.find_by_id(params[:id]).first
if @complaint_vote.blank?
render status: :not_found
end
end
# if the difference between the pros and cons votes is more than 2, destroy the learning object
def verify_votes(complaint_vote)
data = ComplaintVote.select("complainable_id, sum(pros) as pros, sum(cons) as cons")
.where("complainable_id = ?", complaint_vote.complainable_id)
.group("complaint_votes.complainable_id")
data.each do |d|
if (d.complainable_id == complaint_vote.complainable_id)
if d.pros - d.cons > 2
ComplaintVote.where("complainable_id = ?", complaint_vote.complainable_id).destroy_all
Complaint.where("complainable_id = ?", complaint_vote.complainable_id).destroy_all
LearningObject.where(id: complaint_vote.complainable_id).update_all(state: LearningObject.states[:deleted])
LearningObject.where(id: complaint_vote.complainable_id).update_all(deleted_at: Time.now)
elsif d.cons - d.pros > 2
ComplaintVote.where("complainable_id = ?", complaint_vote.complainable_id).destroy_all
Complaint.where("complainable_id = ?", complaint_vote.complainable_id).update_all(state: Complaint.states[:rejected])
LearningObject.where(id: complaint_vote.complainable_id).update_all(state: LearningObject.states[:published])
end
end
end
end
end
......@@ -54,7 +54,9 @@ class V1::ComplaintsController < ApplicationController
if @complaint.save
ComplaintsMailer.new_complaint_received(@complaint, @current_user).deliver_now
@complaint.complainable.treat_complaintment
if (Complaint.where(complainable_id: @complaint.complainable_id).count >= 2)
LearningObject.where(id: @complaint.complainable_id).update_all(state: LearningObject.states[:suspended])
end
render json: @complaint, status: :created
else
......
......@@ -22,13 +22,13 @@ class V1::ContactsController < ApplicationController
before_action :authenticate_user!, except: [:create]
before_action :set_contact, only: [:show, :update, :destroy]
before_action :set_new_contact, only: :index
before_action :set_new_contact, only: :index
before_action :authorize!, except: [:create]
# GET v1/contacts
def index
contacts = paginate policy_scope(Contact)
render json: contacts
render json: contacts
end
# GET v1/contacts/1
......@@ -82,8 +82,8 @@ class V1::ContactsController < ApplicationController
def authorize!
authorize @contact
end
def set_new_contact
@contact ||= Contact.new
end
def set_new_contact
@contact ||= Contact.new
end
end
......@@ -21,13 +21,28 @@ class V1::EmailController < ApplicationController
before_action :authenticate, only: [:create]
before_action -> { authorize current_user }, only: [:create]
def index
users_email = []
for u in User.all
users_email.push(u.email)
end
render json: users_email
end
def create
email = Email.new(email_params)
email.role_ids = roles_params[:roles]
users = User.joins(:roles).where(roles: { id: email.role_ids }).distinct
for u in users
email.emails.push(u.email)
end
email.user = current_user
if email.save
email.emails.each do |address|
EmailMailer.new_email(email, address).deliver_now
UserMailer.users_email_sender(address, email_params[:subject], email_params[:body]).deliver_now
end
render status: :ok
else
......
......@@ -40,7 +40,7 @@ class V1::FeedController < ApplicationController
current_user.watching.each do |watching|
if !watching.respond_to?(:state) || watching.state == "published"
if (watching.class == Submission || watching.class == CuratorAssignment)
query += " ((trackable_type = ? and trackable_id = ?) and (owner_type = 'User' and owner_id = #{current_user.id})"
query += " ( recipient_id != owner_id and (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
......
# 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 V1::ItemsController < ApplicationController
include ::Paginator
include ::ItemsFilter
before_action :set_item, only: [:show, :update, :destroy]
before_action :authenticate_user!, except: [:index, :show]
before_action :authorize!, only: [:update, :destroy]
def index
items = paginate filter_items(policy_scope(Item))
render json: items
end
def show
render json: @item
end
def create
@item = Item.new(item_params)
authorize @item
if @item.save
render json: @item, status: :created
else
render json: @item.errors, status: :unprocessable_entity
end
end
# PUT/PATCH /v1/items/1
def update
if @item.update(item_params)
render json: @item, status: :ok
else
render json: @item.errors, status: :unprocessable_entity
end
end
# DELETE /v1/items/1
def destroy
if @item.update(state: 2)
render status: :ok, json: @item
else
render json: @item.errors, status: :unprocessable_entity
end
end
private
def set_item
@item ||= Item.find_by_id(params[:id])
if @item.blank?
render status: :not_found
end
end
def item_params
params.require(:item).permit(:name, :price, :discount, :description, :state, :item_type, :image, :achievement_id)
end
def authorize!
authorize @item
end
end
......@@ -30,15 +30,18 @@ class V1::LearningObjects::ChunksController < ApplicationController
def create
save_file!
if last_chunk?
combine_file!
attachment = post_file!
render json: attachment, status: :ok
else
if chunks_params[:cancel] == "true"
FileUtils.rm_rf(chunk_file_directory)
render status: :ok
else
if last_chunk?
combine_file!
attachment = post_file!
render json: attachment, status: :ok
else
render status: :ok
end
end
rescue
render status: :internal_server_error
end
private
......@@ -53,7 +56,7 @@ class V1::LearningObjects::ChunksController < ApplicationController
# Never trust parameters from the scary internet, only allow the white list through.
def chunks_params
params.permit(:id, :file, :_chunkNumber, :_totalChunks, :_chunkFilename, :_chunkIdentifier, :_chunkSize, :_currentChunkSize, :_totalSize)
params.permit(:id, :file, :_chunkNumber, :_totalChunks, :_chunkFilename, :_chunkIdentifier, :_chunkSize, :_currentChunkSize, :_totalSize, :cancel)
end
def post_file!
......
class V1::LearningObjectsComplaintsController < ApplicationController
include ::DeletedObjectsController
include ::Paginator
# learning_object_complaints[i] = data of a complaint (always in even positions)
# learning_object_complaints[i+1] = image of learning_object, and user, also contains the tags of the object and the download link (always in odd positions)
def generate_priority_queue(complaints_priority)
complaints_curator = []
complaints_priority.each do |complainable|
# Select all complaints related to the complainable_id (attributes that have been sumed)
complaints_curator << ComplaintReason.joins("INNER JOIN complaints ON complaint_reasons.id = complaints.complaint_reason_id
INNER JOIN learning_objects on complaints.complainable_id = learning_objects.id
INNER JOIN users ON learning_objects.publisher_id = users.id
INNER JOIN object_types ON learning_objects.object_type_id = object_types.id
")
.select("learning_objects.id as learning_object_id, learning_objects.name, learning_objects.review_average,
learning_objects.likes_count, users.name as publisher_name,
object_types.name as type_object, complaints.description, complaint_reasons.id as complaint_reason_id,
complaint_reasons.reason, complaint_reasons.priority")
.where("complaints.complainable_id = ? AND complaints.state = 0", complainable.complainable_id).order("complaint_reasons.priority DESC")
#find the learning_object by the complainable_id
learning_object = LearningObject.where(id: complainable.complainable_id)
lo_data = Hash.new
tags = Tagging.joins(:tag).where("taggings.taggable_id = ?", complainable.complainable_id).select("tags.name")
all_tags = []
#add all tags to lo_data hash
tags.each do |tag|
if (tag.name != nil)
all_tags << tag.name
end
end
lo_data['tags'] = all_tags
#iterate by all learning_objects found
for lo in learning_object
lo_data['learning_object_thumb'] = lo.thumbnail
if (lo.publisher_id != nil)
user = User.where(id: lo.publisher_id).first
lo_data['user_avatar'] = user.avatar
end
lo_data['download_link'] = lo.download_link
end
complaints_curator << lo_data
end
return complaints_curator
end
# GET v1/learning_objects_complaints
def index
#select and sum the priority if has two or more complaints
complaints_priority = ComplaintReason.joins(:complaints).select("complainable_id, SUM(complaint_reasons.priority) as priorities")
.where("complaints.state = 0").group("complainable_id").having("(COUNT(complainable_id) > 1 OR SUM(complaint_reasons.priority) > 20)")
.order("priorities DESC").order("complainable_id").limit(params["limit"]).offset(params["offset"])
total = ComplaintReason.joins(:complaints).select("complainable_id, SUM(complaint_reasons.priority)")
.where("complaints.state = 0").group("complainable_id").having("COUNT(complainable_id) > 1 OR SUM(complaint_reasons.priority) > 20")
queue = generate_priority_queue(complaints_priority)
complaints_queue = paginate_select(queue, total.length)
render json: complaints_queue
end
# GET v1/learning_objects_complaints/queue_user/:user_id
def queue_user
#select and sum the priority if has two or more complaints
complaints_priority = ComplaintReason.joins(:complaints).select("complainable_id, SUM(complaint_reasons.priority) as priorities")
.where("complaints.state = 0").where.not("complaints.user_id = ?",params[:user_id]).group("complainable_id").having("(COUNT(complainable_id) > 1 OR SUM(complaint_reasons.priority) > 20)")
.order("priorities DESC").order("complainable_id").limit(params["limit"]).offset(params["offset"])
total = ComplaintReason.joins(:complaints).select("complainable_id, SUM(complaint_reasons.priority)")
.where("complaints.state = 0").where.not("complaints.user_id = ?",params[:user_id]).group("complainable_id").having("COUNT(complainable_id) > 1 OR SUM(complaint_reasons.priority) > 20")
queue = generate_priority_queue(complaints_priority)
complaints_queue = paginate_select(queue, total.length)
render json: complaints_queue
end
def show
id = params[:id]
complaints = ComplaintReason.joins("INNER JOIN complaints ON complaint_reasons.id = complaints.complaint_reason_id")
.where("complaints.complainable_id = ?",id)
.select("complaints.description, complaint_reasons.reason, complaint_reasons.priority")
render json: complaints
end
end
......@@ -75,6 +75,13 @@ class V1::LearningObjectsController < ApplicationController
# PATCH/PUT /learning_objects/1.json
def update
lo_params = learning_object_params
language_ids_lo = params[:language_ids]
@learning_object.language_ids = language_ids_lo
current_user.update_tags(@learning_object, with: params[:tags].map { |t| t['name'] }) unless params[:tags].nil?
@learning_object.update_educational_stages(ids: params[:educational_stages]) unless params[:educational_stages].nil?
@learning_object.update_subjects(ids: params[:subjects]) unless params[:subjects].nil?
@learning_objectl.thumbnail = params[:thumbnail] unless lo_params[:thumbnail] != "null"
if !lo_params[:object_type_id].blank? && lo_params[:object_type_id] != @learning_object.object_type_id && lo_params[:link].blank?
change_object_type_id = true
end
......@@ -91,14 +98,20 @@ class V1::LearningObjectsController < ApplicationController
render json: @learning_object, status: :ok
else
render json: @learning_object.errors, status: :unprocessable_entity
render json: @learning_object.errors, status: :unprocessable_entity
end
end
# DELETE /learning_objects/1
# DELETE /learning_objects/1.json
def destroy
@learning_object.update(state: LearningObject.states[:deleted])
@learning_object.destroy
Submission.where(learning_object_id: @learning_object.id).update_all(status: Submission.statuses[:rejected])
Submission.where(learning_object_id: @learning_object.id).destroy_all
response = { 'status': 'deleted' }
render status: :ok, json: response
end
......@@ -162,12 +175,9 @@ class V1::LearningObjectsController < ApplicationController
elsif !extra_params[:tags].nil?
current_user.tag(learning_object, with: extra_params[:tags].map { |t| t['name'] })
end
learning_object.add_subjects(ids: extra_params[:subjects]) unless extra_params[:subjects].nil?
learning_object.add_educational_stages(ids: extra_params[:educational_stages]) unless extra_params[:educational_stages].nil?
learning_object.add_subjects(ids: params[:subjects]) unless params[:subjects].nil?
#learning_object.add_educational_stages(ids: extra_params[:educational_stages]) unless extra_params[:educational_stages].nil?
if change_object_type_id
learning_object.link = nil
end
end
def update_learning_object_associations(learning_object, change_object_type_id=false)
......@@ -175,9 +185,6 @@ class V1::LearningObjectsController < ApplicationController
learning_object.update_subjects(ids: extra_params[:subjects].map {|s| s.to_i}) unless extra_params[:subjects].nil?
learning_object.update_educational_stages(ids: extra_params[:educational_stages].map {|es| es.to_i}) unless extra_params[:educational_stages].nil?
if change_object_type_id
learning_object.link = nil
end
end
def authorize!
......