Class: Decidim::DirectVerifications::Verification::Admin::DirectVerificationsController

Inherits:
Admin::ApplicationController
  • Object
show all
Includes:
NeedsPermission
Defined in:
app/controllers/decidim/direct_verifications/verification/admin/direct_verifications_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/controllers/decidim/direct_verifications/verification/admin/direct_verifications_controller.rb', line 16

def create
  enforce_permission_to :create, UserProcessor

  @userlist = params[:userlist]
  processor = UserProcessor.new(current_organization, current_user)
  processor.emails = extract_emails_to_hash @userlist
  processor.authorization_handler = params[:authorization_handler] if params[:authorization_handler]
  if params[:register]
    processor.register_users
    flash[:warning] = t(".registered", count: processor.emails.count,
                                       registered: processor.processed[:registered].count,
                                       errors: processor.errors[:registered].count)
  end
  if params[:authorize] == "in"
    processor.authorize_users
    flash[:notice] = t(".authorized", handler: t("#{processor.authorization_handler}.name", scope: "decidim.authorization_handlers"),
                                      count: processor.emails.count,
                                      authorized: processor.processed[:authorized].count,
                                      errors: processor.errors[:authorized].count)
  elsif params[:authorize] == "out"
    processor.revoke_users
    flash[:notice] = t(".revoked", handler: t("#{processor.authorization_handler}.name", scope: "decidim.authorization_handlers"),
                                   count: processor.emails.count,
                                   revoked: processor.processed[:revoked].count,
                                   errors: processor.errors[:revoked].count)
  else
    flash[:info] = t(".info", handler: t("#{processor.authorization_handler}.name", scope: "decidim.authorization_handlers"),
                              count: processor.emails.count,
                              authorized: processor.total(:authorized),
                              unconfirmed: processor.total(:unconfirmed),
                              registered: processor.total(:registered))
    render(action: :index) && return
  end
  redirect_to direct_verifications_path
end

#indexObject



12
13
14
# File 'app/controllers/decidim/direct_verifications/verification/admin/direct_verifications_controller.rb', line 12

def index
  enforce_permission_to :index, UserProcessor
end

#permission_class_chainObject



52
53
54
55
56
57
58
# File 'app/controllers/decidim/direct_verifications/verification/admin/direct_verifications_controller.rb', line 52

def permission_class_chain
  [
    Decidim::DirectVerifications::Verification::Admin::Permissions,
    Decidim::Admin::Permissions,
    Decidim::Permissions
  ]
end

#permission_scopeObject



60
61
62
# File 'app/controllers/decidim/direct_verifications/verification/admin/direct_verifications_controller.rb', line 60

def permission_scope
  :admin
end