foreman_users 1.1.4 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. data/app/controllers/foreman_users/sygroups_controller.rb +79 -0
  2. data/app/controllers/foreman_users/syusermodels_controller.rb +90 -0
  3. data/app/controllers/foreman_users/syusers_controller.rb +8 -20
  4. data/app/models/foreman_users/sygroup.rb +77 -2
  5. data/app/models/foreman_users/syuser.rb +67 -72
  6. data/app/models/foreman_users/syusermodel.rb +83 -0
  7. data/app/views/foreman_users/layouts/_model.html.erb +12 -0
  8. data/app/views/foreman_users/layouts/layouts/_model.html.erb +12 -0
  9. data/app/views/foreman_users/sygroups/_form.html.erb +29 -0
  10. data/app/views/foreman_users/sygroups/_list.html.erb +43 -0
  11. data/app/views/foreman_users/sygroups/_sygroup.html.erb +3 -0
  12. data/app/views/foreman_users/sygroups/_sygroup_td.html.erb +7 -0
  13. data/app/views/foreman_users/sygroups/create.js.erb +2 -0
  14. data/app/views/foreman_users/sygroups/destroy.js.erb +1 -0
  15. data/app/views/foreman_users/sygroups/edit.html.erb +1 -0
  16. data/app/views/foreman_users/sygroups/edit.js.erb +3 -0
  17. data/app/views/foreman_users/sygroups/index.html.erb +5 -0
  18. data/app/views/foreman_users/sygroups/new.html.erb +1 -0
  19. data/app/views/foreman_users/sygroups/new.js.erb +3 -0
  20. data/app/views/foreman_users/sygroups/show.html.erb +28 -0
  21. data/app/views/foreman_users/sygroups/update.js.erb +3 -0
  22. data/app/views/foreman_users/syusermodels/_form.html.erb +24 -0
  23. data/app/views/foreman_users/syusermodels/_list.html.erb +41 -0
  24. data/app/views/foreman_users/syusermodels/edit.html.erb +1 -0
  25. data/app/views/foreman_users/syusermodels/index.html.erb +5 -0
  26. data/app/views/foreman_users/syusermodels/new.html.erb +1 -0
  27. data/app/views/foreman_users/syusermodels/show.html.erb +111 -0
  28. data/app/views/foreman_users/syusers/_form.html.erb +2 -10
  29. data/app/views/foreman_users/syusers/_syuser.html.erb +3 -0
  30. data/app/views/foreman_users/syusers/_syuser_td.html.erb +14 -0
  31. data/app/views/foreman_users/syusers/create.js.erb +2 -0
  32. data/app/views/foreman_users/syusers/destroy.js.erb +1 -0
  33. data/app/views/foreman_users/syusers/edit.js.erb +3 -0
  34. data/app/views/foreman_users/syusers/new.js.erb +3 -0
  35. data/app/views/foreman_users/syusers/show.html.erb +0 -21
  36. data/app/views/foreman_users/syusers/update.js.erb +3 -0
  37. data/config/routes.rb +3 -9
  38. data/db/migrate/20150918022411_create_syusers.rb +1 -0
  39. data/db/migrate/20150918050239_create_sygroups.rb +1 -0
  40. data/db/migrate/20150918050249_create_syusermodels.rb +12 -0
  41. data/lib/foreman_users/engine.rb +16 -11
  42. data/lib/foreman_users/version.rb +1 -1
  43. metadata +49 -3
  44. data/app/views/foreman_users/layouts/layouts/new_layout.html.erb +0 -0
  45. data/app/views/foreman_users/layouts/new_layout.html.erb +0 -0
@@ -0,0 +1,79 @@
1
+ class ForemanUsers::SygroupsController < ApplicationController
2
+ # GET /sygroups
3
+ # GET /sygroups.json
4
+ def index
5
+ @sygroups = ForemanUsers::Sygroup.all.paginate(:page => params[:page])
6
+
7
+ respond_to do |format|
8
+ format.html # index.html.erb
9
+ format.json { render json: @sygroups }
10
+ end
11
+ end
12
+
13
+ # GET /sygroups/1
14
+ # GET /sygroups/1.json
15
+ def show
16
+ @sygroup = ForemanUsers::Sygroup.find(params[:id])
17
+
18
+ respond_to do |format|
19
+ format.html # show.html.erb
20
+ format.json { render json: @sygroup }
21
+ end
22
+ end
23
+
24
+ # GET /sygroups/new
25
+ # GET /sygroups/new.json
26
+ def new
27
+ usermodel = ForemanUsers::Syusermodel.find(params[:syusermodel_id])
28
+ @sygroup = usermodel.sygroups.new
29
+ respond_to do |format|
30
+ format.js
31
+ end
32
+ end
33
+
34
+ # GET /sygroups/1/edit
35
+ def edit
36
+ @sygroup = ForemanUsers::Sygroup.find(params[:id])
37
+ end
38
+
39
+ # POST /sygroups
40
+ # POST /sygroups.json
41
+ def create
42
+ @sygroup = ForemanUsers::Sygroup.new(params[:foreman_users_sygroup])
43
+
44
+ respond_to do |format|
45
+ if @sygroup.save
46
+ format.js
47
+ else
48
+ format.js { render :template => 'layouts/error', locals: { errors: @syusers.errors } }
49
+ end
50
+ end
51
+ end
52
+
53
+ # PUT /sygroups/1
54
+ # PUT /sygroups/1.json
55
+ def update
56
+ @sygroup = ForemanUsers::Sygroup.find(params[:id])
57
+
58
+ respond_to do |format|
59
+ if @sygroup.update_attributes(params[:foreman_users_sygroup])
60
+ format.js
61
+ else
62
+ format.html { render action: "edit" }
63
+ format.json { render json: @sygroup.errors, status: :unprocessable_entity }
64
+ end
65
+ end
66
+ end
67
+
68
+ # DELETE /sygroups/1
69
+ # DELETE /sygroups/1.json
70
+ def destroy
71
+ @sygroup = ForemanUsers::Sygroup.find(params[:id])
72
+ @sygroup.destroy
73
+ respond_to do |format|
74
+ format.js
75
+ end
76
+
77
+
78
+ end
79
+ end
@@ -0,0 +1,90 @@
1
+ class ForemanUsers::SyusermodelsController < ApplicationController
2
+ # GET /syusermodels
3
+ # GET /syusermodels.json
4
+ def index
5
+ @syusermodels = ForemanUsers::Syusermodel.all.paginate(:page => params[:page])
6
+
7
+ respond_to do |format|
8
+ format.html # index.html.erb
9
+ format.json { render json: @syusermodels }
10
+ end
11
+ end
12
+
13
+ # GET /syusermodels/1
14
+ # GET /syusermodels/1.json
15
+ def show
16
+ @syusermodel = ForemanUsers::Syusermodel.find(params[:id])
17
+
18
+ respond_to do |format|
19
+ format.html # show.html.erb
20
+ format.json { render json: @syusermodel }
21
+ end
22
+ end
23
+
24
+ # GET /syusermodels/new
25
+ # GET /syusermodels/new.json
26
+ def new
27
+ @syusermodel = ForemanUsers::Syusermodel.new
28
+ respond_to do |format|
29
+ format.html # new.html.erb
30
+ format.json { render json: @syusermodel }
31
+ end
32
+ end
33
+
34
+ # GET /syusermodels/1/edit
35
+ def edit
36
+ @syusermodel = ForemanUsers::Syusermodel.find(params[:id])
37
+ # sygroup_time = @syusermodel.sygroups.size
38
+ # if sygroup_time == 0
39
+ # 5.times { @syusermodel.sygroups.build}
40
+ # else
41
+ # 5.times { @syusermodel.sygroups.build}
42
+ # end
43
+ end
44
+
45
+ # POST /syusermodels
46
+ # POST /syusermodels.json
47
+ def create
48
+ @syusermodel = ForemanUsers::Syusermodel.new(params[:foreman_users_syusermodel])
49
+
50
+ respond_to do |format|
51
+ if @syusermodel.save
52
+ format.html { redirect_to @syusermodel, notice: 'Syusermodel was successfully created.' }
53
+ format.json { render json: @syusermodel, status: :created, location: @syusermodel }
54
+ else
55
+ format.html { render action: "new" }
56
+ format.json { render json: @syusermodel.errors, status: :unprocessable_entity }
57
+ end
58
+ end
59
+ end
60
+
61
+ # PUT /syusermodels/1
62
+ # PUT /syusermodels/1.json
63
+ def update
64
+ @syusermodel = ForemanUsers::Syusermodel.find(params[:id])
65
+
66
+ respond_to do |format|
67
+ if @syusermodel.update_attributes(params[:foreman_users_syusermodel])
68
+ format.html { redirect_to @syusermodel, notice: 'Syusermodel was successfully updated.' }
69
+ format.json { head :no_content }
70
+ else
71
+ format.html { render action: "edit" }
72
+ format.json { render json: @syusermodel.errors, status: :unprocessable_entity }
73
+ end
74
+ end
75
+ end
76
+
77
+ # DELETE /syusermodels/1
78
+ # DELETE /syusermodels/1.json
79
+ def destroy
80
+ @syusermodel = ForemanUsers::Syusermodel.find(params[:id])
81
+ @syusermodel.destroy
82
+ @syusermodel.destory_dir
83
+ respond_to do |format|
84
+ format.html { redirect_to foreman_usermodels_syusermodels_url }
85
+ format.json { head :no_content }
86
+ end
87
+
88
+
89
+ end
90
+ end
@@ -24,24 +24,17 @@ class ForemanUsers::SyusersController < ApplicationController
24
24
  # GET /syusers/new
25
25
  # GET /syusers/new.json
26
26
  def new
27
- @syuser = ForemanUsers::Syuser.new
28
- sygroups = @syuser.sygroups.new
29
- #5.times { @syuser.sygroups.build}
27
+ usermodel = ForemanUsers::Syusermodel.find(params[:syusermodel_id])
28
+ @syuser = usermodel.syusers.new
29
+ #@syuser = ForemanUsers::Syuser.new
30
30
  respond_to do |format|
31
- format.html # new.html.erb
32
- format.json { render json: @syuser }
31
+ format.js
33
32
  end
34
33
  end
35
34
 
36
35
  # GET /syusers/1/edit
37
36
  def edit
38
37
  @syuser = ForemanUsers::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
38
  end
46
39
 
47
40
  # POST /syusers
@@ -51,11 +44,9 @@ class ForemanUsers::SyusersController < ApplicationController
51
44
 
52
45
  respond_to do |format|
53
46
  if @syuser.save
54
- format.html { redirect_to @syuser, notice: 'Syuser was successfully created.' }
55
- format.json { render json: @syuser, status: :created, location: @syuser }
47
+ format.js
56
48
  else
57
- format.html { render action: "new" }
58
- format.json { render json: @syuser.errors, status: :unprocessable_entity }
49
+ format.js { render :template => 'layouts/error', locals: { errors: @syusers.errors } }
59
50
  end
60
51
  end
61
52
  end
@@ -67,8 +58,7 @@ class ForemanUsers::SyusersController < ApplicationController
67
58
 
68
59
  respond_to do |format|
69
60
  if @syuser.update_attributes(params[:foreman_users_syuser])
70
- format.html { redirect_to @syuser, notice: 'Syuser was successfully updated.' }
71
- format.json { head :no_content }
61
+ format.js
72
62
  else
73
63
  format.html { render action: "edit" }
74
64
  format.json { render json: @syuser.errors, status: :unprocessable_entity }
@@ -81,10 +71,8 @@ class ForemanUsers::SyusersController < ApplicationController
81
71
  def destroy
82
72
  @syuser = ForemanUsers::Syuser.find(params[:id])
83
73
  @syuser.destroy
84
- @syuser.destory_dir
85
74
  respond_to do |format|
86
- format.html { redirect_to foreman_users_syusers_url }
87
- format.json { head :no_content }
75
+ format.js
88
76
  end
89
77
 
90
78
 
@@ -1,4 +1,79 @@
1
1
  class ForemanUsers::Sygroup < ActiveRecord::Base
2
- attr_accessible :name, :ensure, :gid, :groupable_type, :groupable_id, :user_id
3
- belongs_to :foreman_users_syuser, class_name: "ForemanUsers::Syuser",foreign_key: "user_id"
2
+ attr_accessible :name, :ensure, :gid, :groupable_type, :groupable_id, :user_id, :syusermodel_id
3
+ #belongs_to :foreman_users_syuser, class_name: "ForemanUsers::Syuser",foreign_key: "user_id"
4
+ belongs_to :foreman_users_syusermodel, class_name: "ForemanUsers::Syusermodel",foreign_key: "syusermodel_id"
5
+ after_create :create_dir
6
+ after_update :create_dir
7
+ after_destroy :create_dir
8
+ def create_dir
9
+ #该处需要注意权限问题,当前用户是否具有该目录的操作权限
10
+ root_dir_name = "/etc/puppet/environments/production/modules/" + self.foreman_users_syusermodel.name
11
+
12
+ #该处需要注意权限问题,当前用户是否具有该目录的操作权限
13
+ root_dir_name = "/etc/puppet/environments/production/modules/" + self.foreman_users_syusermodel.name
14
+ #判断该目录是否存在
15
+ dir_exist_status = File.exist?(root_dir_name )
16
+ if dir_exist_status
17
+ FileUtils.rm_r root_dir_name
18
+ end #默认删除该目录,然后重新创建,主要目的防止文件或文件夹被误删除
19
+
20
+
21
+ #创建目录结构
22
+ Dir::mkdir(root_dir_name)
23
+ if !File.exist?(root_dir_name + "/files")
24
+ Dir::mkdir(root_dir_name + "/files")
25
+ end
26
+
27
+ if !File.exist?(root_dir_name + "/manifests")
28
+ Dir::mkdir(root_dir_name + "/manifests")
29
+ end
30
+
31
+ if File.exist?(root_dir_name + "/files")
32
+ if File.exist?(root_dir_name + "/files/welcome.conf")
33
+ #生成files下welcome.conf文件
34
+ files_welcome_File = File.new(root_dir_name + "/files/welcome.conf", "w+")
35
+ files_welcome_File.close
36
+ end
37
+ end
38
+
39
+ if File.exist?(root_dir_name + "/manifests")
40
+ if File.exist?(root_dir_name + "/manifests/init.pp")
41
+ FileUtils.rm_r (root_dir_name + "/manifests/init.pp")
42
+ end
43
+ #生成manifests下init.pp文件
44
+ main_init_File = File.new(root_dir_name +"/manifests/init.pp", "w+")
45
+ if main_init_File
46
+ main_init_File.syswrite(self.create_content)
47
+ else
48
+ puts "Unable to open file!"
49
+ end
50
+ main_init_File.close
51
+ end
52
+ end
53
+
54
+ def destory_dir
55
+
56
+ end
57
+
58
+ def create_content
59
+ title_content = "class users {"
60
+ user_content = "\n" + "\s\s"
61
+ if self.foreman_users_syusermodel.syusers.size > 0
62
+ self.foreman_users_syusermodel.syusers.each do |syuser|
63
+ user_content += "\n" + "\s\s" + "user { '" + syuser.name + "':" + "\n\s\s\s\s" + "ensure => '" + syuser.ensure + "'," + "\n\s\s\s\s" + "gid => '" + syuser.gid + "'," + "\n\s\s\s\s" + "groups => [" + syuser.groups + "]," + "\n\s\s\s\s" + "home => '" + syuser.home + "'," + "\n\s\s\s\s" + "password => '" + syuser.password + "'," + "\n\s\s\s\s" + "password_max_age => '" + syuser.password_max_age + "'," + "\n\s\s\s\s" + "password_min_age => '" + syuser.password_min_age + "'," + "\n\s\s\s\s" + "shell => '" + syuser.shell + "'," + "\n\s\s\s\s" + "uid => '" + syuser.uid + "'," + "\n\s\s" +"}" + "\n"
64
+ end
65
+ end
66
+
67
+
68
+ group_content = "\s\s"
69
+ if self.foreman_users_syusermodel.sygroups.size > 0
70
+ self.foreman_users_syusermodel.sygroups.each do |sygroup|
71
+ 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"
72
+ end
73
+ end
74
+ title_content = title_content + user_content + group_content
75
+
76
+ rs = title_content + "\n" + "}"
77
+ return rs
78
+ end
4
79
  end
@@ -1,87 +1,82 @@
1
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
2
 
5
- has_many :sygroups, class_name: "ForemanUsers::Sygroup"
6
- accepts_nested_attributes_for :sygroups, reject_if: proc { |attributes| attributes['gid'].blank?| attributes['name'].blank? | attributes['ensure'].blank? } , allow_destroy: true
3
+ attr_accessible :title, :body, :name, :ensure , :gid, :groups, :home , :password, :password_max_age, :password_min_age, :shell, :uid, :sygroups_attributes, :syusermodel_id
4
+ belongs_to :foreman_users_syusermodel, class_name: "ForemanUsers::Syusermodel",foreign_key: "syusermodel_id"
7
5
 
8
6
  after_create :create_dir
9
7
  after_update :create_dir
10
- #after_destory :destory_dir
11
- def create_dir
12
- #目前用 "/home/stdtnt/app/"代替 "/etc/puppet/environments/production/modules/users"
13
- #该处需要注意权限问题,当前用户是否具有该目录的操作权限
14
- root_dir_name = "/etc/puppet/environments/production/modules/users"
15
- #self.destory_dir #默认删除该目录,然后重新创建
16
- dir_exist_status = File.exist?(root_dir_name) #判断该目录是否存在
17
- if !dir_exist_status
18
- #创建目录结构
19
- Dir::mkdir(root_dir_name)
20
- if !File.exist?(root_dir_name + "/files")
21
- Dir::mkdir(root_dir_name + "/files")
22
- end
8
+ after_destroy :create_dir
9
+ def create_dir
10
+ #该处需要注意权限问题,当前用户是否具有该目录的操作权限
11
+ puts "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
12
+ puts self.foreman_users_syusermodel
13
+ puts ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
14
+ self.foreman_users_syusermodel.name
15
+ puts "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
16
+ root_dir_name = "/etc/puppet/environments/production/modules/" + self.foreman_users_syusermodel.name
23
17
 
24
- if !File.exist?(root_dir_name + "/manifests")
25
- Dir::mkdir(root_dir_name + "/manifests")
26
- end
27
- end
28
- if File.exist?(root_dir_name + "/files")
29
- if File.exist?(root_dir_name + "/files/welcome.conf")
30
- #生成files下welcome.conf文件
31
- files_welcome_File = File.new(root_dir_name + "/files/welcome.conf", "w+")
32
- files_welcome_File.close
33
- end
34
- end
18
+ dir_exist_status = File.exist?(root_dir_name) #判断该目录是否存在
19
+
20
+
21
+ if dir_exist_status
22
+ FileUtils.rm_r root_dir_name
23
+ end #默认删除该目录,然后重新创建,主要目的防止文件或文件夹被误删除
35
24
 
36
- if File.exist?(root_dir_name + "/manifests")
37
- if File.exist?(root_dir_name + "/manifests/init.pp")
38
- FileUtils.rm_r (root_dir_name + "/manifests/init.pp")
39
- end
40
- #生成manifests下init.pp文件
41
- main_init_File = File.new(root_dir_name +"/manifests/init.pp", "w+")
42
- if main_init_File
43
- main_init_File.syswrite(self.create_content)
44
- else
45
- puts "Unable to open file!"
46
- end
47
- main_init_File.close
48
- end
49
- end
50
25
 
26
+ #创建目录结构
27
+ Dir::mkdir(root_dir_name)
28
+ if !File.exist?(root_dir_name + "/files")
29
+ Dir::mkdir(root_dir_name + "/files")
30
+ end
31
+
32
+ if !File.exist?(root_dir_name + "/manifests")
33
+ Dir::mkdir(root_dir_name + "/manifests")
34
+ end
51
35
 
52
- def destory_dir
53
- #目前用 "/home/stdtnt/app/"代替 "/etc/puppet/environments/production/modules/users"
54
- #该处需要注意权限问题,当前用户是否具有该目录的操作权限
55
- root_dir_name = "/etc/puppet/environments/production/modules/users"
56
- #判断该目录是否存在
57
- dir_exist_status = File.exist?(root_dir_name )
58
- if dir_exist_status
59
- #使用fileUtils.rm_r 删除该文件夹及其以下所有内容
60
- if ForemanUsers::Syuser.all.size == 0
61
- FileUtils.rm_r root_dir_name
62
- end
63
- end
36
+ if File.exist?(root_dir_name + "/files")
37
+ if File.exist?(root_dir_name + "/files/welcome.conf")
38
+ #生成files下welcome.conf文件
39
+ files_welcome_File = File.new(root_dir_name + "/files/welcome.conf", "w+")
40
+ files_welcome_File.close
41
+ end
42
+ end
43
+
44
+ if File.exist?(root_dir_name + "/manifests")
45
+ if File.exist?(root_dir_name + "/manifests/init.pp")
46
+ FileUtils.rm_r (root_dir_name + "/manifests/init.pp")
47
+ end
48
+ #生成manifests下init.pp文件
49
+ main_init_File = File.new(root_dir_name +"/manifests/init.pp", "w+")
50
+ if main_init_File
51
+ main_init_File.syswrite(self.create_content)
52
+ else
53
+ puts "Unable to open file!"
54
+ end
55
+ main_init_File.close
64
56
  end
57
+ end
58
+
65
59
 
66
- def create_content
67
- #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" + "}"
68
- #
69
- title_content = "class users {"
70
60
 
71
- ForemanUsers::Syuser.all.each do |syuser|
72
- user_content = "\n" + "\s\s" + "user { '" + syuser.name + "':" + "\n\s\s\s\s" + "ensure => '" + syuser.ensure + "'," + "\n\s\s\s\s" + "gid => '" + syuser.gid + "'," + "\n\s\s\s\s" + "groups => [" + syuser.groups + "]," + "\n\s\s\s\s" + "home => '" + syuser.home + "'," + "\n\s\s\s\s" + "password => '" + syuser.password + "'," + "\n\s\s\s\s" + "password_max_age => '" + syuser.password_max_age + "'," + "\n\s\s\s\s" + "password_min_age => '" + syuser.password_min_age + "'," + "\n\s\s\s\s" + "shell => '" + syuser.shell + "'," + "\n\s\s\s\s" + "uid => '" + syuser.uid + "'," + "\n\s\s" +"}" + "\n"
61
+ def create_content
62
+ title_content = "class users {"
63
+ user_content = "\n" + "\s\s"
64
+ if self.foreman_users_syusermodel.syusers.size > 0
65
+ self.foreman_users_syusermodel.syusers.each do |syuser|
66
+ user_content += "\n" + "\s\s" + "user { '" + syuser.name + "':" + "\n\s\s\s\s" + "ensure => '" + syuser.ensure + "'," + "\n\s\s\s\s" + "gid => '" + syuser.gid + "'," + "\n\s\s\s\s" + "groups => [" + syuser.groups + "]," + "\n\s\s\s\s" + "home => '" + syuser.home + "'," + "\n\s\s\s\s" + "password => '" + syuser.password + "'," + "\n\s\s\s\s" + "password_max_age => '" + syuser.password_max_age + "'," + "\n\s\s\s\s" + "password_min_age => '" + syuser.password_min_age + "'," + "\n\s\s\s\s" + "shell => '" + syuser.shell + "'," + "\n\s\s\s\s" + "uid => '" + syuser.uid + "'," + "\n\s\s" +"}" + "\n"
67
+ end
68
+ end
73
69
 
74
- group_content = "\s\s"
75
- if syuser.sygroups.size > 0
76
- syuser.sygroups.each do |sygroup|
77
- 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"
78
- end
79
- end
80
- title_content = title_content + user_content + group_content
81
- end
82
70
 
83
- rs = title_content + "\n" + "}"
84
- return rs
85
- end
86
- end
71
+ group_content = "\s\s"
72
+ if self.foreman_users_syusermodel.sygroups.size > 0
73
+ self.foreman_users_syusermodel.sygroups.each do |sygroup|
74
+ 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"
75
+ end
76
+ end
77
+ title_content = title_content + user_content + group_content
87
78
 
79
+ rs = title_content + "\n" + "}"
80
+ return rs
81
+ end
82
+ end
@@ -0,0 +1,83 @@
1
+ class ForemanUsers::Syusermodel < ActiveRecord::Base
2
+ require "fileutils"
3
+ attr_accessible :name, :remark
4
+
5
+ has_many :sygroups, class_name: "ForemanUsers::Sygroup",foreign_key: "syusermodel_id", :dependent => :destroy
6
+ has_many :syusers, class_name: "ForemanUsers::Syuser",foreign_key: "syusermodel_id", :dependent => :destroy
7
+
8
+ after_create :create_dir
9
+ after_update :create_dir
10
+ after_destroy :destory_dir
11
+ def create_dir
12
+ #该处需要注意权限问题,当前用户是否具有该目录的操作权限
13
+ root_dir_name = "/etc/puppet/environments/production/modules/" + self.name
14
+
15
+ dir_exist_status = File.exist?(root_dir_name) #判断该目录是否存在
16
+ self.destory_dir #默认删除该目录,然后重新创建,主要目的防止文件或文件夹被误删除
17
+ if !dir_exist_status
18
+ #创建目录结构
19
+ Dir::mkdir(root_dir_name)
20
+ if !File.exist?(root_dir_name + "/files")
21
+ Dir::mkdir(root_dir_name + "/files")
22
+ end
23
+
24
+ if !File.exist?(root_dir_name + "/manifests")
25
+ Dir::mkdir(root_dir_name + "/manifests")
26
+ end
27
+ end
28
+ if File.exist?(root_dir_name + "/files")
29
+ if File.exist?(root_dir_name + "/files/welcome.conf")
30
+ #生成files下welcome.conf文件
31
+ files_welcome_File = File.new(root_dir_name + "/files/welcome.conf", "w+")
32
+ files_welcome_File.close
33
+ end
34
+ end
35
+
36
+ if File.exist?(root_dir_name + "/manifests")
37
+ if File.exist?(root_dir_name + "/manifests/init.pp")
38
+ FileUtils.rm_r (root_dir_name + "/manifests/init.pp")
39
+ end
40
+ #生成manifests下init.pp文件
41
+ main_init_File = File.new(root_dir_name +"/manifests/init.pp", "w+")
42
+ if main_init_File
43
+ main_init_File.syswrite(self.create_content)
44
+ else
45
+ puts "Unable to open file!"
46
+ end
47
+ main_init_File.close
48
+ end
49
+ end
50
+
51
+ def destory_dir
52
+ #该处需要注意权限问题,当前用户是否具有该目录的操作权限
53
+ root_dir_name = "/etc/puppet/environments/production/modules/" + self.name
54
+ #判断该目录是否存在
55
+ dir_exist_status = File.exist?(root_dir_name )
56
+ if dir_exist_status
57
+ FileUtils.rm_r root_dir_name
58
+ end
59
+ end
60
+
61
+ def create_content
62
+ title_content = "class users {"
63
+ user_content = "\n" + "\s\s"
64
+ if self.syusers.size > 0
65
+ self.syusers.each do |syuser|
66
+ user_content += "\n" + "\s\s" + "user { '" + syuser.name + "':" + "\n\s\s\s\s" + "ensure => '" + syuser.ensure + "'," + "\n\s\s\s\s" + "gid => '" + syuser.gid + "'," + "\n\s\s\s\s" + "groups => [" + syuser.groups + "]," + "\n\s\s\s\s" + "home => '" + syuser.home + "'," + "\n\s\s\s\s" + "password => '" + syuser.password + "'," + "\n\s\s\s\s" + "password_max_age => '" + syuser.password_max_age + "'," + "\n\s\s\s\s" + "password_min_age => '" + syuser.password_min_age + "'," + "\n\s\s\s\s" + "shell => '" + syuser.shell + "'," + "\n\s\s\s\s" + "uid => '" + syuser.uid + "'," + "\n\s\s" +"}" + "\n"
67
+ end
68
+ end
69
+
70
+
71
+ group_content = "\s\s"
72
+ if self.sygroups.size > 0
73
+ self.sygroups.each do |sygroup|
74
+ 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"
75
+ end
76
+ end
77
+ title_content = title_content + user_content + group_content
78
+
79
+ rs = title_content + "\n" + "}"
80
+ return rs
81
+ end
82
+
83
+ end
@@ -0,0 +1,12 @@
1
+ <div class="modal fade" id="formModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
2
+ <div class="modal-dialog">
3
+ <div class="modal-content">
4
+ <div class="modal-header">
5
+ <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
6
+ <h4 class="modal-title" id="myModalLabel">请填写</h4>
7
+ </div>
8
+ <div class="modal-body">
9
+ </div>
10
+ </div>
11
+ </div>
12
+ </div>
@@ -0,0 +1,12 @@
1
+ <div class="modal fade" id="formModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
2
+ <div class="modal-dialog">
3
+ <div class="modal-content">
4
+ <div class="modal-header">
5
+ <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
6
+ <h4 class="modal-title" id="myModalLabel">请填写</h4>
7
+ </div>
8
+ <div class="modal-body">
9
+ </div>
10
+ </div>
11
+ </div>
12
+ </div>
@@ -0,0 +1,29 @@
1
+ <%= javascript 'sygroups', 'sygroup_edit', 'sygroup_edit_interfaces', 'class_edit', 'compute_resource', 'lookup_keys'%>
2
+
3
+ <%= form_for(@sygroup, remote: true) do |f| %>
4
+ <%= base_errors_for @sygroup %>
5
+ <div class="row clearfix">
6
+ <div class="row">
7
+ <div class="form-group col-md-3">
8
+ <label>name</label>
9
+ <%= f.text_field :name, :size => "col-md-3", placeholder: "填写用户名", class: "form-control" %>
10
+ </div>
11
+ <div class="form-group col-md-3">
12
+ <label>ensure</label> <br />
13
+ <%= f.select :ensure, [['Please select an ensure', nil], 'present', 'absent', 'role'], placeholder: "ensure", control_label: 'ensure', class: "col-md-3 column form-control"%>
14
+ </div>
15
+
16
+ <div class="form-group col-md-3">
17
+ <label>gid</label>
18
+ <%= f.text_field :gid, :size => "col-md-3", placeholder: "填写gid", class: "form-control" %>
19
+ </div>
20
+ </div>
21
+ <div class="row">
22
+ <div class="actions">
23
+ <%= f.hidden_field :syusermodel_id, value: @sygroup.syusermodel_id %>
24
+ <%= f.submit "提交", class: "btn btn-success" %>
25
+ <%= link_to '返回', foreman_users_sygroups_path, class: "btn btn-primary" %>
26
+ </div>
27
+ </div>
28
+ </div>
29
+ <% end %>
@@ -0,0 +1,43 @@
1
+ <%= javascript "jquery.cookie" %>
2
+ <% title header ||= "" %>
3
+ <table class="table table-bordered table-striped table-condensed" >
4
+ <thead>
5
+ <tr>
6
+ <th class=''>name</th>
7
+ <th class="hidden-xs">ensure</th>
8
+ <th class="hidden-xs">gid</th>
9
+ <th>操作</th>
10
+ </tr>
11
+ </thead>
12
+ <tbody>
13
+ <% sygroups.each do |sygroup| %>
14
+ <tr>
15
+ <td class=''><%= sygroup.name %></td>
16
+ <td class="hidden-xs"><%= sygroup.ensure %></td>
17
+ <td class="hidden-xs"><%= sygroup.gid %></td>
18
+ <td>
19
+ <%= link_to '查看', sygroup %>
20
+ <%= link_to '编辑', edit_foreman_users_sygroup_path(sygroup) %>
21
+ <%= link_to '删除', sygroup, method: :delete, data: { confirm: 'Are you sure?' } %>
22
+ </td>
23
+ </tr>
24
+ <% end %>
25
+ </tbody>
26
+ </table>
27
+ <div id="confirmation-modal" class="modal fade">
28
+ <div class="modal-dialog">
29
+ <div class="modal-content">
30
+ <div class="modal-header">
31
+ <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
32
+ <h4 class="modal-title"><%= _('Please Confirm') %></h4>
33
+ </div>
34
+ <div class="modal-body">
35
+ </div>
36
+ <div class="modal-footer">
37
+ <button type="button" class="btn btn-default" data-dismiss="modal"><%= _('Cancel') %></button>
38
+ <button type="button" class="btn btn-primary" onclick="submit_modal_form()"><%= _('Submit') %></button>
39
+ </div>
40
+ </div><!-- /.modal-content -->
41
+ </div><!-- /.modal-dialog -->
42
+ </div><!-- /.modal -->
43
+ <%= will_paginate_with_info sygroups, :more => " - "+_("<b class='select_count'>0</b> selected") %>
@@ -0,0 +1,3 @@
1
+ <tr id="sygroup-<%= sygroup.id %>">
2
+ <%= render partial: "foreman_users/sygroups/sygroup_td", locals: { sygroup: sygroup } %>
3
+ </tr>
@@ -0,0 +1,7 @@
1
+ <td><%= sygroup.name %></td>
2
+ <td><%= sygroup.ensure %></td>
3
+ <td><%= sygroup.gid %></td>
4
+ <td>
5
+ <%= link_to '编辑', edit_foreman_users_sygroup_path(sygroup), remote: true %>
6
+ <%= link_to '删除', sygroup, method: :delete, remote: true, data: { confirm: 'Are you sure?' } %>
7
+ </td>
@@ -0,0 +1,2 @@
1
+ $('#formModal').modal("hide");
2
+ $(".table.sygroups tbody").prepend('<%= escape_javascript(render(:partial => "foreman_users/sygroups/sygroup", locals: { :sygroup => @sygroup })) %>');
@@ -0,0 +1 @@
1
+ $("#sygroup-<%= @sygroup.id %>").fadeOut(200).remove();
@@ -0,0 +1 @@
1
+ <%= render 'form' %>
@@ -0,0 +1,3 @@
1
+ $('#formModal').modal("show");
2
+ $('#formModal .modal-body').html("<%= escape_javascript(render 'foreman_users/sygroups/form') %>");
3
+ defaultInit();
@@ -0,0 +1,5 @@
1
+ <% if authorized? %>
2
+ <% title_actions button_group(link_to "新增", new_foreman_users_sygroup_path) %>
3
+ <% end %>
4
+
5
+ <%= render 'list', :sygroups => @sygroups, :header => @title || _("System Groups") %>
@@ -0,0 +1 @@
1
+ <%= render 'form' %>
@@ -0,0 +1,3 @@
1
+ $('#formModal').modal("show");
2
+ $('#formModal .modal-body').html("<%= escape_javascript(render 'foreman_users/sygroups/form') %>");
3
+ defaultInit();
@@ -0,0 +1,28 @@
1
+
2
+ <div class="container">
3
+ <div class="row">
4
+ <h1 class="clearfix">
5
+ <%= @sygroup.name %>
6
+ <%= link_to '返回', foreman_users_sygroup_path, class: "btn btn-primary pull-right mr1" %>
7
+ <%= link_to '编辑', edit_foreman_users_sygroup_path(@sygroup), 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
+ </tr>
20
+ <tr>
21
+ <td><%= @sygroup.name %></td>
22
+ <td><%= @sygroup.ensure %></td>
23
+ <td><%= @sygroup.gid %></td>
24
+ </tr>
25
+ </tbody>
26
+ </table>
27
+ </div>
28
+ </div>
@@ -0,0 +1,3 @@
1
+ $('#formModal').modal("hide");
2
+ $("#sygroup-<%= @sygroup.id %>").html('<%= escape_javascript(render(:partial => "foreman_users/sygroups/sygroup_td", locals: { :sygroup => @sygroup })) %>');
3
+ defaultInit();
@@ -0,0 +1,24 @@
1
+ <%= javascript 'syusermodels', 'syusermodel_edit', 'syusermodel_edit_interfaces', 'class_edit', 'compute_resource', 'lookup_keys'%>
2
+
3
+ <%= form_for @syusermodel, :html => {:data => {:id => @syusermodel.try(:id), :submit => 'progress_bar'}} do |f| %>
4
+ <%= base_errors_for @syusermodel %>
5
+ <div class="row clearfix">
6
+ <div class="row">
7
+ <div class="form-group col-md-3">
8
+ <label>name</label>
9
+ <%= f.text_field :name, :size => "col-md-3", placeholder: "填写模块名", class: "form-control" %>
10
+ </div>
11
+
12
+ <div class="form-group col-md-3">
13
+ <label>remark</label>
14
+ <%= f.text_field :remark, :size => "col-md-3", placeholder: "remark", class: "form-control" %>
15
+ </div>
16
+ </div>
17
+ <div class="row">
18
+ <div class="actions">
19
+ <%= f.submit "提交", class: "btn btn-success" %>
20
+ <%= link_to '返回', foreman_users_syusermodels_path, class: "btn btn-primary" %>
21
+ </div>
22
+ </div>
23
+ </div>
24
+ <% end %>
@@ -0,0 +1,41 @@
1
+ <%= javascript "jquery.cookie" %>
2
+ <% title header ||= "" %>
3
+ <table class="table table-bordered table-striped table-condensed" >
4
+ <thead>
5
+ <tr>
6
+ <th class=''>name</th>
7
+ <th class="hidden-xs">remark</th>
8
+ <th>操作</th>
9
+ </tr>
10
+ </thead>
11
+ <tbody>
12
+ <% syusermodels.each do |syusermodel| %>
13
+ <tr>
14
+ <td class=''><%= syusermodel.name %></td>
15
+ <td class="hidden-xs"><%= syusermodel.remark %></td>
16
+ <td>
17
+ <%= link_to '查看', syusermodel %>
18
+ <%= link_to '编辑', edit_foreman_users_syusermodel_path(syusermodel) %>
19
+ <%= link_to '删除', syusermodel, method: :delete, data: { confirm: 'Are you sure?' } %>
20
+ </td>
21
+ </tr>
22
+ <% end %>
23
+ </tbody>
24
+ </table>
25
+ <div id="confirmation-modal" class="modal fade">
26
+ <div class="modal-dialog">
27
+ <div class="modal-content">
28
+ <div class="modal-header">
29
+ <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
30
+ <h4 class="modal-title"><%= _('Please Confirm') %></h4>
31
+ </div>
32
+ <div class="modal-body">
33
+ </div>
34
+ <div class="modal-footer">
35
+ <button type="button" class="btn btn-default" data-dismiss="modal"><%= _('Cancel') %></button>
36
+ <button type="button" class="btn btn-primary" onclick="submit_modal_form()"><%= _('Submit') %></button>
37
+ </div>
38
+ </div><!-- /.modal-content -->
39
+ </div><!-- /.modal-dialog -->
40
+ </div><!-- /.modal -->
41
+ <%= will_paginate_with_info syusermodels, :more => " - "+_("<b class='select_count'>0</b> selected") %>
@@ -0,0 +1 @@
1
+ <%= render 'form' %>
@@ -0,0 +1,5 @@
1
+ <% if authorized? %>
2
+ <% title_actions button_group(link_to "新增", new_foreman_users_syusermodel_path) %>
3
+ <% end %>
4
+
5
+ <%= render 'list', :syusermodels => @syusermodels, :header => @title || _("System Usermodels") %>
@@ -0,0 +1 @@
1
+ <%= render 'form' %>
@@ -0,0 +1,111 @@
1
+
2
+ <div class="container">
3
+ <div class="row">
4
+ <h1 class="clearfix">
5
+ <%= @syusermodel.name %>
6
+ <%= link_to '返回', foreman_users_syusermodel_path, class: "btn btn-primary pull-right mr1" %>
7
+ <%= link_to '编辑', edit_foreman_users_syusermodel_path(@syusermodel), class: "btn btn-warning pull-right mr1" %>
8
+ </h1>
9
+ </div>
10
+
11
+ <div class="row">
12
+ <div class="col-md-12">
13
+ <table class="table table-striped table-bordered">
14
+ <thead></thead>
15
+ <tbody>
16
+ <tr>
17
+ <td><strong>name</strong></td>
18
+ <td><strong>remark</strong></td>
19
+ </tr>
20
+ <tr>
21
+ <td><%= @syusermodel.name %></td>
22
+ <td><%= @syusermodel.remark %></td>
23
+ </tr>
24
+ </tbody>
25
+ </table>
26
+ </div>
27
+
28
+
29
+ </div>
30
+ <div class="row">
31
+ <div class="col-md-12">
32
+ <ul class="nav nav-tabs mb1">
33
+ <li class="active"><a href="#syusers" data-toggle="tab">User <span class="red"><%= @syusermodel.syusers.count %></a></li>
34
+ <li><a href="#sygroups" data-toggle="tab">Group <span class="red"><%= @syusermodel.sygroups.count %></a></li>
35
+ </ul>
36
+
37
+ <div class="tab-content">
38
+ <div class="tab-pane active" id="syusers">
39
+ <div id="syusers">
40
+ <%= link_to "new", new_foreman_users_syuser_path(syusermodel_id: @syusermodel.id), remote: true, class: "btn btn-primary pull-right" %>
41
+ <div class="panel-body">
42
+ <table class="table table-striped table-hover syusers">
43
+ <thead>
44
+ <th class=''>name</th>
45
+ <th class="hidden-xs">ensure</th>
46
+ <th class="hidden-xs">gid</th>
47
+ <th class="hidden-tablet hidden-xs">groups</th>
48
+ <th class="hidden-tablet hidden-xs">home</th>
49
+ <th class="hidden-tablet hidden-xs">password</th>
50
+ <th class="hidden-tablet hidden-xs">password_max_age</th>
51
+ <th class="hidden-tablet hidden-xs">password_min_age</th>
52
+ <th class="hidden-tablet hidden-xs">shell</th>
53
+ <th class="hidden-tablet hidden-xs">uid</th>
54
+ <th class="hidden-tablet hidden-xs">操作</th>
55
+ </thead>
56
+ <tbody>
57
+ <% @syusermodel.syusers.each do |syuser| %>
58
+ <%= render partial: "foreman_users/syusers/syuser", locals: { syuser: syuser} %>
59
+ <% end %>
60
+ </tbody>
61
+ </table>
62
+ </div>
63
+
64
+
65
+ </div>
66
+ </div>
67
+ <div class="tab-pane" id="sygroups">
68
+ <div id="sygroups">
69
+ <%= link_to "new", new_foreman_users_sygroup_path(syusermodel_id: @syusermodel.id), remote: true, class: "btn btn-primary pull-right" %>
70
+ <div class="panel-body">
71
+ <table class="table table-bordered table-striped table-condensed sygroups" >
72
+ <thead>
73
+ <tr>
74
+ <th class=''>name</th>
75
+ <th class="hidden-xs">ensure</th>
76
+ <th class="hidden-xs">gid</th>
77
+ <th>操作</th>
78
+ </tr>
79
+ </thead>
80
+ <tbody>
81
+ <% @syusermodel.sygroups.each do |sygroup| %>
82
+ <%= render partial: "foreman_users/sygroups/sygroup", locals: { sygroup: sygroup} %>
83
+ <% end %>
84
+ </tbody>
85
+ </table>
86
+ </div>
87
+
88
+ </div>
89
+ </div>
90
+
91
+ </div>
92
+ </div>
93
+ </div>
94
+
95
+ <!-- Modal -->
96
+ <div class="modal fade" id="formModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
97
+ <div class="modal-dialog">
98
+ <div class="modal-content">
99
+ <div class="modal-header">
100
+ <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
101
+ <h4 class="modal-title" id="myModalLabel">请填写</h4>
102
+ </div>
103
+ <div class="modal-body">
104
+ </div>
105
+ </div>
106
+ </div>
107
+ </div>
108
+
109
+
110
+ </div>
111
+
@@ -1,6 +1,6 @@
1
1
  <%= javascript 'syusers', 'syuser_edit', 'syuser_edit_interfaces', 'class_edit', 'compute_resource', 'lookup_keys'%>
2
2
 
3
- <%= nested_form_for @syuser, :html => {:data => {:id => @syuser.try(:id), :submit => 'progress_bar'}} do |f| %>
3
+ <%= form_for(@syuser, remote: true) do |f| %>
4
4
  <%= base_errors_for @syuser %>
5
5
  <div class="row clearfix">
6
6
  <div class="row">
@@ -54,17 +54,9 @@
54
54
  <%= f.text_field :uid, :size => "col-md-6", placeholder: "填写uid,例如:609", class: "form-control"%>
55
55
  </div>
56
56
  </div>
57
- <p><span style="color:red">以下为group信息</span></p>
58
- <div class="row">
59
- <div class="col-md-12 column">
60
- <%= render partial: "foreman_users/syusers/sub", locals: { f: f, object: @syuser } %>
61
- </div>
62
- </div>
63
- <div class="row">
64
- <br /><br />
65
- </div>
66
57
  <div class="row">
67
58
  <div class="actions">
59
+ <%= f.hidden_field :syusermodel_id, value: @syuser.syusermodel_id %>
68
60
  <%= f.submit "提交", class: "btn btn-success" %>
69
61
  <%= link_to '返回', foreman_users_syusers_path, class: "btn btn-primary" %>
70
62
  </div>
@@ -0,0 +1,3 @@
1
+ <tr id="syuser-<%= syuser.id %>">
2
+ <%= render partial: "foreman_users/syusers/syuser_td", locals: { syuser: syuser } %>
3
+ </tr>
@@ -0,0 +1,14 @@
1
+ <td><%= syuser.name %></td>
2
+ <td><%= syuser.ensure %></td>
3
+ <td><%= syuser.gid %></td>
4
+ <td><%= syuser.groups %></td>
5
+ <td><%= syuser.home %></td>
6
+ <td><%= syuser.password %></td>
7
+ <td><%= syuser.password_max_age %></td>
8
+ <td><%= syuser.password_min_age %></td>
9
+ <td><%= syuser.shell %></td>
10
+ <td><%= syuser.uid %></td>
11
+ <td>
12
+ <%= link_to '编辑', edit_foreman_users_syuser_path(syuser), remote: true %>
13
+ <%= link_to '删除', syuser, method: :delete, remote: true, data: { confirm: 'Are you sure?' } %>
14
+ </td>
@@ -0,0 +1,2 @@
1
+ $('#formModal').modal("hide");
2
+ $(".table.syusers tbody").prepend('<%= escape_javascript(render(:partial => "foreman_users/syusers/syuser", locals: { :syuser => @syuser })) %>');
@@ -0,0 +1 @@
1
+ $("#syuser-<%= @syuser.id %>").fadeOut(200).remove();
@@ -0,0 +1,3 @@
1
+ $('#formModal').modal("show");
2
+ $('#formModal .modal-body').html("<%= escape_javascript(render 'foreman_users/syusers/form') %>");
3
+ defaultInit();
@@ -0,0 +1,3 @@
1
+ $('#formModal').modal("show");
2
+ $('#formModal .modal-body').html("<%= escape_javascript(render 'foreman_users/syusers/form') %>");
3
+ defaultInit();
@@ -53,25 +53,4 @@
53
53
  </tbody>
54
54
  </table>
55
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
56
  </div>
@@ -0,0 +1,3 @@
1
+ $('#formModal').modal("hide");
2
+ $("#syuser-<%= @syuser.id %>").html('<%= escape_javascript(render(:partial => "foreman_users/syusers/syuser_td", locals: { :syuser => @syuser })) %>');
3
+ defaultInit();
data/config/routes.rb CHANGED
@@ -1,13 +1,7 @@
1
1
  Rails.application.routes.draw do
2
2
  namespace :foreman_users do
3
- resources :syusers #do
4
- # match 'index', to: 'foreman_users/users#index'
5
- # match 'show', to: 'foreman_users/users#show'
6
- # match 'new', to: 'foreman_users/users#new'
7
- # match 'edit', to: 'foreman_users/users#edit'
8
- # match 'create', to: 'foreman_users/users#create'
9
- # match 'update', to: 'foreman_users/users#update'
10
- # match 'destroy', to: 'foreman_users/users#destroy'
11
- # end
3
+ resources :syusers
4
+ resources :sygroups
5
+ resources :syusermodels
12
6
  end
13
7
  end
@@ -1,4 +1,5 @@
1
1
  class CreateSyusers < ActiveRecord::Migration
2
+ drop tables syusers if table_exists? :syusers
2
3
  def change
3
4
  create_table :syusers do |t|
4
5
  t.string :name #名称
@@ -1,4 +1,5 @@
1
1
  class CreateSygroups < ActiveRecord::Migration
2
+ drop tables sygroups if table_exists? :sygroups
2
3
  def change
3
4
  create_table :sygroups do |t|
4
5
  t.string :name
@@ -0,0 +1,12 @@
1
+ class CreateSyusermodels < ActiveRecord::Migration
2
+ drop tables syusermodels if table_exists? :syusermodels
3
+ def change
4
+ create_table :syusermodels do |t|
5
+ t.string :name #名称
6
+ t.text :remark #备注
7
+ t.timestamps
8
+ end
9
+ end
10
+ add_column :syusers, :syusermodel_id, :integer
11
+ add_column :sygroups, :syusermodel_id, :integer
12
+ end
@@ -24,26 +24,31 @@ module ForemanUsers
24
24
  permission :view_foreman_users, :'foreman_users/syusers' => [:index, :show, :auto_complete_search]
25
25
  permission :new_foreman_users, :'foreman_users/syusers' => [:new, :create]
26
26
  permission :edit_foreman_users, :'foreman_users/syusers' => [:edit, :update]
27
- permission :delete_foreman_users, :'foreman_users/syusers' => [:destroy]
27
+ permission :delete_foreman_users, :'foreman_users/syusers' => [:destroy]
28
28
 
29
+ permission :view_foreman_groups, :'foreman_users/sygroups' => [:index, :show, :auto_complete_search]
30
+ permission :new_foreman_groups, :'foreman_users/sygroups' => [:new, :create]
31
+ permission :edit_foreman_groups, :'foreman_users/sygroups' => [:edit, :update]
32
+ permission :delete_foreman_groups, :'foreman_users/sygroups' => [:destroy]
33
+
34
+
35
+ permission :view_foreman_usermodels, :'foreman_users/syusermodels' => [:index, :show, :auto_complete_search]
36
+ permission :new_foreman_usermodels, :'foreman_users/syusermodels' => [:new, :create]
37
+ permission :edit_foreman_usermodels, :'foreman_users/syusermodels' => [:edit, :update]
38
+ permission :delete_foreman_usermodels, :'foreman_users/syusermodels' => [:destroy]
29
39
 
30
40
  end
31
41
 
32
42
  # Add a new role called 'Discovery' if it doesn't exist
33
- role "ForemanUsers", [:view_foreman_users, :new_foreman_users, :edit_foreman_users, :delete_foreman_users]
43
+ role "ForemanUsers", [:view_foreman_users, :new_foreman_users, :edit_foreman_users, :delete_foreman_users, :view_foreman_groups, :new_foreman_groups, :edit_foreman_groups, :delete_foreman_groups, :view_foreman_usermodels, :new_foreman_usermodels, :edit_foreman_usermodels, :delete_foreman_usermodels]
34
44
 
35
45
 
36
46
  # add menu entry
37
47
  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/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
- # menu :top_menu, :level2, :url_hash => {:controller=> :example, :action=>:index}
41
- # menu :top_menu, :level3, :url_hash => {:controller=> :example, :action=>:index}
42
- # sub_menu :top_menu, :inner_level, :caption=> N_('Inner level') do
43
- # menu :top_menu, :level41, :url_hash => {:controller=> :example, :action=>:index}
44
- # menu :top_menu, :level42, :url_hash => {:controller=> :example, :action=>:index}
45
- # end
46
- # menu :top_menu, :level5, :url_hash => {:controller=> :example, :action=>:index}
48
+ menu :top_menu, :level1, :caption=>N_('UserModel List'), :url_hash => { :controller => 'foreman_users/syusermodels', :action => :index }, :resource_type => ForemanUsers::Syusermodel.name
49
+ #menu :top_menu, :level2, :caption=>N_('User List'), :url_hash => { :controller => 'foreman_users/syusers', :action => :index }, :resource_type => ForemanUsers::Syuser.name
50
+ #menu :top_menu, :level3, :caption=>N_('Group List'), :url_hash => { :controller => 'foreman_users/sygroups', :action => :index }, :resource_type => ForemanUsers::Sygroup.name
51
+ #menu :top_menu, :level4, :caption=>N_('New User'), :url_hash => { :controller => 'foreman_users/syusers', :action => :new }, :resource_type => ForemanUsers::Syuser.name
47
52
  end
48
53
 
49
54
 
@@ -1,3 +1,3 @@
1
1
  module ForemanUsers
2
- VERSION = '1.1.4'
2
+ VERSION = '1.2.0'
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: 1.1.4
4
+ version: 1.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -43,6 +43,22 @@ dependencies:
43
43
  - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: compass-rails
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
46
62
  - !ruby/object:Gem::Dependency
47
63
  name: rubocop
48
64
  requirement: !ruby/object:Gem::Requirement
@@ -83,24 +99,54 @@ extensions: []
83
99
  extra_rdoc_files: []
84
100
  files:
85
101
  - app/views/dashboard/_foreman_users_widget.html.erb
86
- - app/views/foreman_users/layouts/layouts/new_layout.html.erb
87
- - app/views/foreman_users/layouts/new_layout.html.erb
102
+ - app/views/foreman_users/syusermodels/edit.html.erb
103
+ - app/views/foreman_users/syusermodels/new.html.erb
104
+ - app/views/foreman_users/syusermodels/show.html.erb
105
+ - app/views/foreman_users/syusermodels/index.html.erb
106
+ - app/views/foreman_users/syusermodels/_list.html.erb
107
+ - app/views/foreman_users/syusermodels/_form.html.erb
108
+ - app/views/foreman_users/layouts/layouts/_model.html.erb
109
+ - app/views/foreman_users/layouts/_model.html.erb
88
110
  - app/views/foreman_users/syusers/edit.html.erb
111
+ - app/views/foreman_users/syusers/destroy.js.erb
112
+ - app/views/foreman_users/syusers/create.js.erb
89
113
  - app/views/foreman_users/syusers/new.html.erb
114
+ - app/views/foreman_users/syusers/update.js.erb
115
+ - app/views/foreman_users/syusers/new.js.erb
90
116
  - app/views/foreman_users/syusers/show.html.erb
91
117
  - app/views/foreman_users/syusers/index.html.erb
92
118
  - app/views/foreman_users/syusers/_list.html.erb
93
119
  - app/views/foreman_users/syusers/_form.html.erb
120
+ - app/views/foreman_users/syusers/_syuser.html.erb
94
121
  - app/views/foreman_users/syusers/_sub.html.erb
122
+ - app/views/foreman_users/syusers/_syuser_td.html.erb
123
+ - app/views/foreman_users/syusers/edit.js.erb
124
+ - app/views/foreman_users/sygroups/edit.html.erb
125
+ - app/views/foreman_users/sygroups/destroy.js.erb
126
+ - app/views/foreman_users/sygroups/create.js.erb
127
+ - app/views/foreman_users/sygroups/new.html.erb
128
+ - app/views/foreman_users/sygroups/update.js.erb
129
+ - app/views/foreman_users/sygroups/new.js.erb
130
+ - app/views/foreman_users/sygroups/_sygroup_td.html.erb
131
+ - app/views/foreman_users/sygroups/show.html.erb
132
+ - app/views/foreman_users/sygroups/index.html.erb
133
+ - app/views/foreman_users/sygroups/_list.html.erb
134
+ - app/views/foreman_users/sygroups/_form.html.erb
135
+ - app/views/foreman_users/sygroups/edit.js.erb
136
+ - app/views/foreman_users/sygroups/_sygroup.html.erb
95
137
  - app/views/foreman_users/hosts/hosts/new_action.html.erb
96
138
  - app/views/foreman_users/hosts/new_action.html.erb
97
139
  - app/assets/javascripts/application.js
98
140
  - app/overrides/dashboard/index/sample_override.html.erb.deface
99
141
  - app/controllers/foreman_users/syusers_controller.rb
142
+ - app/controllers/foreman_users/sygroups_controller.rb
143
+ - app/controllers/foreman_users/syusermodels_controller.rb
100
144
  - app/helpers/foreman_users/syusers_helper.rb
101
145
  - app/models/foreman_users/syuser.rb
102
146
  - app/models/foreman_users/sygroup.rb
147
+ - app/models/foreman_users/syusermodel.rb
103
148
  - config/routes.rb
149
+ - db/migrate/20150918050249_create_syusermodels.rb
104
150
  - db/migrate/20150918050239_create_sygroups.rb
105
151
  - db/migrate/syusers/edit.html.erb
106
152
  - db/migrate/syusers/new.html.erb
File without changes