Forked from
PortalMEC / portalmec
2383 commits behind the upstream repository.
-
Matheus Agio Nerone authored
Signed-off-by:
man13 <man13@inf.ufpr.br>
Matheus Agio Nerone authoredSigned-off-by:
man13 <man13@inf.ufpr.br>
users_controller.rb 1.76 KiB
class UsersController < ApplicationController
before_action :authenticate_user!, only: :me
before_action :check_current_user_page, only: :show
before_action :set_user, only: :show
before_action :set_institutions, only: :me
before_action :set_empty_collection, only: [:show, :me]
def show
@objects = @user.learning_objects
@institutions = @user.institutions
@groups = [
CollectionsGroup.new(title: 'Coleções Automáticas',
collections: [
@new_collection
]),
CollectionsGroup.new(title: 'Coleções Adicionadas',
collections: [
@user.collections
])
]
end
def me
@publishers = current_user.institutions
@objects = current_user.learning_objects
@bookmarks = current_user.bookmarks
@groups = [
CollectionsGroup.new(title: 'Coleções Automáticas',
collections: [@bookmarks]),
CollectionsGroup.new(title: 'Coleções Adicionadas',
collections: current_user.collections)
]
end
def list
@users = User.all
end
private
def set_empty_collection
@new_collection = Collection.new
end
def set_institutions
@institutions = current_user.institutions
end
def set_user
@user = user_repository.find params[:id]
end
def check_current_user_page
if user_signed_in?
if current_user.id == params[:id]
redirect_to action: :me
end
end
end
def publishers_for(user)
publishers = []
user_publisher = user
user_publisher.id = user.rid
publishers << user_publisher
publishers + user.institutions
end
end