diff --git a/Gemfile b/Gemfile index 743d56684..9440b3465 100644 --- a/Gemfile +++ b/Gemfile @@ -90,7 +90,7 @@ group :test do gem 'capybara' gem 'capybara-screenshot' gem 'capybara-selenium', '~> 0.0.6' - gem 'cucumber-rails', '~> 2.0', require: false + gem 'cucumber-rails', '2.3', require: false gem 'database_cleaner' gem 'delorean' # gem is discontinued gem 'launchy' diff --git a/Gemfile.lock b/Gemfile.lock index 009c82bc4..bbda8f421 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -109,12 +109,12 @@ GEM rack (>= 0.9.0) binding_of_caller (1.0.0) debug_inspector (>= 0.0.1) - bootsnap (1.7.5) + bootsnap (1.7.6) msgpack (~> 1.0) bootstrap-sass (3.4.1) autoprefixer-rails (>= 5.2.1) sassc (>= 2.0.0) - brakeman (5.0.4) + brakeman (5.1.1) builder (3.2.4) bullet (6.1.4) activesupport (>= 3.0.0) @@ -348,13 +348,13 @@ GEM gli (2.20.0) globalid (0.4.2) activesupport (>= 4.2.0) - guard (2.17.0) + guard (2.18.0) formatador (>= 0.2.4) listen (>= 2.7, < 4.0) lumberjack (>= 1.0.12, < 2.0) nenv (~> 0.1) notiffany (~> 0.0) - pry (>= 0.9.12) + pry (>= 0.13.0) shellany (~> 0.0) thor (>= 0.18.1) guard-compat (1.2.1) @@ -425,11 +425,11 @@ GEM addressable (~> 2.7) letter_opener (1.7.0) launchy (~> 2.2) - listen (3.5.1) + listen (3.6.0) rb-fsevent (~> 0.10, >= 0.10.3) rb-inotify (~> 0.9, >= 0.9.10) local_time (2.1.0) - loofah (2.10.0) + loofah (2.11.0) crass (~> 1.0.2) nokogiri (>= 1.5.9) lumberjack (1.2.8) @@ -441,7 +441,7 @@ GEM middleware (0.1.0) mime-types (3.3.1) mime-types-data (~> 3.2015) - mime-types-data (3.2021.0225) + mime-types-data (3.2021.0704) mini_histogram (0.3.1) mini_mime (1.0.3) minitest (5.14.4) @@ -529,7 +529,7 @@ GEM eventmachine_httpserver http_parser.rb (~> 0.6.0) multi_json - puma (5.3.2) + puma (5.4.0) nio4r (~> 2.0) racc (1.5.2) rack (2.2.3) @@ -581,7 +581,7 @@ GEM rake (>= 0.8.7) thor (~> 1.0) rainbow (3.0.0) - rake (13.0.3) + rake (13.0.6) rb-fsevent (0.11.0) rb-inotify (0.10.1) ffi (~> 1.0) @@ -800,7 +800,7 @@ DEPENDENCIES config constant-redefinition coveralls - cucumber-rails (~> 2.0) + cucumber-rails (= 2.3) database_cleaner delorean derailed_benchmarks diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 5c2403410..000ec95be 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -3,18 +3,23 @@ class ProjectsController < ApplicationController layout 'with_sidebar' before_action :authenticate_user!, except: %i(index show) - before_action :set_project, only: %i(show edit update) - before_action :get_current_stories, only: [:show] + before_action :set_project, only: %i(show edit update access_to_edit) + before_action :get_current_stories, only: %i(show) + before_action :valid_admin, only: %i(index), if: -> { params[:status] == 'pending' } + before_action :access_to_edit, only: %i(edit) include DocumentsHelper - # TODO: YA Add controller specs for all the code - def index - initialze_projects + query_projects(params[:status]) @projects_languages_array = Language.pluck(:name) filter_projects_list_by_language if params[:project] - @projects = @projects.search(params[:search], params[:page]) - render layout: 'with_sidebar_sponsor_right' + projects_status = params[:status] || 'active' + @projects = @projects.where(status: projects_status).search(params[:search], params[:page]) + if params[:status] == 'pending' + render :pending_projects, layout: 'with_sidebar_sponsor_right' + else + render layout: 'with_sidebar_sponsor_right' + end end def show @@ -33,9 +38,11 @@ def new end def create - @project = Project.new(project_params.merge('user_id' => current_user.id)) - if @project.save + status = current_user.admin? ? project_params[:status].downcase : 'pending' + @project = Project.create(project_params.merge(user: current_user, status: status)) + if @project.persisted? add_to_feed(:create) + current_user.follow(@project) redirect_to project_path(@project), notice: 'Project was successfully created.' else flash.now[:alert] = 'Project was not saved. Please check the input.' @@ -46,6 +53,7 @@ def create def edit; end def update + params[:command].present? && update_project_status(params[:command]) and return if @project.update(project_params) add_to_feed(:update) redirect_to project_path(@project), notice: 'Project was successfully updated.' @@ -93,16 +101,17 @@ def set_project @project = Project.friendly.find(params[:id]) end - def initialze_projects - @projects = Project.order('status ASC') + def query_projects(status) + status ||= 'active' + @projects = Project.where(status: status) .order('last_github_update DESC NULLS LAST') .order('commit_count DESC NULLS LAST') .includes(:user) end def filter_projects_list_by_language - @language = params[:project][:languages] - @projects = @projects.search_by_language(@language) + language = params[:project][:languages] + @projects = @projects.search_by_language(language) end def add_to_feed(action) @@ -135,4 +144,21 @@ def project_params name_ids: [], source_repositories_attributes: %i(id url _destroy), issue_trackers_attributes: %i(id url _destroy)) end + + def valid_admin + redirect_to root_path, notice: 'You do not have permission to perform that operation' unless user_signed_in? && current_user.admin? + end + + def access_to_edit + unless current_user.admin? || (current_user == @project.user) + redirect_to root_path, notice: 'You do not have permission to perform that operation' + end + end + + def update_project_status(command) + status = command == 'activate' ? 'active' : 'pending' + @project = Project.friendly.find(params[:id]) + @project.update(status: status) + redirect_to project_path, notice: "Project was #{command}d" + end end diff --git a/app/views/layouts/_sponsors.html.erb b/app/views/layouts/_sponsors.html.erb index d4266076d..52a068428 100644 --- a/app/views/layouts/_sponsors.html.erb +++ b/app/views/layouts/_sponsors.html.erb @@ -3,26 +3,12 @@
What to do next:
Ready to kick things off?
There are no pending projecs right now…
+<% end %> +