Skip to content

Commit

Permalink
Merge branch 'main' into ROAD-534-add-approved-attribute-to-stories
Browse files Browse the repository at this point in the history
  • Loading branch information
mateusdeap authored Oct 11, 2023
2 parents 85d21ed + f6bc154 commit c934650
Show file tree
Hide file tree
Showing 12 changed files with 109 additions and 73 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ gem "jquery-rails"

gem "pg"

gem "jquery-ui-rails", "~> 5.0", ">= 5.0.5"
gem "jquery-ui-rails", "~> 6.0"
gem "acts_as_list"

gem "mimemagic", "~> 0.3.8"
Expand Down
46 changes: 24 additions & 22 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ GEM
tzinfo (~> 2.0)
acts_as_list (1.1.0)
activerecord (>= 4.2)
addressable (2.8.1)
addressable (2.8.5)
public_suffix (>= 2.0.2, < 6.0)
ast (2.4.2)
autoprefixer-rails (10.4.13.0)
Expand Down Expand Up @@ -146,7 +146,7 @@ GEM
globalid (1.1.0)
activesupport (>= 5.0)
hashie (5.0.0)
i18n (1.12.0)
i18n (1.14.1)
concurrent-ruby (~> 1.0)
jbuilder (2.11.5)
actionview (>= 5.0.0)
Expand All @@ -155,7 +155,7 @@ GEM
rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
jquery-ui-rails (5.0.5)
jquery-ui-rails (6.0.1)
railties (>= 3.2.16)
json (2.6.3)
jwt (2.7.0)
Expand All @@ -165,9 +165,9 @@ GEM
listen (3.8.0)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
loofah (2.19.1)
loofah (2.21.3)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
nokogiri (>= 1.12.0)
madmin (1.2.7)
pagy (>= 3.5, < 6.0)
rails (>= 6.0.3)
Expand All @@ -182,8 +182,8 @@ GEM
mimemagic (0.3.10)
nokogiri (~> 1)
rake
mini_mime (1.1.2)
minitest (5.18.0)
mini_mime (1.1.5)
minitest (5.20.0)
multi_xml (0.6.0)
net-imap (0.3.4)
date
Expand All @@ -198,11 +198,11 @@ GEM
next_rails (1.2.2)
colorize (>= 0.8.1)
nio4r (2.5.9)
nokogiri (1.14.3-arm64-darwin)
nokogiri (1.15.4-arm64-darwin)
racc (~> 1.4)
nokogiri (1.14.3-x86_64-darwin)
nokogiri (1.15.4-x86_64-darwin)
racc (~> 1.4)
nokogiri (1.14.3-x86_64-linux)
nokogiri (1.15.4-x86_64-linux)
racc (~> 1.4)
oauth2 (2.0.9)
faraday (>= 0.17.3, < 3.0)
Expand Down Expand Up @@ -237,13 +237,13 @@ GEM
parser (3.2.1.1)
ast (~> 2.4.1)
pg (1.4.6)
public_suffix (5.0.1)
public_suffix (5.0.3)
puma (6.3.1)
nio4r (~> 2.0)
pundit (2.3.0)
activesupport (>= 3.0.0)
racc (1.6.2)
rack (2.2.6.4)
racc (1.7.1)
rack (2.2.8)
rack-mini-profiler (3.0.0)
rack (>= 1.2.0)
rack-protection (3.0.5)
Expand All @@ -268,11 +268,13 @@ GEM
actionpack (>= 5.0.1.rc1)
actionview (>= 5.0.1.rc1)
activesupport (>= 5.0.1.rc1)
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
rails-dom-testing (2.2.0)
activesupport (>= 5.0.0)
minitest
nokogiri (>= 1.6)
rails-html-sanitizer (1.5.0)
loofah (~> 2.19, >= 2.19.1)
rails-html-sanitizer (1.6.0)
loofah (~> 2.21)
nokogiri (~> 1.14)
railties (7.0.4.3)
actionpack (= 7.0.4.3)
activesupport (= 7.0.4.3)
Expand All @@ -287,7 +289,7 @@ GEM
ffi (~> 1.0)
recursive-open-struct (1.1.3)
redcarpet (3.5.1)
regexp_parser (2.7.0)
regexp_parser (2.8.1)
responders (3.1.0)
actionpack (>= 5.2)
railties (>= 5.2)
Expand Down Expand Up @@ -369,7 +371,7 @@ GEM
rubocop-performance (~> 1.16.0)
standardrb (1.0.1)
standard
thor (1.2.1)
thor (1.2.2)
tilt (2.1.0)
timeout (0.3.2)
turbolinks (5.2.1)
Expand All @@ -393,12 +395,12 @@ GEM
rubyzip (>= 1.3.0)
selenium-webdriver (~> 4.0)
websocket (1.2.9)
websocket-driver (0.7.5)
websocket-driver (0.7.6)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
xpath (3.2.0)
nokogiri (~> 1.8)
zeitwerk (2.6.7)
zeitwerk (2.6.12)

PLATFORMS
arm64-darwin-22
Expand All @@ -420,7 +422,7 @@ DEPENDENCIES
faker
jbuilder (~> 2.5)
jquery-rails
jquery-ui-rails (~> 5.0, >= 5.0.5)
jquery-ui-rails (~> 6.0)
listen (~> 3.7)
madmin (~> 1.2)
matrix
Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
//= require jquery
//= require bootstrap-sprockets
//= require jquery-ui/widget
//= require jquery-ui/sortable
//= require jquery-ui/widgets/sortable
//= require turbolinks
//= require clipboard.min
//= require sortable_list
Expand Down
19 changes: 1 addition & 18 deletions app/assets/stylesheets/project.scss
Original file line number Diff line number Diff line change
Expand Up @@ -267,24 +267,7 @@
i {
position: relative;
border-radius: 50%;
padding: 5px;
opacity: 0;
transition: transform 0.5s, opacity 0.5s;
transform: translateX(-100%);
}

&:hover {
i {
opacity: 1;
transform: translateX(0);
}
}

&:active {
i {
background: #f70a7c;
color: white;
}
padding-right: 5px;
}
}

Expand Down
8 changes: 6 additions & 2 deletions app/assets/stylesheets/stories.scss
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@
padding-bottom: 1.3em;
}

.modal strong {
font-weight: bold;
}

.new_story,
.edit_story {
display: grid;
Expand Down Expand Up @@ -125,8 +129,8 @@
.popup {
display: none;
position: absolute;
top: 5px;
left: 30px;
right: 30px;
z-index: 50;
background: #d9f1f1;
height: 30px;
width: 140px;
Expand Down
15 changes: 12 additions & 3 deletions app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class ProjectsController < ApplicationController
before_action :authenticate_user!
before_action :find_project, only: [:show, :edit, :update, :sort, :sort_stories, :destroy, :new_sub_project, :toggle_archive, :toggle_locked]
before_action :find_project, only: [:show, :edit, :update, :sort, :sort_stories, :destroy, :new_sub_project, :toggle_archive, :toggle_locked, :open_delete_modal]
before_action :ensure_unarchived!, only: [:edit, :new_sub_project, :update]

def index
Expand Down Expand Up @@ -70,9 +70,14 @@ def create
end

def destroy
@project.destroy
respond_to do |format|
format.html { redirect_to projects_path, notice: "Project was successfully destroyed." }
if @project.title.strip.eql?(params.dig(:project, :title)&.strip)
@project.destroy
flash[:success] = "Project was successfully destroyed."
else
flash[:error] = "Make sure you added the correct project's title"
end
format.html { redirect_to projects_path }
end
end

Expand Down Expand Up @@ -104,6 +109,10 @@ def new_sub_project
@sub = Project.new(parent_id: @project)
end

# GET /projects/1/open_delete_modal.js
def open_delete_modal
end

private

def find_project
Expand Down
12 changes: 12 additions & 0 deletions app/views/projects/_delete_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<%= form_with(model: project, method: :delete) do |f| %>
This action cannot be undone.
This will permanently delete the <strong><%= project.title %></strong> project,
stories, and associated estimations.

<div class="field">
<%= f.label :title, raw("Please type <strong>#{project.title}</strong> to confirm.") %>
<%= f.text_field :title, value: "", placeholder: "Project's title", autofocus: true, required: true %>
</div>

<%= f.submit "I understand the consequences, delete this project", class: "button magenta" %>
<% end %>
3 changes: 3 additions & 0 deletions app/views/projects/open_delete_modal.js.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(function(){
showModal("Are you absolutely sure?", "<%= j(render('delete_form', project: @project)) %>")
})()
16 changes: 6 additions & 10 deletions app/views/projects/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
<% @stories.each do | story | %>
<tr class="project-table__row project-table__row--story" id="<%= dom_id(story)%>" data-status="<%= story.status %>">
<td class="project-table__cell">
<span class="popup">Copied to clipboard</span>
<input type="checkbox" name="stories[]" value="<%= story.id %>">
<%= link_to "#{story.id} - #{story.title}", [story.project, story] %>
<button class="copy-link btn-clipboard" data-clipboard-text="<%= project_story_url(@project, story) %>" title='Copy story'><i class="fa fa-link"></i><span class= "popup">Copied to clipboard</span></button>
</td>
<td class="project-table__cell status"><%= status_label(story) %></td>
<td class="project-table__cell" id="best_estimate_<%= story.id %>"><%= story.estimate_for(current_user)&.best_case_points %></td>
Expand All @@ -48,6 +48,10 @@
<i class="fa fa-ellipsis-v"></i>
</button>
<div class="dropdown">

<button class="copy-link btn-clipboard" data-clipboard-text="<%= project_story_url(@project, story) %>" title='Copy story'>
<i class="fa fa-link"></i>Copy Link</button>

<%= link_unless_archived(@project, "Edit", edit_project_story_path(@project, story), classes: "edit", icon: 'pencil-square-o') %>

<% if @siblings.any? %>
Expand All @@ -65,12 +69,6 @@
<% end %>

<%= link_unless_archived(@project, "Delete", project_story_path(@project.id, story), classes: "delete", icon: 'trash-o', method: :delete, remote: true, data_attr: { confirm: 'Are you sure?', story_id: story.id }) %>

<% link_to new_project_story_path(@project.id, story_id: story.id), class: "clone", title: "Clone" do %>
<i class="fa fa-files-o"></i>
<span>Clone</span>
<% end %>

<%= link_unless_archived(@project, "Clone", new_project_story_path(@project.id, story_id: story.id), classes: "clone", icon: 'files-o') %>
</div>
</div>
Expand Down Expand Up @@ -105,17 +103,15 @@

<div class="btn-group actions">
<%= link_to 'Return to Projects Page', projects_path, id: :back, class: "button" %>

<% if current_user.admin? %>
<%= button_to is_unlocked?(@project) ? 'Lock Project' : 'Unlock Project', toggle_locked_project_path(@project.id), method: :patch, class: "button magenta", id: "lock-btn", remote: true %>
<% end %>

<%= link_to 'Clone Project', new_clone_project_path(@project.id), class: "button green" %>
<%= link_to 'Edit Project', edit_project_path(@project.id), class: "button green" %>

<% if is_unlocked?(@project) %>
<%= link_unless_archived(@project, "Add Sub-Project", project_new_sub_project_path(@project), classes: :green) unless @project.parent_id.present? %>
<%= link_unless_archived(@project, "Delete Project", project_path(@project.id), classes: "delete magenta", method: :delete, remote: true, data_attr: { confirm: 'Are you sure?' }, id: "delete") %>
<%= link_unless_archived(@project, "Delete Project", open_delete_modal_project_path(@project.id), classes: "delete magenta", remote: true) %>
<% end %>

<% unless @project.parent_id %>
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
patch :toggle_locked
get :new_clone
post :clone
get :open_delete_modal
end
get :new_sub_project

Expand Down
28 changes: 27 additions & 1 deletion spec/controllers/projects_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,35 @@
describe "#destroy" do
it "deletes the project" do
expect {
delete :destroy, params: {id: project.id}
delete :destroy, params: {id: project.id, project: {title: project.title}}
}.to change(Project, :count).by(-1)
end

it "deletes stripped project's title" do
project.update(title: " foo bar ")
expect {
delete :destroy, params: {id: project.id, project: {title: "foo bar"}}
}.to change(Project, :count).by(-1)
end

it "deletes stripped project's params" do
project.update(title: "foo bar")
expect {
delete :destroy, params: {id: project.id, project: {title: "foo bar "}}
}.to change(Project, :count).by(-1)
end

it "does not delete the project" do
expect {
delete :destroy, params: {id: project.id}
}.not_to change(Project, :count)
end

it "does not delete the project when the title does not match" do
expect {
delete :destroy, params: {id: project.id, project: {title: "random title"}}
}.not_to change(Project, :count)
end
end

describe "#show" do
Expand Down
Loading

0 comments on commit c934650

Please sign in to comment.