Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Admin based Project approval flow #3784

Merged
merged 37 commits into from
Aug 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
5f0236f
modified projects controller create method to take a default pending …
Jul 18, 2021
664c439
created pending_projects conroller method with corresponding view and…
Jul 18, 2021
6830c96
created activate_project controller method with form in project view …
Jul 18, 2021
b7b16a5
created deactivate_project controller method with form in project vie…
Jul 18, 2021
290f01f
added admin attribute to User and created valid_admin method in proje…
Jul 18, 2021
c5f383b
modified index method in projects controller to only display project…
Jul 18, 2021
10eb6ba
added access_to_edit method inproject controller to resctrict edit of…
Jul 19, 2021
3f96a11
made deactivate project button class btn-danger
Jul 19, 2021
48dfd1f
created a sub facory called :signed_in_user
Jul 21, 2021
0e9aa47
created NewUserForm class for page object pattern for feature spec
Jul 21, 2021
83b6e69
created features folder and projects_spec.rb
Jul 21, 2021
d9e01a3
refactors project create and approve feature
tochman Jul 21, 2021
7eb06eb
refactors project create and approve feature
Jul 21, 2021
bdb00f4
refactors feature structure
tochman Jul 24, 2021
21f77de
refactors projects controller to deal with activation/deactivation of
tochman Jul 24, 2021
2fc4f0e
refactors specs and reactivates the #access_to_edit method
tochman Jul 25, 2021
eda9f12
adds more scenarios to feature
tochman Jul 25, 2021
890619f
cleans up debugging code runs migrations
tochman Jul 25, 2021
cfacbcb
Merge branch 'develop' into wobranch
tochman Jul 25, 2021
0519718
WIP projects controller spec is failing
tochman Jul 25, 2021
23f0e55
deletes prjects_controller spec
tochman Jul 31, 2021
9f2e1f6
updates project controller and activate/deactivate feature
tochman Jul 31, 2021
a49f993
triggers ci
tochman Jul 31, 2021
9f45664
fixes project edit feature
tochman Aug 1, 2021
a07b8f2
fixes create project feature
tochman Aug 1, 2021
6d5d56d
fixes list projects feature
tochman Aug 1, 2021
362624e
fixes deactivate project feature
tochman Aug 1, 2021
7a4ae56
fixes sidebar feature
tochman Aug 1, 2021
c67841b
fixes activity feed feature
tochman Aug 1, 2021
67e5f58
updates gems brakeman guard puma bootsnap cucumber-rails
tochman Aug 1, 2021
0a807d2
cleans up comments and code
tochman Aug 1, 2021
66025ba
removes end of input in view
tochman Aug 1, 2021
60f3e2d
fixes failing project show before action
tochman Aug 1, 2021
944ed1b
downgrades cucumber-rails due to need for refactoring of tables
tochman Aug 1, 2021
f6d5656
more updates due to opening a faquing pandoras box when you move out-…
tochman Aug 1, 2021
24746b5
created new file in root folder
Aug 5, 2021
ed17310
modified new file in root folder
Aug 5, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
20 changes: 10 additions & 10 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -800,7 +800,7 @@ DEPENDENCIES
config
constant-redefinition
coveralls
cucumber-rails (~> 2.0)
cucumber-rails (= 2.3)
database_cleaner
delorean
derailed_benchmarks
Expand Down
52 changes: 39 additions & 13 deletions app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.'
Expand All @@ -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.'
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
16 changes: 1 addition & 15 deletions app/views/layouts/_sponsors.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,12 @@
<h3>Supporters</h3>
<ul>
<li>
<a href="https://standuply.com/?utm_source=links&utm_medium=agileventures&utm_campaign=partnership" class="sponsorMedal">
<div class="sponsorStandinMedal">
<img alt="Standuply" src="<%= image_path('sponsors/standuply.png') %>">
</div>
</a>
</li>
<li>
<a href="http://craftacademy.se/english" target='new' class="sponsorMedal">
<a href="https://craftacademy.se/english" target='new' class="sponsorMedal">
<div class="sponsorStandinMedal">
<img alt="Craft Academy" src="<%= image_path('sponsors/craft_banner_2.png') %>">
</div>
</a>
</li>
<li>
<a href="https://mooqita.org/" target='new' class="sponsorMedal">
<div class="sponsorStandinMedal">
<img alt="Mooqita" src="<%= image_path('sponsors/mooqita.png') %>">
</div>
</a>
</li>
<li>
<a href="https://smile.amazon.co.uk/ch/1170963-0" target='new' class="sponsorMedal">
<div class="sponsorStandinMedal">
Expand Down
23 changes: 12 additions & 11 deletions app/views/projects/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<div class='row'>
<div class='col-sm-8'>
<%= form_for @project, html: { role: 'form', id: 'project_form' } do |f| %>

<%= awesome_text_field f, :title, placeholder: 'Name' %>
<div id='help-link'>
You can upload an image at
Expand All @@ -11,11 +10,13 @@
</div>
<%= awesome_text_field f, :image_url, placeholder: 'Paste a link to your image here' %>
<%= awesome_text_area f, :description, rows: 10, placeholder: 'Description' %>

<div class='form-group'>
<%= f.label :status %>
<%= f.select :status, %w( Active Closed Pending ), {}, :class => 'form-control input-lg' %>
</div>

<% if current_user.admin? %>
<div class='form-group'>
<%= f.label :status %>
<%= f.select :status, %w( Active Closed Pending ), {}, class: 'form-control input-lg' %>
</div>
<% end %>

<div id='source_repositories' class='form-group'>
<%= f.fields_for :source_repositories do |source_repository| %>
Expand All @@ -42,16 +43,16 @@
<h3>New project checklist</h3>
<p>What to do next:</p>
<ul>
<li>Attend one of the scrums</li>
<li>Share the project with the members</li>
<li>Start a Hangout!</li>
<li>Attend one of the community follow-ups!</li>
<li>Share the project with the community members</li>
<li>Start an omline meeting or live stream!</li>
</ul>
<p>Ready to kick things off?</p>
</div>
<% end %>
<div class='form-group'>
<%= link_to 'Back', (@project.id.nil? ? projects_path : project_path(@project)), :type => 'button', :class => 'btn btn-default'%>
<%= f.submit 'Submit', :class => 'btn btn-default' %>
<%= link_to 'Back', (@project.id.nil? ? projects_path : project_path(@project)), type: 'button', class: 'btn btn-default'%>
<%= f.submit 'Submit', class: 'btn btn-default' %>
</div>
<% end %>
</div>
Expand Down
16 changes: 16 additions & 0 deletions app/views/projects/pending_projects.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<% provide :title, 'Pending Projects' %>
<div class="row">
<div class="col-xs-9">
<h1 id="projects-header">List of Pending Projects</h1>
</div>
</div>

<% if @projects.empty? %>
<p>There are no pending projecs right now&#8230;</p>
<% end %>
<div class="row">
<ul id="project-list" style="list-style: none; padding-left: 0;">
<%= render 'listing' %>
</ul>
</div>
<%= will_paginate @projects %>
59 changes: 34 additions & 25 deletions app/views/projects/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,41 @@
<hr>
<div class="project-edit">
<% if user_signed_in? %>
<% if current_user.admin? %>
<% if @project.status == 'pending' %>
<%= form_tag(activate_project_path(@project)) do %>
<%= button_tag(type: 'submit' , class: 'btn btn-primary') do %>
Activate Project </i>
<% end %>
<% end %>
<% else %>
<%= form_tag(deactivate_project_path(@project)) do %>
<%= button_tag(type: 'submit' , class: 'btn btn-danger') do %>
Deactivate Project</i>
<% end %>
<% end %>
<% end %>
<% end %>
<ul class="list-inline">
<% if current_user.following?(@project) %>
<li class="dropdown">
<button class="btn btn-default dropdown-toggle" type="button" id="actions-dropdown" data-toggle="dropdown">
Project Actions
<span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu" aria-labelledby="actions-dropdown">
<li role="presentation">
<a role="menuitem" tabindex="-1" href="<%= edit_project_path(@project) %>">Edit Project Details</a></li>
<li role="presentation">
<a role="menuitem" tabindex="-1" href="<%= new_project_document_path(project_id: @project.friendly_id) %>">Create new document</a></li>
<li role="presentation" class="divider"></li>
<li role="presentation">
<a role="menuitem" tabindex="-1" href="<%= unfollow_project_path(@project) %>">Leave Project</a>
</li>
</ul>
</li>
<li class="hangout-btn">
<%= button_to 'Start Hangout Instructions', 'https://support.google.com/youtube/answer/7083786', id: 'hoa_instructions', class: "btn btn-primary", form: {target: '_blank'} %>
<li class="dropdown">
<button class="btn btn-default dropdown-toggle" type="button" id="actions-dropdown" data-toggle="dropdown">
Project Actions
<span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu" aria-labelledby="actions-dropdown">
<li role="presentation">
<a role="menuitem" tabindex="-1" href="<%= edit_project_path(@project) %>">Edit Project Details</a></li>
<li role="presentation">
<a role="menuitem" tabindex="-1" href="<%= new_project_document_path(project_id: @project.friendly_id) %>">Create new document</a></li>
<li role="presentation" class="divider"></li>
<li role="presentation">
<a role="menuitem" tabindex="-1" href="<%= unfollow_project_path(@project) %>">Leave Project</a>
</li>
</ul>
</li>
</ul>
<hr>
</ul>
<hr>
<% else %>
<div>
<button type="button" class="btn btn-warning" data-toggle="modal" data-target="#myModal">
Expand Down Expand Up @@ -111,11 +123,8 @@
<% unless @project.pitch.nil? %>
<%= clean_html(@project.pitch) %>
<% else %>
<p><b>Project content missing :(</b></p>

<p>A compelling pitch can make your project
<a href="https://www.kickstarter.com/discover/categories/technology?ref=discover_index">more
appealing</a> to potential collaborators. Please add a README to your project in GitHub.</p>
<p><b>Project content missing</b></p>
<p>A compelling pitch can make your project more appealing to potential collaborators. Please add a README to your project in GitHub.</p>
<% end %>
</div>
<div class="tab-pane" id="documents_list">
Expand Down
7 changes: 5 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,18 @@ def loaderio_token
get :mercury_saved
get :follow
get :unfollow
post :activate, action: :update, defaults: { command: 'activate' }
post :deactivate, action: :update, defaults: { command: 'deactivate' }
end

resources :documents, except: %i(edit update), format: false do
put :mercury_update
get :mercury_saved
end

resources :events, only: [:index]
end
get :pending_projects, controller: :projects, action: :index, defaults: { status: 'pending' }

resources :events do
member do
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20210721093118_add_admin_to_users.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddAdminToUsers < ActiveRecord::Migration[6.1]
def change
add_column :users, :admin, :boolean
end
end
Loading