diff options
author | Andrew8xx8 <avk@8xx8.ru> | 2013-03-25 02:17:03 +0400 |
---|---|---|
committer | Andrew8xx8 <avk@8xx8.ru> | 2013-03-25 02:17:03 +0400 |
commit | e90aebe259b1f81cb2523099cab4626b9276e751 (patch) | |
tree | 154f278a7619a15720a3df3f6c6c53081f0a63a7 /app | |
parent | 9bd1983e167c7a040565d8e03a20364455bddd59 (diff) | |
download | gitlab-ce-e90aebe259b1f81cb2523099cab4626b9276e751.tar.gz |
Personal snippets controlelr refactored
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/snippets_controller.rb | 59 | ||||
-rw-r--r-- | app/models/ability.rb | 5 |
2 files changed, 33 insertions, 31 deletions
diff --git a/app/controllers/snippets_controller.rb b/app/controllers/snippets_controller.rb index bb5fffca33c..2062ceafa9c 100644 --- a/app/controllers/snippets_controller.rb +++ b/app/controllers/snippets_controller.rb @@ -1,13 +1,6 @@ -class SnippetsController < ProjectResourceController - before_filter :module_enabled +class SnippetsController < ApplicationController before_filter :snippet, only: [:show, :edit, :destroy, :update, :raw] - # Allow read any snippet - before_filter :authorize_read_snippet! - - # Allow write(create) snippet - before_filter :authorize_write_snippet!, only: [:new, :create] - # Allow modify snippet before_filter :authorize_modify_snippet!, only: [:edit, :update] @@ -17,22 +10,39 @@ class SnippetsController < ProjectResourceController respond_to :html def index - @snippets = @project.snippets.fresh.non_expired + @snippets = Snippet.public.fresh.non_expired.page(params[:page]).per(20) + end + + 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 = @snippets.page(params[:page]).per(20) end def new - @snippet = @project.snippets.new + @snippet = PersonalSnippet.new end def create - @snippet = @project.snippets.new(params[:snippet]) + @snippet = PersonalSnippet.new(params[:personal_snippet]) @snippet.author = current_user @snippet.save if @snippet.valid? - redirect_to [@project, @snippet] + redirect_to snippet_path(@snippet) else - respond_with(@snippet) + respond_with @snippet end end @@ -40,27 +50,24 @@ class SnippetsController < ProjectResourceController end def update - @snippet.update_attributes(params[:snippet]) + @snippet.update_attributes(params[:personal_snippet]) if @snippet.valid? - redirect_to [@project, @snippet] + redirect_to snippet_path(@snippet) else - respond_with(@snippet) + respond_with @snippet end end def show - @note = @project.notes.new(noteable: @snippet) - @target_type = :snippet - @target_id = @snippet.id end def destroy - return access_denied! unless can?(current_user, :admin_snippet, @snippet) + return access_denied! unless can?(current_user, :admin_personal_snippet, @snippet) @snippet.destroy - redirect_to project_snippet_path(@project) + redirect_to snippets_path end def raw @@ -75,18 +82,14 @@ class SnippetsController < ProjectResourceController protected def snippet - @snippet ||= @project.snippets.find(params[:id]) + @snippet ||= PersonalSnippet.find(params[:id]) end def authorize_modify_snippet! - return render_404 unless can?(current_user, :modify_snippet, @snippet) + return render_404 unless can?(current_user, :modify_personal_snippet, @snippet) end def authorize_admin_snippet! - return render_404 unless can?(current_user, :admin_snippet, @snippet) - end - - def module_enabled - return render_404 unless @project.snippets_enabled + return render_404 unless can?(current_user, :admin_personal_snippet, @snippet) end end diff --git a/app/models/ability.rb b/app/models/ability.rb index 928b36e6c80..2dadb584460 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -8,7 +8,7 @@ class Ability when "Issue" then issue_abilities(user, subject) when "Note" then note_abilities(user, subject) when "ProjectSnippet" then project_snippet_abilities(user, subject) - when "Snippet" then snippet_abilities(user, subject) + when "PersonalSnippet" then personal_snippet_abilities(user, subject) when "MergeRequest" then merge_request_abilities(user, subject) when "Group", "Namespace" then group_abilities(user, subject) when "UserTeam" then user_team_abilities(user, subject) @@ -135,8 +135,7 @@ class Ability rules.flatten end - - [:issue, :note, :project_snippet, :snippet, :merge_request].each do |name| + [:issue, :note, :project_snippet, :personal_snippet, :merge_request].each do |name| define_method "#{name}_abilities" do |user, subject| if subject.author == user [ |