diff options
| author | Alban Peignier | 2016-11-20 16:37:25 +0100 | 
|---|---|---|
| committer | Alban Peignier | 2016-11-20 16:40:57 +0100 | 
| commit | 35e226ad25d9d88018012310ce2649ce65121478 (patch) | |
| tree | 50e1ab26b0a2868599e6e1e9d1388e3d08a185dd | |
| parent | 938bf0d6d573332dc4ec9a2cf34c839d8611d41d (diff) | |
| download | chouette-core-35e226ad25d9d88018012310ce2649ce65121478.tar.bz2 | |
Disable Referenial unarchive action when Referential overlaps other referentials. Refs #1864
| -rw-r--r-- | app/controllers/referentials_controller.rb | 9 | ||||
| -rw-r--r-- | app/models/referential.rb | 9 | ||||
| -rw-r--r-- | app/views/workbenches/show.html.slim | 5 | ||||
| -rw-r--r-- | config/locales/referentials.fr.yml | 1 | 
4 files changed, 21 insertions, 3 deletions
| diff --git a/app/controllers/referentials_controller.rb b/app/controllers/referentials_controller.rb index dbf753794..b7e6d8031 100644 --- a/app/controllers/referentials_controller.rb +++ b/app/controllers/referentials_controller.rb @@ -53,8 +53,13 @@ class ReferentialsController < BreadcrumbController      redirect_to workbench_path(referential.workbench_id), notice: t('notice.referential.archived')    end    def unarchive -    referential.unarchive! -    redirect_to workbench_path(referential.workbench_id), notice: t('notice.referential.unarchived') +    if referential.unarchive! +      flash[:notice] = t('notice.referential.unarchived') +    else +      flash[:alert] = t('notice.referential.unarchived_failed') +    end + +    redirect_to workbench_path(referential.workbench_id)    end    protected diff --git a/app/models/referential.rb b/app/models/referential.rb index afff89892..be7c15535 100644 --- a/app/models/referential.rb +++ b/app/models/referential.rb @@ -234,6 +234,10 @@ class Referential < ActiveRecord::Base      self.class.connection.select_values(query).map(&:to_i)    end +  def metadatas_overlap? +    overlapped_referential_ids.present? +  end +    validate :detect_overlapped_referentials    def detect_overlapped_referentials @@ -313,8 +317,13 @@ class Referential < ActiveRecord::Base      touch :archived_at    end    def unarchive! +    return false unless can_unarchive?      # self.archived = false      update_column :archived_at, nil    end +  def can_unarchive? +    not metadatas_overlap? +  end +  end diff --git a/app/views/workbenches/show.html.slim b/app/views/workbenches/show.html.slim index 978af1538..06f64d3c4 100644 --- a/app/views/workbenches/show.html.slim +++ b/app/views/workbenches/show.html.slim @@ -56,7 +56,10 @@                  li                    - if referential.archived? -                    = link_to "Désarchiver", unarchive_referential_path(referential), method: :put +                    - if referential.can_unarchive? +                      = link_to "Désarchiver", unarchive_referential_path(referential), method: :put +                    - else +                      = link_to "Désarchiver", "#"                    - else                      = link_to "Archiver", archive_referential_path(referential), method: :put diff --git a/config/locales/referentials.fr.yml b/config/locales/referentials.fr.yml index 02848ec64..dc3d796b8 100644 --- a/config/locales/referentials.fr.yml +++ b/config/locales/referentials.fr.yml @@ -84,4 +84,5 @@ fr:      referential:        archived: "L'espace de données a été correctement archivé"        unarchived: "L'espace de données a été correctement désarchivé" +      unarchived_failed: "L'espace de données ne peut être désarchivé"        deleted: "L'espace de données a été correctement supprimé" | 
