Skip to content
Snippets Groups Projects
Commit e1193ca5 authored by Bernardo Chagas's avatar Bernardo Chagas
Browse files

Merge branch 'master' of gitlab.c3sl.ufpr.br:portalmec/portalmec into show-public-collections

parents 581940fa 9fb087fb
No related branches found
No related tags found
No related merge requests found
Showing
with 184 additions and 12 deletions
......@@ -16,7 +16,7 @@ class V1::CollectionsController < ApplicationController
# GET /v1/collections
# GET /v1/collections.json
def index
collections = paginate Collection
collections = paginate policy_scope(Collection)
render json: collections
end
......
class V1::ContactsController < ApplicationController
include ::Paginator
before_action :set_contact, only: [:show, :update, :destroy]
# GET v1/contacts
def index
contacts = paginate Contact
render json: contacts
end
# GET v1/contacts/1
def show
render json: @contact
end
# POST v1/contacts
def create
@contact = Contact.new(contact_params)
if @contact.save
render json: @contact, status: :created
else
render json: @contact.errors, status: :unprocessable_entity
end
end
# PATCH/PUT v1/contacts/1
def update
if @contact.update(contact_params)
render json: @contact
else
render json: @contact.errors, status: :unprocessable_entity
end
end
# DELETE v1/contacts/1
def destroy
@contact.destroy
render status: :ok
end
private
# Use callbacks to share common setup or constraints between actions.
def set_contact
@contact = Contact.find(params[:id])
end
# Only allow a trusted parameter "white list" through.
def contact_params
params.require(:contact).permit(:name, :email, :message)
end
end
require 'open-uri'
class V1::OmniauthCallbacksController < DeviseTokenAuth::ApplicationController
attr_reader :auth_params
......@@ -76,8 +77,7 @@
# break out provider attribute assignment for easy method extension
def assign_provider_attrs(user, auth_hash)
avatar = auth_hash['provider']=='google_oauth2' ? "" : auth_hash['info']['image']
avatar = auth_hash['provider']=='google_oauth2' ? open(auth_hash['info']['image']) : auth_hash['info']['image']
user.assign_attributes({
nickname: auth_hash['info']['nickname'],
......
class V1::SuggestionsController < ApplicationController
include ::Paginator
before_action :set_suggestion, only: [:show, :update, :destroy]
# GET v1/suggestions
def index
suggestions= paginate Suggestion
render json: suggestions
end
# GET v1/suggestions/1
def show
render json: @suggestion
end
# POST v1/suggestions
def create
@suggestion = Suggestion.new(suggestion_params)
if @suggestion.save
render json: @suggestion, status: :created
else
render json: @suggestion.errors, status: :unprocessable_entity
end
end
# PATCH/PUT v1/suggestions/1
def update
if @suggestion.update(suggestion_params)
render json: @suggestion
else
render json: @suggestion.errors, status: :unprocessable_entity
end
end
# DELETE v1/suggestions/1
def destroy
@suggestion.destroy
render status: :ok
end
private
# Use callbacks to share common setup or constraints between actions.
def set_suggestion
@suggestion = Suggestion.find(params[:id])
end
# Only allow a trusted parameter "white list" through.
def suggestion_params
params.require(:suggestion).permit(:name, :link, :description, :status)
end
end
......@@ -24,4 +24,9 @@ class CollectionItem < ApplicationRecord
def recipient
collection
end
def thumbnail
collectionable_type == 'LearningObject' ? LearningObject.find(collectionable_id).default_thumbnail : Collection.find(collectionable_id).thumbnail
end
end
# == Schema Information
#
# Table name: contacts
#
# id :integer not null, primary key
# name :string
# email :string
# message :text
#
class Contact < ApplicationRecord
end
# == Schema Information
#
# Table name: suggestions
#
# id :integer not null, primary key
# name :string
# link :string
# description :text
# status :integer
#
class Suggestion < ApplicationRecord
enum status: { created: 0, accepted: 1, rejected: 2, loaded: 3 }
end
......@@ -6,17 +6,11 @@ class CollectionPolicy < ApplicationPolicy
include StageablePolicy
class Scope < Scope
def initialize(user, user_id, scope)
@user = user
@user_id = user_id
@scope = scope
end
def resolve
if @user.try(:id) == @user_id || @user.try(:is_admin?)
if !user.nil? && user.is_admin?
scope.all
else
scope.where(privacy: 'public')
scope.includes(:collection_items).where.not(:collection_items => {:collection_id => nil}).where(privacy: 'public')
end
end
end
......
......@@ -17,7 +17,19 @@ class CollectionSerializer < ActiveModel::Serializer
object.followed? current_user
end
attributes :id, :name, :created_at, :updated_at, :description, :privacy, :score, :likes_count, :liked, :reviewed, :complained, :followed, :review_average, :thumbnail
def items_thumbnails
thumbs = []
i = 0
while thumbs.size < 4 && i < object.collection_items.size do
t = object.collection_items[i].thumbnail
thumbs << t unless t.blank?
i=i+1
end
thumbs
end
attributes :id, :name, :created_at, :updated_at, :description, :privacy, :score, :likes_count, :liked, :reviewed, :complained, :review_average, :thumbnail, :items_thumbnails
belongs_to :owner
has_many :tags
has_many :subjects
......
class ContactSerializer < ActiveModel::Serializer
cache key: 'contact', expires_in: 24.hours
attributes :id, :name, :email, :message
end
class SuggestionSerializer < ActiveModel::Serializer
attributes :id, :name, :link, :description, :status
end
......@@ -139,6 +139,8 @@ Rails.application.routes.draw do
resources :roles, except: [:new, :edit]
resources :scores, only: [:index, :show, :update]
resources :ratings, except: [:new, :edit]
resources :contacts
resources :suggestions
post '/package', to: 'packages#link'
get '/subjects', to: 'subjects#index'
......
class CreateContacts < ActiveRecord::Migration[5.0]
def change
create_table :contacts do |t|
t.string :name
t.string :email
t.text :message
t.timestamps
end
end
end
class CreateSuggestions < ActiveRecord::Migration[5.0]
def change
create_table :suggestions do |t|
t.string :name
t.string :link
t.text :description
t.integer :status, default: 0
t.timestamps
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment