Skip to content

Commit

Permalink
Merge pull request #3784 from wordhouse66/wobranch
Browse files Browse the repository at this point in the history
Admin based Project approval flow
  • Loading branch information
tochman authored Aug 8, 2021
2 parents 0588073 + ed17310 commit fd9716a
Show file tree
Hide file tree
Showing 31 changed files with 656 additions and 395 deletions.
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

0 comments on commit fd9716a

Please sign in to comment.