Class: Decidim::Kids::AuthorizationsController

Inherits:
Verifications::AuthorizationsController
  • Object
show all
Includes:
NeedsTutorAuthorization, UserProfile
Defined in:
app/controllers/decidim/kids/authorizations_controller.rb

Instance Method Summary collapse

Instance Method Details

#authorizations_path(prs = {}) ⇒ Object



13
14
15
# File 'app/controllers/decidim/kids/authorizations_controller.rb', line 13

def authorizations_path(prs = {})
  decidim_kids.user_minor_authorizations_path(prs)
end

#createObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/controllers/decidim/kids/authorizations_controller.rb', line 36

def create
  if minor_authorized?
    flash[:notice] = t("authorizations.authorize.already_authorized", scope: "decidim.kids")
    return redirect_to decidim_kids.user_minors_path
  end

  AuthorizeMinor.call(handler) do
    on(:ok) do
      flash[:notice] = t("authorizations.authorize.success", scope: "decidim.kids")
      redirect_to redirect_url || authorizations_path
    end

    on(:transferred) do
      flash[:notice] = t("authorizations.authorize.success", scope: "decidim.kids")
      redirect_to redirect_url || authorizations_path
    end

    on(:invalid_age) do
      flash[:alert] = t("authorizations.create.invalid_age", scope: "decidim.kids")
      render action: :new
    end

    on(:invalid) do
      flash[:alert] = t("authorizations.authorize.error", scope: "decidim.kids")
      render action: :new
    end
  end
end

#handler_nameObject



69
70
71
# File 'app/controllers/decidim/kids/authorizations_controller.rb', line 69

def handler_name
  current_organization.minors_authorization
end

#handler_paramsObject



65
66
67
# File 'app/controllers/decidim/kids/authorizations_controller.rb', line 65

def handler_params
  (params[:authorization_handler] || {}).merge(user: minor_user)
end

#indexObject



17
18
19
20
21
22
23
24
25
# File 'app/controllers/decidim/kids/authorizations_controller.rb', line 17

def index
  if minor_authorized?
    # TODO: unblock user, update personal data
    flash[:notice] = t("authorizations.authorize.success", scope: "decidim.kids")
  else
    flash[:alert] = t("authorizations.authorize.error", scope: "decidim.kids")
  end
  redirect_to decidim_kids.user_minors_path
end

#minor_authorized?Boolean

Returns:

  • (Boolean)


77
78
79
# File 'app/controllers/decidim/kids/authorizations_controller.rb', line 77

def minor_authorized?
  minor_authorization(minor_user).present?
end

#minor_userObject



73
74
75
# File 'app/controllers/decidim/kids/authorizations_controller.rb', line 73

def minor_user
  current_user.minors.find(params[:user_minor_id])
end

#newObject



27
28
29
30
31
32
33
34
# File 'app/controllers/decidim/kids/authorizations_controller.rb', line 27

def new
  if minor_authorized?
    flash[:notice] = t("authorizations.authorize.already_authorized", scope: "decidim.kids")
    redirect_to decidim_kids.user_minors_path
  else
    super
  end
end