Skip to content

Commit

Permalink
added missing creation informations
Browse files Browse the repository at this point in the history
  • Loading branch information
BraunTom committed Jun 7, 2019
1 parent 22d7846 commit a36b3e1
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
20 changes: 19 additions & 1 deletion app/controllers/app_settings_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class AppSettingsController < ApplicationController
before_action :set_app_setting, only: %i[edit update]
before_action :set_app_setting, only: %i[edit update import]
before_action :authenticate_admin

# GET /app_settings/1/edit
Expand All @@ -16,6 +16,24 @@ def update
end
end

def import
current_users = User.all.collect {|each| each.name}
GitHelper.open_git_repository(for_write: true) {}
initpp = File.read(File.join(Puppetscript.init_path, Puppetscript.init_file_name))
all_initpp_users = initpp.scan(/realname\s*=>\s*'(.+?)'/).flatten
initpp_only_users = all_initpp_users - current_users

successful_created_users = 0

initpp_only_users.each do |each|
user = User.extern each
puts 'enter'
successful_created_users += 1 if user.persisted?
end

redirect_to edit_app_setting_path(@app_setting), notice: "Successfully added #{successful_created_users} users."
end

private

# Use callbacks to share common setup or constraints between actions.
Expand Down
9 changes: 9 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,15 @@ def self.from_omniauth(auth)
end
end

# This is only to get users from a imported init.pp file.
# They are not able to login because the callback checks only
# user with hpi as provider (this is wanted behaviour)
def self.extern(user_name)
first_name, last_name = user_name.scan(/((?:\w|[-äöüÄÖÜß])+) (.*)/).first
create(provider: :extern, first_name: first_name, last_name: last_name,
email: "#{first_name}.#{last_name}@mail.com", password: 'test12345!')
end

def self.from_mail_identifier(mail_id)
all.each do |user|
return user if user.human_readable_identifier.casecmp(mail_id).zero?
Expand Down
3 changes: 2 additions & 1 deletion app/views/app_settings/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<h1>HART Settings</h1>

<%= render 'form', app_setting: @app_setting %>
<%= render 'form', app_setting: @app_setting %>
<%= button_to 'Import', controller: :app_settings, action: :import %>
6 changes: 5 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
# '/dashboard'
get '/dashboard' => 'dashboard#index', as: :dashboard
# '/app_settings/...'
resources :app_settings, only: %i[update edit]
resources :app_settings, only: %i[update edit] do
member do
post :import
end
end
# '/projects/...'
resources :projects
# '/servers/...'
Expand Down

0 comments on commit a36b3e1

Please sign in to comment.