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

Add a (information) validity attribute to cards #53

Merged
merged 6 commits into from
Dec 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
22 changes: 8 additions & 14 deletions app/controllers/users/cards_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,20 @@ class Users::CardsController < ApplicationController
layout "admin"

def edit
@confirm = params[:confirm]
@confirmed = params[:confirmed]

@confirmed = params[:confirmed] == "true"
@card = card
end

def update
@card = card
@card.last_updated = Time.current

if @card.update(card_params)
if params[:confirmed]
redirect_to edit_users_card_path(@card, confirmed:true), success: "Ton groupe a été mis à jour"
else
redirect_to edit_users_card_path(@card), success: "Ton groupe a été mis à jour"
end
@card.assign_attributes(card_params)
was_outdated = !@card.maintained?
if @card.valid?
@card.last_updated = Time.current
@card.validity = :maintained
@card.save
redirect_to edit_users_card_path(@card, confirmed: was_outdated), success: "Ton groupe a été mis à jour"
else
if params[:confirmed]
@confirming = true
end
render 'edit'
end
end
Expand Down
1 change: 1 addition & 0 deletions app/models/card.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class Card < ApplicationRecord

enum card_type: [:youth, :adult, :activist, :organization, :network, :training]
enum status: [:pending, :online, :incomplete, :change]
enum validity: [:maintained, :solicited, :disabled]

belongs_to :location, optional: true # validation made manually according to the step
belongs_to :user
Expand Down
12 changes: 12 additions & 0 deletions app/views/users/cards/_confirmed.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<div data-controller="popup">
<div class="standard-popup active" data-popup-target="content">
<div class="content">

<p>Merci d'avoir confirmé ton groupe. Aucune autre action de ta part n'est nécessaire.</p>

<div class="buttons">
<button class="cancel" type="button" data-action="popup#close">Fermer</button>
</div>
</div>
</div>
</div>
13 changes: 13 additions & 0 deletions app/views/users/cards/_outdated.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<div data-controller="popup">
<div class="standard-popup active" data-popup-target="content">
<div class="content">

<p>Merci de vérifier (et mettre à jour si nécessaire) les informations de ton groupe.</p>
<p>Quand tu as fini, clique sur le bouton <b>"Sauvegarder et mettre à jour"</b>, même si tu n'a fait aucun changement.</p>

<div class="buttons">
<button class="cancel" type="button" data-action="popup#close">Fermer</button>
</div>
</div>
</div>
</div>
37 changes: 3 additions & 34 deletions app/views/users/cards/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,10 @@
<%= link_to "Voir le groupe", card_path(@card) %>
<% end %>

<% if @confirm %>
<div data-controller="popup">
<div class="standard-popup active" data-popup-target="content">
<div class="content">

<p>Merci de vérifier (et mettre à jour si nécessaire) les information de ton groupe.</p>
<p>Quand tu as fini, clique sur le bouton <b>"Sauvegarder et mettre à jour"</b>, même si tu n'a fait aucune mise à jour.</p>

<div class="buttons">
<button class="cancel" type="button" data-action="popup#close">Fermer</button>
</div>
</div>
</div>
</div>
<% end %>

<% if @confirmed %>
<div data-controller="popup">
<div class="standard-popup active" data-popup-target="content">
<div class="content">

<p>Merci d'avoir confirmé ton groupe. Aucune autre action de ta part n'est nécessaire.</p>

<div class="buttons">
<button class="cancel" type="button" data-action="popup#close">Fermer</button>
</div>
</div>
</div>
</div>
<% end %>
<%= render "outdated" if !@card.maintained? %>

<%= render "confirmed" if @confirmed %>

<section class="std-container top-container">
<div class="left">
<div class="title red">
Expand Down Expand Up @@ -71,10 +44,6 @@

<%= render "error_messages", object: f.object %>

<% if @confirm || @confirming %>
<%= hidden_field_tag 'confirmed', true %>
<% end %>

<section class="std-container content-container">

<div class="left">
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20211219170017_add_validity_to_cards.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddValidityToCards < ActiveRecord::Migration[6.0]
def change
add_column :cards, :validity, :integer, default: 0
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2021_11_06_163807) do
ActiveRecord::Schema.define(version: 2021_12_19_170017) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -112,6 +112,7 @@
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.datetime "last_updated"
t.integer "validity", default: 0
t.index ["location_id"], name: "index_cards_on_location_id"
t.index ["user_id"], name: "index_cards_on_user_id"
end
Expand Down
3 changes: 2 additions & 1 deletion features/cards/edit.feature
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Feature: update a card
Feature: Update a card

So that the card's information are update
as the owner
Expand All @@ -13,6 +13,7 @@ Feature: update a card
When I visit the card's update page
And I update the card's name with "Spacestation"
Then I should see "Spacestation"
And I should not see "Merci d'avoir confirmé ton groupe"

Scenario: I update the card with an error
When I visit the card's update page
Expand Down
25 changes: 25 additions & 0 deletions features/cards/validity.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Feature: Confirm the validity of a card

So that my card is not disabled
as the owner
I want to update the card

Background:
Given I am a confirmed user
And I am signed in

Scenario: The card is up-to-date
Given I have a complete card
When I visit the card's update page
Then I should not see "Merci de vérifier"

Scenario: The owner received a request to confirm the card
Given I have a card that must be confirmed
When I visit the card's update page
Then I should see "Merci de vérifier"

Scenario: I update an card after a request
Given I have a card that must be confirmed
When I visit the card's update page
And I click the button "Sauvegarder et mettre à jour"
Then I should see "Merci d'avoir confirmé ton groupe"
4 changes: 4 additions & 0 deletions features/step_definitions/cards/confirmation_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
@card = create(:card, user: @user)
end

Given('I have a card that must be confirmed') do
@card = create(:card, user: @user, validity: :solicited)
end

Given("I have an incomplete card") do
visit "/cards/wizards/new"
step "I complete the first step and submit it"
Expand Down
5 changes: 3 additions & 2 deletions lib/tasks/cards_update_check.rake
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@ namespace :cards_update do

if step == 4
# => To be implemented in model
#card.deactivated = true
#card.save
card.update_attribute(:validity, :disabled)

Admin::CardMailer.deactivated(card).deliver_now
end

if step != -1
card.update_attribute(:validity, :outdated) if step < 4 && !@card.outdated

CardMailer.update_check(card, step).deliver_now
end
end
Expand Down
1 change: 1 addition & 0 deletions spec/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
location { Location.find_by_official_name("Bulle") || create(:location) }
card_type { :youth }
status { :online }
validity { :maintained }
end

factory :location do
Expand Down