Skip to content
Snippets Groups Projects
Commit 7e5137d0 authored by Mauricio Giacomini Girardello's avatar Mauricio Giacomini Girardello
Browse files

Merge branch 'master' of gitlab.c3sl.ufpr.br:portalmec/portalmec

parents f251e0d7 5ec3f92a
No related branches found
No related tags found
No related merge requests found
class UsersController < ApplicationController class UsersController < ApplicationController
include Pundit
before_action :authenticate_user!, only: [:follow, :unfollow] before_action :authenticate_user!, only: [:follow, :unfollow]
before_action :check_current_user_page, only: :show before_action :check_current_user_page, only: :show
before_action :set_user, only: [:show] before_action :set_user, only: [:show]
...@@ -9,7 +12,7 @@ class UsersController < ApplicationController ...@@ -9,7 +12,7 @@ class UsersController < ApplicationController
def show def show
@objects = @user.learning_objects @objects = @user.learning_objects
@institutions = @user.institutions @institutions = @user.institutions
@groups = [CollectionsGroup.new(title: 'Coleções Adicionadas', collections: [@user.collections.includes(:owner)])] @groups = [CollectionsGroup.new(title: 'Coleções Adicionadas', collections: [ CollectionPolicy::Scope.new(current_user, @user.id, @user.collections).resolve.includes(:owner)])]
if @user == current_user if @user == current_user
@publishers = @user.institutions @publishers = @user.institutions
......
...@@ -28,7 +28,7 @@ module CollectionsHelper ...@@ -28,7 +28,7 @@ module CollectionsHelper
end end
def no_collections(collections, user) def no_collections(collections, user)
"Nenhuma coleção disponível. Crie novas coleções na página do seu perfil ou #{link_to 'clique aqui', user_path(user)}" if collections.blank? "Nenhuma coleção disponível. Crie novas coleções na página do seu perfil ou #{link_to 'clique aqui', user_path(user)}".html_safe if collections.blank?
end end
end end
...@@ -59,8 +59,9 @@ class Collection < ActiveRecord::Base ...@@ -59,8 +59,9 @@ class Collection < ActiveRecord::Base
end end
def user_own?(user) def user_own?(user)
return true if user.is_a? Institution and owner.users.include?(user)
return false unless user.is_a? User return false unless user.is_a? User
owner?(user) || owner.users.include?(user) user.is_admin? || owner?(user)
end end
def private? def private?
......
...@@ -2,6 +2,26 @@ class CollectionPolicy < ApplicationPolicy ...@@ -2,6 +2,26 @@ class CollectionPolicy < ApplicationPolicy
include SociablePolicy include SociablePolicy
include FollowablePolicy include FollowablePolicy
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?)
scope.all
else
scope.where(privacy: 'public')
end
end
end
def create? def create?
record if user_exists? record if user_exists?
end end
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
</div> </div>
</div> </div>
<div class="col-md-6 right-column align-right"> <div class="col-md-6 right-column align-right">
<% if current_user_page? @user %> <% if user_signed_in? && current_user_page?(@user) %>
<%= link_to 'Adicionar novo objeto', new_learning_object_path, class: 'btn btn-primary'%> <%= link_to 'Adicionar novo objeto', new_learning_object_path, class: 'btn btn-primary'%>
<% else %> <% else %>
<!-- <button type="button" class="btn btn-primary">Enviar mensagem</button> --> <!-- <button type="button" class="btn btn-primary">Enviar mensagem</button> -->
...@@ -48,7 +48,7 @@ ...@@ -48,7 +48,7 @@
</div> </div>
</div> </div>
<div class="col-md-6 right-column align-right"> <div class="col-md-6 right-column align-right">
<%= render('collections/create', collection: @new_collection, publishers: @publishers, placement: 'left') if current_user_page?(@user) %> <%= render('collections/create', collection: @new_collection, publishers: @publishers, placement: 'left') if user_signed_in? && current_user_page?(@user) %>
</div> </div>
</div> </div>
......
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