Sha256: b9fe68707841457ba1b5d6920675c8eff42a8f065d12283aa24f78ac7f886f95

Contents?: true

Size: 1.19 KB

Versions: 16

Compression:

Stored size: 1.19 KB

Contents

# frozen_string_literal: true

require "zip"

module Decidim
  # The controller to handle the user's download_my_data page.
  class DataPortabilityController < Decidim::ApplicationController
    include Decidim::UserProfile

    def show
      enforce_permission_to :show, :user, current_user: current_user

      @account = form(AccountForm).from_model(current_user)
    end

    def export
      enforce_permission_to :export, :user, current_user: current_user

      DataPortabilityExportJob.perform_later(current_user)

      flash[:notice] = t("decidim.account.data_portability_export.notice")
      redirect_back(fallback_location: data_portability_path)
    end

    def download_file
      enforce_permission_to :download, :user, current_user: current_user

      if data_portability_file_exists?
        redirect_to uploader.url
      else
        flash[:error] = t("decidim.account.data_portability_export.file_no_exists")
        redirect_to data_portability_path
      end
    end

    private

    def data_portability_file_exists?
      uploader.file.exists?
    rescue StandardError
      false
    end

    def uploader
      current_user.data_portability_file(params[:filename])
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
decidim-core-0.24.3 app/controllers/decidim/data_portability_controller.rb
decidim-core-0.23.6 app/controllers/decidim/data_portability_controller.rb
decidim-core-0.24.2 app/controllers/decidim/data_portability_controller.rb
decidim-core-0.23.5 app/controllers/decidim/data_portability_controller.rb
decidim-core-0.24.1 app/controllers/decidim/data_portability_controller.rb
decidim-core-0.24.0 app/controllers/decidim/data_portability_controller.rb
decidim-core-0.24.0.rc2 app/controllers/decidim/data_portability_controller.rb
decidim-core-0.23.4 app/controllers/decidim/data_portability_controller.rb
decidim-core-0.24.0.rc1 app/controllers/decidim/data_portability_controller.rb
decidim-core-0.23.3 app/controllers/decidim/data_portability_controller.rb
decidim-core-0.23.2 app/controllers/decidim/data_portability_controller.rb
decidim-core-0.23.1 app/controllers/decidim/data_portability_controller.rb
decidim-core-0.23.1.rc1 app/controllers/decidim/data_portability_controller.rb
decidim-core-0.23.0 app/controllers/decidim/data_portability_controller.rb
decidim-core-0.22.0 app/controllers/decidim/data_portability_controller.rb
decidim-core-0.21.0 app/controllers/decidim/data_portability_controller.rb