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



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

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



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

def deny_access(exception)
  if current_user && 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



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

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

#validate_usersObject



37
38
39
# File 'app/controllers/concerns/sufia/depositors_controller_behavior.rb', line 37

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