Class: Admin::DocumentAccessesController

Inherits:
AdminController
  • Object
show all
Defined in:
app/controllers/admin/document_accesses_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

POST /document_accesses POST /document_accesses.json



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/controllers/admin/document_accesses_controller.rb', line 35

def create
  @document_access = DocumentAccess.new(document_access_params)
  logger.debug("DA Params: #{DocumentAccess.new(document_access_params).inspect}")
  logger.debug("Document ACCESS: #{@document_access.inspect}")

  respond_to do |format|
    if @document_access.save
      format.html do
        redirect_to admin_document_document_accesses_path(@document), notice: "Document access was successfully created."
      end
      format.json { render :show, status: :created, location: @document_access }
    else
      format.html { render :new }
      format.json { render json: @document_access.errors, status: :unprocessable_entity }
    end
  end
end

#destroyObject

DELETE /document_accesses/1 DELETE /document_accesses/1.json



71
72
73
74
75
76
77
78
79
# File 'app/controllers/admin/document_accesses_controller.rb', line 71

def destroy
  @document_access.destroy
  respond_to do |format|
    format.html do
      redirect_to admin_document_document_accesses_path(@document), notice: "Document access was successfully destroyed."
    end
    format.json { head :no_content }
  end
end

#destroy_allObject



81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'app/controllers/admin/document_accesses_controller.rb', line 81

def destroy_all
  logger.debug("Destroy Access Links")
  return unless params.dig(:document_access, :assets, :file)

  respond_to do |format|
    if DocumentAccess.destroy_all(params.dig(:document_access, :assets, :file))
      format.html { redirect_to admin_document_accesses_path, notice: "Document Access Links were created destroyed." }
    else
      format.html { redirect_to admin_document_accesses_path, notice: "Document Access Links could not be destroyed." }
    end
  rescue => e
    format.html { redirect_to admin_document_accesses_path, notice: "Document Access Links could not be destroyed. #{e}" }
  end
end

#editObject

GET /document_accesses/1/edit



30
31
# File 'app/controllers/admin/document_accesses_controller.rb', line 30

def edit
end

#importObject

GET /documents/#id/access/import POST /documents/#id/access/import



98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'app/controllers/admin/document_accesses_controller.rb', line 98

def import
  logger.debug("Import Action")
  return unless params.dig(:document_access, :assets, :file)

  respond_to do |format|
    if DocumentAccess.import(params.dig(:document_access, :assets, :file))
      format.html { redirect_to admin_document_accesses_path, notice: "Document access links were created successfully." }
    else
      format.html { redirect_to admin_document_accesses_path, notice: "Access URLs could not be created." }
    end
  rescue => e
    format.html { redirect_to admin_document_accesses_path, notice: "Access URLs could not be created. #{e}" }
  end
end

#indexObject

GET /documents/#id/access GET /documents/#id/access.json



11
12
13
14
15
16
17
# File 'app/controllers/admin/document_accesses_controller.rb', line 11

def index
  if params[:document_id]
    @document_accesses = DocumentAccess.where(friendlier_id: @document.friendlier_id).order(institution_code: :asc)
  else
    @pagy, @document_accesses = pagy(DocumentAccess.all.order(friendlier_id: :asc, updated_at: :desc), items: 20)
  end
end

#newObject

GET /document_accesses/new



25
26
27
# File 'app/controllers/admin/document_accesses_controller.rb', line 25

def new
  @document_access = DocumentAccess.new
end

#showObject

GET /document_accesses/1 GET /document_accesses/1.json



21
22
# File 'app/controllers/admin/document_accesses_controller.rb', line 21

def show
end

#updateObject

PATCH/PUT /document_accesses/1 PATCH/PUT /document_accesses/1.json



55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'app/controllers/admin/document_accesses_controller.rb', line 55

def update
  respond_to do |format|
    if @document_access.update(document_access_params)
      format.html do
        redirect_to admin_document_document_accesses_path(@document), notice: "Document access was successfully updated."
      end
      format.json { render :show, status: :ok, location: @document_access }
    else
      format.html { render :edit }
      format.json { render json: @document_access.errors, status: :unprocessable_entity }
    end
  end
end