foreman_users 0.0.21 → 0.0.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. data/app/controllers/foreman_users/syusers_controller.rb +92 -0
  2. data/app/helpers/foreman_users/{users_helper.rb → syusers_helper.rb} +1 -1
  3. data/app/models/foreman_users/{group.rb → sygroup.rb} +0 -0
  4. data/app/models/foreman_users/syuser.rb +66 -0
  5. data/app/views/foreman_users/{users → syusers}/_form.html.erb +10 -10
  6. data/app/views/foreman_users/{users → syusers}/_list.html.erb +16 -16
  7. data/app/views/foreman_users/{users → syusers}/_sub.html.erb +4 -4
  8. data/app/views/foreman_users/{users → syusers}/edit.html.erb +0 -0
  9. data/app/views/foreman_users/syusers/index.html.erb +5 -0
  10. data/app/views/foreman_users/{users → syusers}/new.html.erb +0 -0
  11. data/app/views/foreman_users/{users → syusers}/show.html.erb +19 -19
  12. data/config/routes.rb +1 -1
  13. data/db/migrate/20150918022411_create_syusers.rb +17 -0
  14. data/db/migrate/20150918050239_create_sygroups.rb +12 -0
  15. data/db/migrate/20150918055455_add_syuser_id_to_sygroup.rb +5 -0
  16. data/db/migrate/syusers/_form.html.erb +94 -0
  17. data/{app/views/foreman_users/users/index.html.erb → db/migrate/syusers/_list.html.erb} +16 -20
  18. data/db/migrate/syusers/_sub.html.erb +19 -0
  19. data/db/migrate/syusers/edit.html.erb +1 -0
  20. data/db/migrate/syusers/index.html.erb +5 -0
  21. data/db/migrate/syusers/new.html.erb +1 -0
  22. data/db/migrate/syusers/show.html.erb +77 -0
  23. data/lib/foreman_users/engine.rb +9 -9
  24. data/lib/foreman_users/version.rb +1 -1
  25. metadata +23 -15
  26. data/app/controllers/foreman_users/users_controller.rb +0 -91
  27. data/app/models/foreman_users/user.rb +0 -66
  28. data/db/migrate/20150918022911_create_foreman_users_users.rb +0 -19
  29. data/db/migrate/20150918050939_create_foreman_users_groups.rb +0 -14
@@ -0,0 +1,92 @@
1
+ class ForemanUsers::SyusersController < ApplicationController
2
+ # GET /syusers
3
+ # GET /syusers.json
4
+ def index
5
+ @syusers = Syuser.all.paginate(:page => params[:page])
6
+
7
+ respond_to do |format|
8
+ format.html # index.html.erb
9
+ format.json { render json: @syusers }
10
+ end
11
+ end
12
+
13
+ # GET /syusers/1
14
+ # GET /syusers/1.json
15
+ def show
16
+ @syuser = Syuser.find(params[:id])
17
+
18
+ respond_to do |format|
19
+ format.html # show.html.erb
20
+ format.json { render json: @syuser }
21
+ end
22
+ end
23
+
24
+ # GET /syusers/new
25
+ # GET /syusers/new.json
26
+ def new
27
+ @syuser = Syuser.new
28
+ 5.times { @syuser.sygroups.build}
29
+ #sygroups = @syuser.sygroups.new
30
+ respond_to do |format|
31
+ format.html # new.html.erb
32
+ format.json { render json: @syuser }
33
+ end
34
+ end
35
+
36
+ # GET /syusers/1/edit
37
+ def edit
38
+ @syuser = Syuser.find(params[:id])
39
+ sygroup_time = @syuser.sygroups.size
40
+ if sygroup_time == 0
41
+ 5.times { @syuser.sygroups.build}
42
+ else
43
+ 5.times { @syuser.sygroups.build}
44
+ end
45
+ end
46
+
47
+ # POST /syusers
48
+ # POST /syusers.json
49
+ def create
50
+ @syuser = Syuser.new(params[:syuser])
51
+
52
+ respond_to do |format|
53
+ if @syuser.save
54
+ format.html { redirect_to @syuser, notice: 'Syuser was successfully created.' }
55
+ format.json { render json: @syuser, status: :created, location: @syuser }
56
+ else
57
+ format.html { render action: "new" }
58
+ format.json { render json: @syuser.errors, status: :unprocessable_entity }
59
+ end
60
+ end
61
+ end
62
+
63
+ # PUT /syusers/1
64
+ # PUT /syusers/1.json
65
+ def update
66
+ @syuser = Syuser.find(params[:id])
67
+
68
+ respond_to do |format|
69
+ if @syuser.update_attributes(params[:syuser])
70
+ format.html { redirect_to @syuser, notice: 'Syuser was successfully updated.' }
71
+ format.json { head :no_content }
72
+ else
73
+ format.html { render action: "edit" }
74
+ format.json { render json: @syuser.errors, status: :unprocessable_entity }
75
+ end
76
+ end
77
+ end
78
+
79
+ # DELETE /syusers/1
80
+ # DELETE /syusers/1.json
81
+ def destroy
82
+ @syuser = Syuser.find(params[:id])
83
+ @syuser.destroy
84
+ #@syuser.destory_dir
85
+ respond_to do |format|
86
+ format.html { redirect_to syusers_url }
87
+ format.json { head :no_content }
88
+ end
89
+
90
+
91
+ end
92
+ end
@@ -1,4 +1,4 @@
1
1
  module ForemanUsers
2
- module UsersHelper
2
+ module SyusersHelper
3
3
  end
4
4
  end
File without changes
@@ -0,0 +1,66 @@
1
+ class ForemanUsers::Syuser < ActiveRecord::Base
2
+ require "fileutils"
3
+ attr_accessible :title, :body, :name, :ensure , :gid, :groups, :home , :password, :password_max_age, :password_min_age, :shell, :uid, :sygroups_attributes
4
+
5
+
6
+ has_many :sygroups
7
+ accepts_nested_attributes_for :sygroups, reject_if: proc { |attributes| attributes['gid'].blank?| attributes['name'].blank? | attributes['ensure'].blank? } , allow_destroy: true
8
+
9
+ after_create :create_dir
10
+ after_update :create_dir
11
+ #after_destory :destory_dir
12
+ def create_dir
13
+ #目前用 "/home/stdtnt/app/"代替 "/etc/puppet/environments/production/modules/users"
14
+ #该处需要注意权限问题,当前用户是否具有该目录的操作权限
15
+ root_dir_name = "/etc/puppet/environments/production/modules/users"
16
+ #self.destory_dir #默认删除该目录,然后重新创建
17
+ dir_exist_status = File.exist?(root_dir_name) #判断该目录是否存在
18
+ if !dir_exist_status
19
+ #创建目录结构
20
+ Dir::mkdir(root_dir_name)
21
+ Dir::mkdir(root_dir_name + "/files")
22
+ Dir::mkdir(root_dir_name + "/manifests")
23
+
24
+ #生成files下welcome.conf文件
25
+ files_welcome_File = File.new(root_dir_name + "/files/welcome.conf", "w+")
26
+ files_welcome_File.close
27
+ #生成manifests下init.pp文件
28
+ main_init_File = File.new(root_dir_name +"/manifests/init.pp", "w+")
29
+ if main_init_File
30
+ main_init_File.syswrite(self.create_content)
31
+ else
32
+ puts "Unable to open file!"
33
+ end
34
+ main_init_File.close
35
+ end
36
+ end
37
+
38
+
39
+ def destory_dir
40
+ #目前用 "/home/stdtnt/app/"代替 "/etc/puppet/environments/production/modules/users"
41
+ #该处需要注意权限问题,当前用户是否具有该目录的操作权限
42
+ root_dir_name = "/etc/puppet/environments/production/modules/users"
43
+ #判断该目录是否存在
44
+ dir_exist_status = File.exist?(root_dir_name )
45
+ if dir_exist_status
46
+ #使用fileUtils.rm_r 删除该文件夹及其以下所有内容
47
+ FileUtils.rm_r root_dir_name
48
+ end
49
+ end
50
+
51
+ def create_content
52
+ #content = "class users { " + "\n" + "\s\s" + "include baseline::params" + "\n" + "\s\s" + "@user {'$user':" + "\n" + "\s\s\s\s" + "ensure => $user_ensure," + "\n" + "\s\s\s\s" + "home => $user_home," + "\n" + "\s\s" + "}" + "\n" + "}"
53
+ #
54
+ user_content = "class users {" + "\n" + "\s\s" + "user { '" + self.name + "':" + "\n\s\s\s\s" + "ensure => '" + self.ensure + "'," + "\n\s\s\s\s" + "gid => '" + self.gid + "'," + "\n\s\s\s\s" + "groups => [" + self.groups + "]," + "\n\s\s\s\s" + "home => '" + self.home + "'," + "\n\s\s\s\s" + "password => '" + self.password + "'," + "\n\s\s\s\s" + "password_max_age => '" + self.password_max_age + "'," + "\n\s\s\s\s" + "password_min_age => '" + self.password_min_age + "'," + "\n\s\s\s\s" + "shell => '" + self.shell + "'," + "\n\s\s\s\s" + "uid => '" + self.uid + "'," + "\n\s\s" +"}" + "\n"
55
+
56
+ group_content = "\s\s"
57
+ if self.sygroups.size > 0
58
+ self.sygroups.each do |sygroup|
59
+ group_content += "group {'"+ sygroup.name + "':" + "\n\s\s\s\s" + "ensure => '" + sygroup.ensure + "'," + "\n\s\s\s\s" + "gid => '" + sygroup.gid + "'," + "\n\s\s" +"}" + "\n\s\s"
60
+ end
61
+ end
62
+ rs = user_content + group_content + "\n" + "}"
63
+ return rs
64
+ end
65
+ end
66
+
@@ -1,15 +1,15 @@
1
- <%= javascript 'foreman_users_users', 'foreman_users_user_edit', 'foreman_users_user_edit_interfaces', 'class_edit', 'compute_resource', 'lookup_keys'%>
1
+ <%= javascript 'syusers', 'syuser_edit', 'syuser_edit_interfaces', 'class_edit', 'compute_resource', 'lookup_keys'%>
2
2
 
3
- <%= form_for @foreman_users_user, :html => {:data => {:id => foreman_users_user.try(:id), :submit => 'progress_bar'}} do |f| %>
4
- <%= base_errors_for foreman_users_user %>
3
+ <%= form_for @syuser, :html => {:data => {:id => @syuser.try(:id), :submit => 'progress_bar'}} do |f| %>
4
+ <%= base_errors_for @syuser %>
5
5
  <div class="row clearfix">
6
6
  <div class="row">
7
7
  <div class="form-group col-md-6">
8
8
  <label>name</label>
9
- <%= f.text_field :username, :size => "col-md-6", placeholder: "填写用户名", class: "form-control" %>
9
+ <%= f.text_field :name, :size => "col-md-6", placeholder: "填写用户名", class: "form-control" %>
10
10
  </div>
11
11
  <div class="form-group col-md-6">
12
- <label for="user_ensure">ensure</label> <br />
12
+ <label for="syuser_ensure">ensure</label> <br />
13
13
  <%= f.select :ensure, [['Please select an ensure', nil], 'present', 'absent', 'role'], placeholder: "ensure", control_label: 'ensure', class: "form-control"%>
14
14
  </div>
15
15
  </div>
@@ -65,17 +65,17 @@
65
65
  <div class="row">
66
66
  <label class=" col-md-4">name</label><label class=" col-md-4">ensure</label><label class=" col-md-4">gid</label>
67
67
  </div>
68
- <%= f.fields_for :foreman_users_groups do |groups_form| %>
68
+ <%= f.fields_for :sygroups do |sygroups_form| %>
69
69
 
70
70
  <div class="row">
71
71
  <div class=" form-group col-md-4">
72
- <%= groups_form.text_field :groupname, :size => "col-md-4", placeholder: "填写shell,例如: /bin/bash" , class: "form-control"%>
72
+ <%= sygroups_form.text_field :name, :size => "col-md-4", placeholder: "填写shell,例如: /bin/bash" , class: "form-control"%>
73
73
  </div>
74
74
  <div class=" form-group col-md-4">
75
- <%= groups_form.text_field :ensure, :size => "col-md-4", placeholder: "填写shell,例如: /bin/bash" , class: "form-control"%>
75
+ <%= sygroups_form.text_field :ensure, :size => "col-md-4", placeholder: "填写shell,例如: /bin/bash" , class: "form-control"%>
76
76
  </div>
77
77
  <div class=" form-group col-md-4">
78
- <%= groups_form.text_field :gid, :size => "col-md-4", placeholder: "填写shell,例如: /bin/bash" , class: "form-control"%>
78
+ <%= sygroups_form.text_field :gid, :size => "col-md-4", placeholder: "填写shell,例如: /bin/bash" , class: "form-control"%>
79
79
  </div>
80
80
  </div>
81
81
 
@@ -88,7 +88,7 @@
88
88
 
89
89
  <div class="actions">
90
90
  <%= f.submit "提交", class: "btn btn-success" %>
91
- <%= link_to '返回', users_path, class: "btn btn-primary" %>
91
+ <%= link_to '返回', foreman_users_syusers_path, class: "btn btn-primary" %>
92
92
  </div>
93
93
  <% end %>
94
94
 
@@ -3,7 +3,7 @@
3
3
  <table class="table table-bordered table-striped table-condensed" >
4
4
  <thead>
5
5
  <tr>
6
- <th class="hidden-tablet hidden-xs">name</th>
6
+ <th class=''>name</th>
7
7
  <th class="hidden-xs">ensure</th>
8
8
  <th class="hidden-xs">gid</th>
9
9
  <th class="hidden-tablet hidden-xs">groups</th>
@@ -17,22 +17,22 @@
17
17
  </tr>
18
18
  </thead>
19
19
  <tbody>
20
- <% foreman_users_users.each do |user| %>
20
+ <% syusers.each do |syuser| %>
21
21
  <tr>
22
- <td class="hidden-tablet hidden-xs"><%= user.username %></td>
23
- <td class="hidden-xs"><%= user.ensure %></td>
24
- <td class="hidden-xs"><%= user.gid %></td>
25
- <td class="hidden-tablet hidden-xs"><%= user.groups %></td>
26
- <td class="hidden-tablet hidden-xs"><%= user.home %></td>
27
- <td class="hidden-tablet hidden-xs"><%= user.password %></td>
28
- <td class="hidden-tablet hidden-xs"><%= user.password_max_age %></td>
29
- <td class="hidden-tablet hidden-xs"><%= user.password_min_age %></td>
30
- <td class="hidden-tablet hidden-xs"><%= user.shell %></td>
31
- <td class="hidden-tablet hidden-xs"><%= user.uid %></td>
22
+ <td class=''><%= syuser.name %></td>
23
+ <td class="hidden-xs"><%= syuser.ensure %></td>
24
+ <td class="hidden-xs"><%= syuser.gid %></td>
25
+ <td class="hidden-tablet hidden-xs"><%= syuser.groups %></td>
26
+ <td class="hidden-tablet hidden-xs"><%= syuser.home %></td>
27
+ <td class="hidden-tablet hidden-xs"><%= syuser.password %></td>
28
+ <td class="hidden-tablet hidden-xs"><%= syuser.password_max_age %></td>
29
+ <td class="hidden-tablet hidden-xs"><%= syuser.password_min_age %></td>
30
+ <td class="hidden-tablet hidden-xs"><%= syuser.shell %></td>
31
+ <td class="hidden-tablet hidden-xs"><%= syuser.uid %></td>
32
32
  <td>
33
- <%= link_to '查看', user %>
34
- <%= link_to '编辑', edit_foreman_users_user_path(user) %>
35
- <%= link_to '删除', user, method: :delete, data: { confirm: 'Are you sure?' } %>
33
+ <%= link_to '查看', syuser %>
34
+ <%= link_to '编辑', edit_syuser_path(syuser) %>
35
+ <%= link_to '删除', syuser, method: :delete, data: { confirm: 'Are you sure?' } %>
36
36
  </td>
37
37
  </tr>
38
38
  <% end %>
@@ -54,4 +54,4 @@
54
54
  </div><!-- /.modal-content -->
55
55
  </div><!-- /.modal-dialog -->
56
56
  </div><!-- /.modal -->
57
- <%= will_paginate_with_info foreman_users_users, :more => " - "+_("<b class='select_count'>0</b> selected") %>
57
+ <%= will_paginate_with_info syusers, :more => " - "+_("<b class='select_count'>0</b> selected") %>
@@ -1,8 +1,8 @@
1
- <div id="group">
2
- <%= f.fields_for :group do |f| %>
1
+ <div id="sygroups">
2
+ <%= f.fields_for :sygroups do |f| %>
3
3
  <div class="row">
4
4
  <div class="col-md-4 column form-group">
5
- <%= text_f f, :groupname, :help_inline => _("填写用户名") %>
5
+ <%= text_f f, :name, :help_inline => _("填写用户名") %>
6
6
  </div>
7
7
  <div class="col-md-4 column form-group">
8
8
  <%= text_f f, :name, :help_inline => _("填写用户名") %>
@@ -16,4 +16,4 @@
16
16
  <% end %>
17
17
  </div>
18
18
 
19
- <%#= f.link_to_add "新增酒店", :group, :data => { :target => "#group" }, class: "btn btn-primary btn-xs mb1" %>
19
+ <%#= f.link_to_add "新增酒店", :sygroups, :data => { :target => "#sygroups" }, class: "btn btn-primary btn-xs mb1" %>
@@ -0,0 +1,5 @@
1
+ <% if authorized? %>
2
+ <% title_actions button_group(link_to "新增", new_syuser_path) %>
3
+ <% end %>
4
+
5
+ <%= render 'list', :syusers => @syusers, :header => @title || _("Syusers") %>
@@ -2,9 +2,9 @@
2
2
  <div class="container">
3
3
  <div class="row">
4
4
  <h1 class="clearfix">
5
- <%= @foreman_users_user.name %>
6
- <%= link_to '返回', user_path, class: "btn btn-primary pull-right mr1" %>
7
- <%= link_to '编辑', edit_user_path(@foreman_users_user), class: "btn btn-warning pull-right mr1" %>
5
+ <%= @syuser.name %>
6
+ <%= link_to '返回', foreman_users_syuser_path, class: "btn btn-primary pull-right mr1" %>
7
+ <%= link_to '编辑', edit_foreman_users_syuser_path(@syuser), class: "btn btn-warning pull-right mr1" %>
8
8
  </h1>
9
9
  </div>
10
10
 
@@ -19,10 +19,10 @@
19
19
  <td><strong>groups</strong></td>
20
20
  </tr>
21
21
  <tr>
22
- <td><%= @foreman_users_user.username %></td>
23
- <td><%= @foreman_users_user.ensure %></td>
24
- <td><%= @foreman_users_user.gid %></td>
25
- <td><%= @foreman_users_user.groups %></td>
22
+ <td><%= @syuser.name %></td>
23
+ <td><%= @syuser.ensure %></td>
24
+ <td><%= @syuser.gid %></td>
25
+ <td><%= @syuser.groups %></td>
26
26
  </tr>
27
27
 
28
28
  <tr>
@@ -32,10 +32,10 @@
32
32
  <td><strong>password_min_age</strong></td>
33
33
  </tr>
34
34
  <tr>
35
- <td><%= @foreman_users_user.home %></td>
36
- <td><%= @foreman_users_user.password %></td>
37
- <td><%= @foreman_users_user.password_max_age %></td>
38
- <td><%= @foreman_users_user.password_min_age %></td>
35
+ <td><%= @syuser.home %></td>
36
+ <td><%= @syuser.password %></td>
37
+ <td><%= @syuser.password_max_age %></td>
38
+ <td><%= @syuser.password_min_age %></td>
39
39
  </tr>
40
40
 
41
41
  <tr>
@@ -45,10 +45,10 @@
45
45
  <td><strong>updated_at</strong></td>
46
46
  </tr>
47
47
  <tr>
48
- <td><%= @foreman_users_user.shell %></td>
49
- <td><%= @foreman_users_user.uid %></td>
50
- <td><%= @foreman_users_user.created_at %></td>
51
- <td><%= @foreman_users_user.updated_at %></td>
48
+ <td><%= @syuser.shell %></td>
49
+ <td><%= @syuser.uid %></td>
50
+ <td><%= @syuser.created_at %></td>
51
+ <td><%= @syuser.updated_at %></td>
52
52
  </tr>
53
53
  </tbody>
54
54
  </table>
@@ -63,11 +63,11 @@
63
63
  <th>gid</th>
64
64
  </thead>
65
65
  <tbody>
66
- <% @foreman_users_user.foreman_users_groups.each do |group|%>
66
+ <% @syuser.sygroups.each do |sygroup|%>
67
67
  <tr class="success">
68
- <td><%= group.groupname %></td>
69
- <td><%= group.ensure %></td>
70
- <td><%= group.gid %></td>
68
+ <td><%= sygroup.name %></td>
69
+ <td><%= sygroup.ensure %></td>
70
+ <td><%= sygroup.gid %></td>
71
71
  </tr>
72
72
  <% end %>
73
73
  </tbody>
data/config/routes.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  Rails.application.routes.draw do
2
2
  namespace :foreman_users do
3
- resources :users #do
3
+ resources :syusers #do
4
4
  # match 'index', to: 'foreman_users/users#index'
5
5
  # match 'show', to: 'foreman_users/users#show'
6
6
  # match 'new', to: 'foreman_users/users#new'
@@ -0,0 +1,17 @@
1
+ class CreateSyusers < ActiveRecord::Migration
2
+ def change
3
+ create_table :syusers do |t|
4
+ t.string :name #名称
5
+ t.string :ensure #下拉菜单
6
+ t.string :gid #输入框
7
+ t.string :groups #多选
8
+ t.string :home #输入
9
+ t.string :password
10
+ t.string :password_max_age
11
+ t.string :password_min_age
12
+ t.string :shell
13
+ t.string :uid
14
+ t.timestamps
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,12 @@
1
+ class CreateSygroups < ActiveRecord::Migration
2
+ def change
3
+ create_table :sygroups do |t|
4
+ t.string :name
5
+ t.string :ensure
6
+ t.string :gid
7
+ t.string :groupable_type
8
+ t.integer :groupable_id
9
+ t.timestamps
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,5 @@
1
+ class AddSyuserIdToSygroup < ActiveRecord::Migration
2
+ def change
3
+ add_column :sygroups, :syuser_id, :integer
4
+ end
5
+ end
@@ -0,0 +1,94 @@
1
+ <%= javascript 'syusers', 'syuser_edit', 'syuser_edit_interfaces', 'class_edit', 'compute_resource', 'lookup_keys'%>
2
+
3
+ <%= form_for @syuser, :html => {:data => {:id => @syuser.try(:id), :submit => 'progress_bar'}} do |f| %>
4
+ <%= base_errors_for @syuser %>
5
+ <div class="row clearfix">
6
+ <div class="row">
7
+ <div class="form-group col-md-6">
8
+ <label>name</label>
9
+ <%= f.text_field :name, :size => "col-md-6", placeholder: "填写用户名", class: "form-control" %>
10
+ </div>
11
+ <div class="form-group col-md-6">
12
+ <label for="syuser_ensure">ensure</label> <br />
13
+ <%= f.select :ensure, [['Please select an ensure', nil], 'present', 'absent', 'role'], placeholder: "ensure", control_label: 'ensure', class: "form-control"%>
14
+ </div>
15
+ </div>
16
+
17
+ <div class="row">
18
+ <div class="form-group col-md-6">
19
+ <label>gid</label>
20
+ <%= f.text_field :gid, :size => "col-md-6", placeholder: "填写gid", class: "form-control" %>
21
+ </div>
22
+ <div class="form-group col-md-6">
23
+ <label>groups</label>
24
+ <%= f.text_field :groups, :size => "col-md-6", placeholder: "填写组名", class: "form-control" %>
25
+ </div>
26
+ </div>
27
+
28
+
29
+ <div class="row">
30
+ <div class="form-group col-md-6">
31
+ <label>home</label>
32
+ <%= f.text_field :home, :size => "col-md-6", placeholder: "填写用户名", class: "form-control"%>
33
+ </div>
34
+ <div class="form-group col-md-6">
35
+ <label>password</label>
36
+ <%= f.text_field :password, :size => "col-md-6", placeholder: "填写密码" , class: "form-control"%>
37
+ </div>
38
+ </div>
39
+
40
+
41
+ <div class="row">
42
+ <div class="form-group col-md-6">
43
+ <label>password_max_age</label>
44
+ <%= f.text_field :password_max_age, :size => "col-md-6", placeholder: "填写用户名" , class: "form-control"%>
45
+ </div>
46
+ <div class="form-group col-md-6">
47
+ <label>password_min_age</label>
48
+ <%= f.text_field :password_min_age, :size => "col-md-6", placeholder: "填写用户名", class: "form-control"%>
49
+ </div>
50
+ </div>
51
+
52
+ <div class="row">
53
+ <div class="form-group col-md-6">
54
+ <label>shell</label>
55
+ <%= f.text_field :shell, :size => "col-md-6", placeholder: "填写shell,例如: /bin/bash" , class: "form-control"%>
56
+ </div>
57
+ <div class="form-group col-md-6">
58
+ <label>uid</label>
59
+ <%= f.text_field :uid, :size => "col-md-6", placeholder: "填写uid,例如:609", class: "form-control"%>
60
+ </div>
61
+ </div>
62
+ <p><span style="color:red">以下为group信息</span>
63
+ </p>
64
+
65
+ <div class="row">
66
+ <label class=" col-md-4">name</label><label class=" col-md-4">ensure</label><label class=" col-md-4">gid</label>
67
+ </div>
68
+ <%= f.fields_for :sygroups do |sygroups_form| %>
69
+
70
+ <div class="row">
71
+ <div class=" form-group col-md-4">
72
+ <%= sygroups_form.text_field :name, :size => "col-md-4", placeholder: "填写shell,例如: /bin/bash" , class: "form-control"%>
73
+ </div>
74
+ <div class=" form-group col-md-4">
75
+ <%= sygroups_form.text_field :ensure, :size => "col-md-4", placeholder: "填写shell,例如: /bin/bash" , class: "form-control"%>
76
+ </div>
77
+ <div class=" form-group col-md-4">
78
+ <%= sygroups_form.text_field :gid, :size => "col-md-4", placeholder: "填写shell,例如: /bin/bash" , class: "form-control"%>
79
+ </div>
80
+ </div>
81
+
82
+
83
+ <% end %>
84
+
85
+ </div>
86
+
87
+
88
+
89
+ <div class="actions">
90
+ <%= f.submit "提交", class: "btn btn-success" %>
91
+ <%= link_to '返回', syusers_path, class: "btn btn-primary" %>
92
+ </div>
93
+ <% end %>
94
+
@@ -1,13 +1,9 @@
1
- <% if authorized? %>
2
- <% title_actions button_group(link_to "新增", new_user_path) %>
3
- <% end %>
4
-
5
1
  <%= javascript "jquery.cookie" %>
6
2
  <% title header ||= "" %>
7
3
  <table class="table table-bordered table-striped table-condensed" >
8
4
  <thead>
9
5
  <tr>
10
- <th class="hidden-tablet hidden-xs">name</th>
6
+ <th class=''>name</th>
11
7
  <th class="hidden-xs">ensure</th>
12
8
  <th class="hidden-xs">gid</th>
13
9
  <th class="hidden-tablet hidden-xs">groups</th>
@@ -21,22 +17,22 @@
21
17
  </tr>
22
18
  </thead>
23
19
  <tbody>
24
- <% foreman_users_users.each do |user| %>
20
+ <% syusers.each do |syuser| %>
25
21
  <tr>
26
- <td class="hidden-tablet hidden-xs"><%= user.username %></td>
27
- <td class="hidden-xs"><%= user.ensure %></td>
28
- <td class="hidden-xs"><%= user.gid %></td>
29
- <td class="hidden-tablet hidden-xs"><%= user.groups %></td>
30
- <td class="hidden-tablet hidden-xs"><%= user.home %></td>
31
- <td class="hidden-tablet hidden-xs"><%= user.password %></td>
32
- <td class="hidden-tablet hidden-xs"><%= user.password_max_age %></td>
33
- <td class="hidden-tablet hidden-xs"><%= user.password_min_age %></td>
34
- <td class="hidden-tablet hidden-xs"><%= user.shell %></td>
35
- <td class="hidden-tablet hidden-xs"><%= user.uid %></td>
22
+ <td class=''><%= syuser.name %></td>
23
+ <td class="hidden-xs"><%= syuser.ensure %></td>
24
+ <td class="hidden-xs"><%= syuser.gid %></td>
25
+ <td class="hidden-tablet hidden-xs"><%= syuser.groups %></td>
26
+ <td class="hidden-tablet hidden-xs"><%= syuser.home %></td>
27
+ <td class="hidden-tablet hidden-xs"><%= syuser.password %></td>
28
+ <td class="hidden-tablet hidden-xs"><%= syuser.password_max_age %></td>
29
+ <td class="hidden-tablet hidden-xs"><%= syuser.password_min_age %></td>
30
+ <td class="hidden-tablet hidden-xs"><%= syuser.shell %></td>
31
+ <td class="hidden-tablet hidden-xs"><%= syuser.uid %></td>
36
32
  <td>
37
- <%= link_to '查看', user %>
38
- <%= link_to '编辑', edit_foreman_users_user_path(user) %>
39
- <%= link_to '删除', user, method: :delete, data: { confirm: 'Are you sure?' } %>
33
+ <%= link_to '查看', syuser %>
34
+ <%= link_to '编辑', edit_syuser_path(syuser) %>
35
+ <%= link_to '删除', syuser, method: :delete, data: { confirm: 'Are you sure?' } %>
40
36
  </td>
41
37
  </tr>
42
38
  <% end %>
@@ -58,4 +54,4 @@
58
54
  </div><!-- /.modal-content -->
59
55
  </div><!-- /.modal-dialog -->
60
56
  </div><!-- /.modal -->
61
- <%= will_paginate_with_info foreman_users_users, :more => " - "+_("<b class='select_count'>0</b> selected") %>
57
+ <%= will_paginate_with_info syusers, :more => " - "+_("<b class='select_count'>0</b> selected") %>
@@ -0,0 +1,19 @@
1
+ <div id="sygroups">
2
+ <%= f.fields_for :sygroups do |f| %>
3
+ <div class="row">
4
+ <div class="col-md-4 column form-group">
5
+ <%= text_f f, :name, :help_inline => _("填写用户名") %>
6
+ </div>
7
+ <div class="col-md-4 column form-group">
8
+ <%= text_f f, :name, :help_inline => _("填写用户名") %>
9
+ </div>
10
+ <div class="col-md-4 column form-group">
11
+ <%= text_f f, :name, :help_inline => _("填写用户名") %>
12
+ </div>
13
+ </div>
14
+ <%= f.hidden_field :groupable_id, value: object.id %>
15
+ <%= f.hidden_field :groupable_type, value: object.class.to_s %>
16
+ <% end %>
17
+ </div>
18
+
19
+ <%#= f.link_to_add "新增酒店", :sygroups, :data => { :target => "#sygroups" }, class: "btn btn-primary btn-xs mb1" %>
@@ -0,0 +1 @@
1
+ <%= render 'form' %>
@@ -0,0 +1,5 @@
1
+ <% if authorized? %>
2
+ <% title_actions button_group(link_to "新增", new_syuser_path) %>
3
+ <% end %>
4
+
5
+ <%= render 'list', :syusers => @syusers, :header => @title || _("Syusers") %>
@@ -0,0 +1 @@
1
+ <%= render 'form' %>
@@ -0,0 +1,77 @@
1
+
2
+ <div class="container">
3
+ <div class="row">
4
+ <h1 class="clearfix">
5
+ <%= @syuser.name %>
6
+ <%= link_to '返回', syuser_path, class: "btn btn-primary pull-right mr1" %>
7
+ <%= link_to '编辑', edit_syuser_path(@syuser), class: "btn btn-warning pull-right mr1" %>
8
+ </h1>
9
+ </div>
10
+
11
+ <div class="row col-md-12">
12
+ <table class="table table-striped table-bordered">
13
+ <thead></thead>
14
+ <tbody>
15
+ <tr>
16
+ <td><strong>name</strong></td>
17
+ <td><strong>ensure</strong></td>
18
+ <td><strong>gid</strong></td>
19
+ <td><strong>groups</strong></td>
20
+ </tr>
21
+ <tr>
22
+ <td><%= @syuser.name %></td>
23
+ <td><%= @syuser.ensure %></td>
24
+ <td><%= @syuser.gid %></td>
25
+ <td><%= @syuser.groups %></td>
26
+ </tr>
27
+
28
+ <tr>
29
+ <td><strong>home</strong></td>
30
+ <td><strong>password</strong></td>
31
+ <td><strong>password_max_age</strong></td>
32
+ <td><strong>password_min_age</strong></td>
33
+ </tr>
34
+ <tr>
35
+ <td><%= @syuser.home %></td>
36
+ <td><%= @syuser.password %></td>
37
+ <td><%= @syuser.password_max_age %></td>
38
+ <td><%= @syuser.password_min_age %></td>
39
+ </tr>
40
+
41
+ <tr>
42
+ <td><strong>shell</strong></td>
43
+ <td><strong>uid</strong></td>
44
+ <td><strong>created_at</strong></td>
45
+ <td><strong>updated_at</strong></td>
46
+ </tr>
47
+ <tr>
48
+ <td><%= @syuser.shell %></td>
49
+ <td><%= @syuser.uid %></td>
50
+ <td><%= @syuser.created_at %></td>
51
+ <td><%= @syuser.updated_at %></td>
52
+ </tr>
53
+ </tbody>
54
+ </table>
55
+ </div>
56
+
57
+ <div class="row col-md-12">
58
+ <h2>groupList</h2>
59
+ <table class="table table-striped table-bordered">
60
+ <thead>
61
+ <th>groub_name</th>
62
+ <th>ensure</th>
63
+ <th>gid</th>
64
+ </thead>
65
+ <tbody>
66
+ <% @syuser.sygroups.each do |sygroup|%>
67
+ <tr class="success">
68
+ <td><%= sygroup.name %></td>
69
+ <td><%= sygroup.ensure %></td>
70
+ <td><%= sygroup.gid %></td>
71
+ </tr>
72
+ <% end %>
73
+ </tbody>
74
+ </table>
75
+ </div>
76
+
77
+ </div>
@@ -20,13 +20,13 @@ module ForemanUsers
20
20
 
21
21
  # Add permissions
22
22
  security_block :foreman_users do
23
- permission :view_foreman_users, :'foreman_users/users' => [:index]
24
- permission :view_foreman_users, :'foreman_users/users' => [:show]
25
- permission :view_foreman_users, :'foreman_users/users' => [:new]
26
- permission :view_foreman_users, :'foreman_users/users' => [:edit]
27
- permission :view_foreman_users, :'foreman_users/users' => [:create]
28
- permission :view_foreman_users, :'foreman_users/users' => [:update]
29
- permission :view_foreman_users, :'foreman_users/users' => [:destroy]
23
+ permission :view_foreman_users, :'foreman_users/syusers' => [:index]
24
+ permission :view_foreman_users, :'foreman_users/syusers' => [:show]
25
+ permission :view_foreman_users, :'foreman_users/syusers' => [:new]
26
+ permission :view_foreman_users, :'foreman_users/syusers' => [:edit]
27
+ permission :view_foreman_users, :'foreman_users/syusers' => [:create]
28
+ permission :view_foreman_users, :'foreman_users/syusers' => [:update]
29
+ permission :view_foreman_users, :'foreman_users/syusers' => [:destroy]
30
30
  end
31
31
 
32
32
  # Add a new role called 'Discovery' if it doesn't exist
@@ -35,8 +35,8 @@ module ForemanUsers
35
35
 
36
36
  # add menu entry
37
37
  sub_menu :top_menu, :forema_user_menu, :caption=> N_('UserManage'), :after=> :export_menu do
38
- menu :top_menu, :level1, :caption=>N_('User List'), :url_hash => { :controller => 'foreman_users/users', :action => :index }, :resource_type => ForemanUsers::User.name
39
- menu :top_menu, :level1, :caption=>N_('New User'), :url_hash => { :controller => 'foreman_users/users', :action => :new }, :resource_type => ForemanUsers::User.name
38
+ menu :top_menu, :level1, :caption=>N_('User List'), :url_hash => { :controller => 'foreman_users/syusers', :action => :index }, :resource_type => ForemanUsers::Syuser.name
39
+ menu :top_menu, :level2, :caption=>N_('New User'), :url_hash => { :controller => 'foreman_users/syusers', :action => :new }, :resource_type => ForemanUsers::Syuser.name
40
40
  # menu :top_menu, :level2, :url_hash => {:controller=> :example, :action=>:index}
41
41
  # menu :top_menu, :level3, :url_hash => {:controller=> :example, :action=>:index}
42
42
  # sub_menu :top_menu, :inner_level, :caption=> N_('Inner level') do
@@ -1,3 +1,3 @@
1
1
  module ForemanUsers
2
- VERSION = '0.0.21'
2
+ VERSION = '0.0.22'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_users
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.21
4
+ version: 0.0.22
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-09-27 00:00:00.000000000 Z
12
+ date: 2015-09-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rubocop
@@ -50,26 +50,34 @@ executables: []
50
50
  extensions: []
51
51
  extra_rdoc_files: []
52
52
  files:
53
- - app/models/foreman_users/group.rb
54
- - app/models/foreman_users/user.rb
53
+ - app/models/foreman_users/sygroup.rb
54
+ - app/models/foreman_users/syuser.rb
55
55
  - app/overrides/dashboard/index/sample_override.html.erb.deface
56
- - app/helpers/foreman_users/users_helper.rb
56
+ - app/helpers/foreman_users/syusers_helper.rb
57
57
  - app/views/dashboard/_foreman_users_widget.html.erb
58
- - app/views/foreman_users/users/new.html.erb
59
- - app/views/foreman_users/users/show.html.erb
60
- - app/views/foreman_users/users/_sub.html.erb
61
- - app/views/foreman_users/users/index.html.erb
62
- - app/views/foreman_users/users/_form.html.erb
63
- - app/views/foreman_users/users/edit.html.erb
64
- - app/views/foreman_users/users/_list.html.erb
65
58
  - app/views/foreman_users/layouts/layouts/new_layout.html.erb
66
59
  - app/views/foreman_users/layouts/new_layout.html.erb
60
+ - app/views/foreman_users/syusers/new.html.erb
61
+ - app/views/foreman_users/syusers/show.html.erb
62
+ - app/views/foreman_users/syusers/_sub.html.erb
63
+ - app/views/foreman_users/syusers/index.html.erb
64
+ - app/views/foreman_users/syusers/_form.html.erb
65
+ - app/views/foreman_users/syusers/edit.html.erb
66
+ - app/views/foreman_users/syusers/_list.html.erb
67
67
  - app/views/foreman_users/hosts/new_action.html.erb
68
68
  - app/views/foreman_users/hosts/hosts/new_action.html.erb
69
- - app/controllers/foreman_users/users_controller.rb
69
+ - app/controllers/foreman_users/syusers_controller.rb
70
70
  - config/routes.rb
71
- - db/migrate/20150918022911_create_foreman_users_users.rb
72
- - db/migrate/20150918050939_create_foreman_users_groups.rb
71
+ - db/migrate/20150918050239_create_sygroups.rb
72
+ - db/migrate/20150918055455_add_syuser_id_to_sygroup.rb
73
+ - db/migrate/20150918022411_create_syusers.rb
74
+ - db/migrate/syusers/new.html.erb
75
+ - db/migrate/syusers/show.html.erb
76
+ - db/migrate/syusers/_sub.html.erb
77
+ - db/migrate/syusers/index.html.erb
78
+ - db/migrate/syusers/_form.html.erb
79
+ - db/migrate/syusers/edit.html.erb
80
+ - db/migrate/syusers/_list.html.erb
73
81
  - lib/foreman_users.rb
74
82
  - lib/foreman_users/engine.rb
75
83
  - lib/foreman_users/version.rb
@@ -1,91 +0,0 @@
1
- class ForemanUsers::UsersController < ApplicationController
2
- # GET /foreman_users
3
- # GET /foreman_users.json
4
- def index
5
- @foreman_users_users = ForemanUsers::User.all.paginate(:page => params[:page])
6
-
7
- respond_to do |format|
8
- format.html # index.html.erb
9
- format.json { render json: @foreman_users_users }
10
- end
11
- end
12
-
13
- # GET /foreman_users/1
14
- # GET /foreman_users/1.json
15
- def show
16
- @foreman_users_user = ForemanUsers::User.find(params[:id])
17
-
18
- respond_to do |format|
19
- format.html # show.html.erb
20
- format.json { render json: @foreman_users_user }
21
- end
22
- end
23
-
24
- # GET /foreman_users/new
25
- # GET /foreman_users/new.json
26
- def new
27
- @foreman_users_user = ForemanUsers::User.new
28
- #5.times { @foreman_users_user.foreman_users_groups.build}
29
- respond_to do |format|
30
- format.html # new.html.erb
31
- format.json { render json: @foreman_users_user }
32
- end
33
- end
34
-
35
- # GET /foreman_users/1/edit
36
- def edit
37
- @foreman_users_user = ForemanUsers::User.find(params[:id])
38
- group_time = @foreman_users_user.foreman_users_groups.size
39
- if group_time == 0
40
- 5.times { @foreman_users_user.foreman_users_groups.build}
41
- else
42
- 5.times { @foreman_users_user.foreman_users_groups.build}
43
- end
44
- end
45
-
46
- # POST /foreman_users
47
- # POST /foreman_users.json
48
- def create
49
- @foreman_users_user = ForemanUsers::User.new(params[:foreman_users_user])
50
-
51
- respond_to do |format|
52
- if @foreman_users_user.save
53
- format.html { redirect_to @foreman_users_user, notice: 'foreman_user was successfully created.' }
54
- format.json { render json: @foreman_users_user, status: :created, location: @foreman_users_user }
55
- else
56
- format.html { render action: "new" }
57
- format.json { render json: @foreman_users_user.errors, status: :unprocessable_entity }
58
- end
59
- end
60
- end
61
-
62
- # PUT /foreman_users/1
63
- # PUT /foreman_users/1.json
64
- def update
65
- @foreman_users_user = ForemanUsers::User.find(params[:id])
66
-
67
- respond_to do |format|
68
- if @foreman_users_user.update_attributes(params[:foreman_users_user])
69
- format.html { redirect_to @foreman_users_user, notice: 'foreman_user was successfully updated.' }
70
- format.json { head :no_content }
71
- else
72
- format.html { render action: "edit" }
73
- format.json { render json: @foreman_users_user.errors, status: :unprocessable_entity }
74
- end
75
- end
76
- end
77
-
78
- # DELETE /foreman_users/1
79
- # DELETE /foreman_users/1.json
80
- def destroy
81
- @foreman_users_user = ForemanUsers::User.find(params[:id])
82
- @foreman_users_user.destroy
83
- @foreman_users_user.destory_dir
84
- respond_to do |format|
85
- format.html { redirect_to foreman_users_url }
86
- format.json { head :no_content }
87
- end
88
-
89
-
90
- end
91
- end
@@ -1,66 +0,0 @@
1
- require "fileutils"
2
- class ForemanUsers::User < ActiveRecord::Base
3
-
4
- attr_accessible :title, :body, :username, :ensure , :gid, :groups, :home , :password, :password_max_age, :password_min_age, :shell, :uid, :foreman_users_groups_attributes
5
-
6
-
7
- has_many :foreman_users_groups, class_name: "ForemanUsers::Group", foreign_key: "user_id"
8
- accepts_nested_attributes_for :foreman_users_groups, reject_if: proc { |attributes| attributes['gid'].blank?| attributes['groupname'].blank? | attributes['ensure'].blank? } , allow_destroy: true
9
-
10
- after_create :create_dir
11
- after_update :create_dir
12
- #after_destory :destory_dir
13
- def create_dir
14
- #目前用 "/home/stdtnt/app/"代替 "/etc/puppet/environments/production/modules/users"
15
- #该处需要注意权限问题,当前用户是否具有该目录的操作权限
16
- root_dir_name = "/etc/puppet/environments/production/modules/users"
17
- self.destory_dir #默认删除该目录,然后重新创建
18
- dir_exist_status = File.exist?(root_dir_name) #判断该目录是否存在
19
- if !dir_exist_status
20
- #创建目录结构
21
- Dir::mkdir(root_dir_name)
22
- Dir::mkdir(root_dir_name + "/files")
23
- Dir::mkdir(root_dir_name + "/manifests")
24
-
25
- #生成files下welcome.conf文件
26
- files_welcome_File = File.new(root_dir_name + "/files/welcome.conf", "w+")
27
- files_welcome_File.close
28
- #生成manifests下init.pp文件
29
- main_init_File = File.new(root_dir_name +"/manifests/init.pp", "w+")
30
- if main_init_File
31
- main_init_File.syswrite(self.create_content)
32
- else
33
- puts "Unable to open file!"
34
- end
35
- main_init_File.close
36
- end
37
- end
38
-
39
-
40
- def destory_dir
41
- #目前用 "/home/stdtnt/app/"代替 "/etc/puppet/environments/production/modules/users"
42
- #该处需要注意权限问题,当前用户是否具有该目录的操作权限
43
- root_dir_name = "/etc/puppet/environments/production/modules/users"
44
- #判断该目录是否存在
45
- dir_exist_status = File.exist?(root_dir_name )
46
- if dir_exist_status
47
- #使用fileUtils.rm_r 删除该文件夹及其以下所有内容
48
- FileUtils.rm_r root_dir_name
49
- end
50
- end
51
-
52
- def create_content
53
- #content = "class users { " + "\n" + "\s\s" + "include baseline::params" + "\n" + "\s\s" + "@user {'$user':" + "\n" + "\s\s\s\s" + "ensure => $user_ensure," + "\n" + "\s\s\s\s" + "home => $user_home," + "\n" + "\s\s" + "}" + "\n" + "}"
54
- #
55
- user_content = "class users {" + "\n" + "\s\s" + "user { '" + self.name + "':" + "\n\s\s\s\s" + "ensure => '" + self.ensure + "'," + "\n\s\s\s\s" + "gid => '" + self.gid + "'," + "\n\s\s\s\s" + "groups => [" + self.groups + "]," + "\n\s\s\s\s" + "home => '" + self.home + "'," + "\n\s\s\s\s" + "password => '" + self.password + "'," + "\n\s\s\s\s" + "password_max_age => '" + self.password_max_age + "'," + "\n\s\s\s\s" + "password_min_age => '" + self.password_min_age + "'," + "\n\s\s\s\s" + "shell => '" + self.shell + "'," + "\n\s\s\s\s" + "uid => '" + self.uid + "'," + "\n\s\s" +"}" + "\n"
56
-
57
- group_content = "\s\s"
58
- if self.groups.size > 0
59
- self.groups.each do |group|
60
- group_content += "group {'"+ group.name + "':" + "\n\s\s\s\s" + "ensure => '" + group.ensure + "'," + "\n\s\s\s\s" + "gid => '" + group.gid + "'," + "\n\s\s" +"}" + "\n\s\s"
61
- end
62
- end
63
- rs = user_content + group_content + "\n" + "}"
64
- return rs
65
- end
66
- end
@@ -1,19 +0,0 @@
1
- class CreateForemanUsersUsers < ActiveRecord::Migration
2
- def change
3
- drop_table :foreman_users_users if table_exists? :foreman_users_users
4
-
5
- create_table :foreman_users_users do |t|
6
- t.string :username
7
- t.string :ensure
8
- t.string :gid
9
- t.string :groups
10
- t.string :home
11
- t.string :password
12
- t.string :password_max_age
13
- t.string :password_min_age
14
- t.string :shell
15
- t.string :uid
16
- t.timestamps
17
- end unless table_exists? :foreman_users_users
18
- end
19
- end
@@ -1,14 +0,0 @@
1
- class CreateForemanUsersGroups < ActiveRecord::Migration
2
- def change
3
- drop_table :foreman_users_groups if table_exists? :foreman_users_groups
4
- create_table :foreman_users_groups do |t|
5
- t.string :groupname
6
- t.string :ensure
7
- t.string :gid
8
- t.string :groupable_type
9
- t.integer :groupable_id
10
- t.integer :user_id
11
- t.timestamps
12
- end unless table_exists? :foreman_users_groups
13
- end
14
- end