Module: Sufia::DepositorsControllerBehavior

Extended by:
ActiveSupport::Concern
Included in:
DepositorsController
Defined in:
app/controllers/concerns/sufia/depositors_controller_behavior.rb

Instance Method Summary collapse

Instance Method Details

#createObject



21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/concerns/sufia/depositors_controller_behavior.rb', line 21

def create
  grantor = authorize_and_return_grantor
  grantee = ::User.from_url_component(params[:grantee_id])
  if grantor.can_receive_deposits_from.include?(grantee)
    head :ok
  else
    grantor.can_receive_deposits_from << grantee
    render json: { name: grantee.name, delete_path: sufia.user_depositor_path(grantor.user_key, grantee.user_key) }
  end
end

#deny_access(exception) ⇒ Object

Overriding the default behavior from Hydra::Core::ContorllerBehavior



12
13
14
15
16
17
18
19
# File 'app/controllers/concerns/sufia/depositors_controller_behavior.rb', line 12

def deny_access(exception)
  if current_user and current_user.persisted?
    redirect_to root_path, alert: exception.message
  else
    session['user_return_to'.freeze] = request.url
    redirect_to new_user_session_path, alert: exception.message
  end
end

#destroyObject



32
33
34
35
36
# File 'app/controllers/concerns/sufia/depositors_controller_behavior.rb', line 32

def destroy
  grantor = authorize_and_return_grantor
  grantor.can_receive_deposits_from.delete(::User.from_url_component(params[:id]))
  head :ok
end

#validate_usersObject



38
39
40
41
42
# File 'app/controllers/concerns/sufia/depositors_controller_behavior.rb', line 38

def validate_users
  if params[:user_id] == params[:grantee_id]
    head :ok
  end
end