diff options
Diffstat (limited to 'app/controllers/snippets_controller.rb')
-rw-r--r-- | app/controllers/snippets_controller.rb | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/app/controllers/snippets_controller.rb b/app/controllers/snippets_controller.rb index 70525beea15..49b740af046 100644 --- a/app/controllers/snippets_controller.rb +++ b/app/controllers/snippets_controller.rb @@ -15,19 +15,28 @@ class SnippetsController < ApplicationController def user_index @user = User.find_by_username(params[:username]) - - @snippets = @current_user.snippets.fresh.non_expired - - @snippets = case params[:scope] - when 'public' then - @snippets.public - when 'private' then - @snippets.private - else - @snippets - end + @snippets = @user.snippets.fresh.non_expired + + if @user == current_user + @snippets = case params[:scope] + when 'public' then + @snippets.public + when 'private' then + @snippets.private + else + @snippets + end + else + @snippets = @snippets.public + end @snippets = @snippets.page(params[:page]).per(20) + + if @user == current_user + render 'current_user_index' + else + render 'user_index' + end end def new @@ -79,7 +88,7 @@ class SnippetsController < ApplicationController protected def snippet - @snippet ||= PersonalSnippet.find(params[:id]) + @snippet ||= PersonalSnippet.where('author_id = :user_id or private is false', user_id: current_user.id).find(params[:id]) end def authorize_modify_snippet! |