diff --git a/app/contexts/projects/create_context.rb b/app/contexts/projects/create_context.rb index da666a71f0da2123535a796e300f21cfe1b4ed72..56c4e1c51da0ab0201e2175bce0eb7c1087e096d 100644 --- a/app/contexts/projects/create_context.rb +++ b/app/contexts/projects/create_context.rb @@ -32,8 +32,9 @@ module Projects @project.namespace_id = current_user.namespace_id end - # Disable wall by default + # Disable less important features by default @project.wall_enabled = false + @project.snippets_enabled = false @project.creator = current_user diff --git a/app/controllers/snippets_controller.rb b/app/controllers/snippets_controller.rb index 26898abfa82f7f0fda688cf871662964f50e3449..d356479330b1ea38630a87455dc29607313db595 100644 --- a/app/controllers/snippets_controller.rb +++ b/app/controllers/snippets_controller.rb @@ -1,4 +1,5 @@ class SnippetsController < ProjectResourceController + before_filter :module_enabled before_filter :snippet, only: [:show, :edit, :destroy, :update, :raw] # Allow read any snippet @@ -84,4 +85,8 @@ class SnippetsController < ProjectResourceController def authorize_admin_snippet! return render_404 unless can?(current_user, :admin_snippet, @snippet) end + + def module_enabled + return render_404 unless @project.snippet_enabled + end end diff --git a/app/models/project.rb b/app/models/project.rb index 458ef18376c25c6eb6f1f5a1041e9d004d708805..b13b2918652c0ad15af22921d97c0768d7967bb7 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -29,7 +29,7 @@ class Project < ActiveRecord::Base class TransferError < StandardError; end attr_accessible :name, :path, :description, :default_branch, :issues_tracker, - :issues_enabled, :wall_enabled, :merge_requests_enabled, :issues_tracker_id, + :issues_enabled, :wall_enabled, :merge_requests_enabled, :snippets_enabled, :issues_tracker_id, :wiki_enabled, :public, :import_url, as: [:default, :admin] attr_accessible :namespace_id, :creator_id, as: :admin diff --git a/app/views/layouts/project_resource.html.haml b/app/views/layouts/project_resource.html.haml index 3f7c4322d63a45e686250f700ee2ec7a524facff..7de5cb6127392a9a5892fb6623277fa9b92f29e3 100644 --- a/app/views/layouts/project_resource.html.haml +++ b/app/views/layouts/project_resource.html.haml @@ -43,6 +43,10 @@ = nav_link(path: 'projects#wall') do = link_to 'Wall', wall_project_path(@project) + - if @project.snippets_enabled + = nav_link(controller: :snippets) do + = link_to 'Snippets', project_snippets_path(@project) + - if can? current_user, :admin_project, @project = nav_link(html_options: {class: "#{project_tab_class}"}) do = link_to edit_project_path(@project), class: "stat-tab tab " do diff --git a/app/views/projects/_form.html.haml b/app/views/projects/_form.html.haml index 25901456ab13df67ecf31e8fed52302761e35732..38384b775f8e1da859a0a13ab64f0f7aa06447dc 100644 --- a/app/views/projects/_form.html.haml +++ b/app/views/projects/_form.html.haml @@ -87,6 +87,12 @@ = f.check_box :wall_enabled %span.descr Simple chat system for broadcasting inside project + .control-group + = f.label :snippets_enabled, "Snippets", class: 'control-label' + .controls + = f.check_box :snippets_enabled + %span.descr Share code pastes with others out of git repository + .control-group = f.label :wiki_enabled, "Wiki", class: 'control-label' .controls diff --git a/db/migrate/20130318212250_add_snippets_to_features.rb b/db/migrate/20130318212250_add_snippets_to_features.rb new file mode 100644 index 0000000000000000000000000000000000000000..ad0b4434c435301911b86e22a58144e231c5838a --- /dev/null +++ b/db/migrate/20130318212250_add_snippets_to_features.rb @@ -0,0 +1,5 @@ +class AddSnippetsToFeatures < ActiveRecord::Migration + def change + add_column :projects, :snippets_enabled, :boolean, null: false, default: true + end +end diff --git a/db/schema.rb b/db/schema.rb index 80c61a4fd6aec682efc579ea17a2b2512898bc19..e4349ac4bf79633e68cdb1e107d54953a0930156 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20130315124931) do +ActiveRecord::Schema.define(:version => 20130318212250) do create_table "events", :force => true do |t| t.string "target_type" @@ -155,6 +155,7 @@ ActiveRecord::Schema.define(:version => 20130315124931) do t.boolean "public", :default => false, :null => false t.string "issues_tracker", :default => "gitlab", :null => false t.string "issues_tracker_id" + t.boolean "snippets_enabled", :default => true, :null => false end add_index "projects", ["creator_id"], :name => "index_projects_on_owner_id"