Mailinglist Archive: yast-commit (883 mails)

< Previous Next >
[yast-commit] <rest-service> master : model adapted to the YaST data structure
  • From: Jiri Suchomel <jsuchome@xxxxxxx>
  • Date: Tue, 7 Jul 2009 16:26:19 +0200
  • Message-id: <E1MOBcZ-0002r6-Kv@xxxxxxxxxxxxxxxx>
ref: refs/heads/master
commit 3ccb8e3bf1b38c051b07b2555115c54d13879926
Author: Jiri Suchomel <jsuchome@xxxxxxx>
Date: Tue Jul 7 16:26:19 2009 +0200

model adapted to the YaST data structure
---
plugins/users/app/controllers/users_controller.rb | 137 +++++++++------------
plugins/users/app/models/user.rb | 107 +++++++----------
2 files changed, 101 insertions(+), 143 deletions(-)

diff --git a/plugins/users/app/controllers/users_controller.rb
b/plugins/users/app/controllers/users_controller.rb
index e71ae28..04b6589 100644
--- a/plugins/users/app/controllers/users_controller.rb
+++ b/plugins/users/app/controllers/users_controller.rb
@@ -27,9 +27,6 @@ class UsersController < ApplicationController
"index" => [ "s", "uid" ],
# attributes to return for each user
"user_attributes" => [ "as", [ "cn" ]]
-# FIXME this way of passing array currently fails in ruby-dbus:
-# TypeError (can't convert Array into String):
-# /usr/lib64/ruby/vendor_ruby/1.8/dbus/type.rb:112:in `+'
}
users_map = YastService.Call("YaPI::USERS::UsersGet", parameters)
if users_map.nil?
@@ -37,9 +34,8 @@ class UsersController < ApplicationController
else
users_map.each do |key, val|
user = User.new
- # FIXME adapt the model to the YaPI return map
- user.login_name = key
- user.full_name = val["cn"]
+ user.uid = key
+ user.cn = val["cn"]
@users << user
end
end
@@ -57,42 +53,45 @@ class UsersController < ApplicationController
# list of attributes to return;
"user_attributes" => [ "as", [
"cn", "uidNumber", "homeDirectory",
- "grouplist", "loginShell", "groupname"
+ "grouplist", "uidloginShell", "groupname"
]]
}
user_map = YastService.Call("YaPI::USERS::UserGet", parameters)
# TODO check if it is not empty
- @user = User.new
- # FIXME adapt the model to the YaPI return map
- @user.login_name = id
- @user.full_name = user_map["cn"]
- @user.login_shell = user_map["loginShell"]
- @user.uid = user_map["uidNumber"]
- @user.home_directory= user_map["homeDirectory"]
- @user.default_group = user_map["groupname"]
+
+ @user = User.new
+
+#FIXME why User.new (user_map) does not work?
+
@user.grouplist = user_map["grouplist"]
+ @user.homeDirectory = user_map["homeDirectory"]
+ @user.groupname = user_map["groupname"]
+ @user.loginShell = user_map["loginShell"]
+ @user.uid = id
+ @user.uidNumber = user_map["uidNumber"]
+ @user.cn = user_map["cn"]

@user.sshkey = saveKey
return true
end

def createSSH
- if @user.home_directory.blank?
+ if @user.homeDirectory.blank?
save_key = @user.sshkey
- get_user @user.login_name
+ get_user @user.uid
@user.sshkey = save_key
end
- ret = @scr.read(".target.stat",
"#{@user.home_directory}/.ssh/authorized_keys")
+ ret = @scr.read(".target.stat",
"#{@user.homeDirectory}/.ssh/authorized_keys")
if ret.empty?
- logger.debug "Create: #{@user.home_directory}/.ssh/authorized_keys"
- @scr.execute(["/bin/mkdir", "#{@user.home_directory}/.ssh"])
- @scr.execute(["/bin/chown", "#{@user.login_name}",
"#{@user.home_directory}/.ssh"])
- @scr.execute(["/bin/chmod", "755", "#{@user.home_directory}/.ssh"])
- @scr.execute(["/usr/bin/touch",
"#{@user.home_directory}/.ssh/authorized_keys"])
- @scr.execute(["/bin/chown", "#{@user.login_name}",
"#{@user.home_directory}/.ssh/authorized_keys"])
- @scr.execute(["/bin/chmod", "644",
"#{@user.home_directory}/.ssh/authorized_keys"])
+ logger.debug "Create: #{@user.homeDirectory}/.ssh/authorized_keys"
+ @scr.execute(["/bin/mkdir", "#{@user.homeDirectory}/.ssh"])
+ @scr.execute(["/bin/chown", "#{@user.uid}",
"#{@user.homeDirectory}/.ssh"])
+ @scr.execute(["/bin/chmod", "755", "#{@user.homeDirectory}/.ssh"])
+ @scr.execute(["/usr/bin/touch",
"#{@user.homeDirectory}/.ssh/authorized_keys"])
+ @scr.execute(["/bin/chown", "#{@user.uid}",
"#{@user.homeDirectory}/.ssh/authorized_keys"])
+ @scr.execute(["/bin/chmod", "644",
"#{@user.homeDirectory}/.ssh/authorized_keys"])
end
- ret = @scr.execute(["echo", "\"#{@user.sshkey}\"", ">>",
"#{@user.home_directory}/.ssh/authorized_keys"])
+ ret = @scr.execute(["echo", "\"#{@user.sshkey}\"", ">>",
"#{@user.homeDirectory}/.ssh/authorized_keys"])
@error_id = ret[:exit]
if ret[:exit] != 0
@error_string = ret[:stderr]
@@ -103,37 +102,29 @@ class UsersController < ApplicationController
end
end

- def udate_user userId
+ # -------------------------------------------------------
+ # modify existing user
+ def update_user userId
ok = true

if not @user.sshkey.blank?
ok = createSSH
end

- command = ["/sbin/yast2", "users", "edit"]
+ config = {
+ "type" => [ "s", "local" ],
+ "uid" => [ "s", @user.uid ]
+ }
+ data = {
+ }

- command << "cn=\"#{@user.full_name}\"" if not @user.full_name.blank?
- if not @user.groups.blank?
- grp_string = @user.groups.map { |group| group[:id] }.join(',')
- command << "grouplist=#{grp_string}"
- end
-
- command << "gid=#{@user.default_group}" if not @user.default_group.blank?
- command << "home=#{@user.home_directory}" if not
@user.home_directory.blank?
- command << "shell=#{@user.login_shell}" if not @user.login_shell.blank?
- command << "username=#{userId}" if not userId.blank?
- command << "uid=#{@user.uid}" if not @user.uid.blank?
- command << "password=#{@user.password}" if not @user.password.blank?
- command << "ldap_password=#{@user.ldap_password}" if not
@user.ldap_password.blank?
- command << "new_uid=#{@user.new_uid}" if not @user.new_uid.blank?
- command << "new_username=#{@user.new_login_name}" if not
@user.new_login_name.blank?
- command << "type=#{@user.type}" if not @user.type.blank?
- command << "batchmode"
- ret = @scr.execute(command)
- if ret[:exit] != 0
+ ret = YastService.Call("YaPI::USERS::UserModify", config, data)
+
+ logger.debug "Command returns: #{ret.inspect}"
+
+ if ret != ""
ok = false
- @error_id = ret[:exit]
- @error_string = ret[:stderr]
+ @error_string = ret
else
@error_id = 0
@error_string = ""
@@ -141,55 +132,41 @@ class UsersController < ApplicationController
return ok
end

+ # -------------------------------------------------------
+ # add the new local user
def add_user
-# command = ["/sbin/yast2", "users", "add"]
-# command << "cn=\"#{@user.full_name}\"" if not @user.full_name.blank?
-# if not @user.groups.blank?
-# grp_string = @user.groups.map { |group| group[:id] }.join(',')
-# command << "grouplist=#{grp_string}"
-# end
-# command << "gid=#{@user.default_group}" if not @user.default_group.blank?
-# command << "home=#{@user.home_directory}" if not
@user.home_directory.blank?
-# command << "shell=#{@user.login_shell}" if not @user.login_shell.blank?
-# command << "username=#{@user.login_name}" if not @user.login_name.blank?
-# command << "uid=#{@user.uid}" if not @user.uid.blank?
-# command << "password=#{@user.password}" if not @user.password.blank?
-# command << "ldap_password=#{@user.ldap_password}" if not
@user.ldap_password.blank?
-# command << "no_home" if not @user.no_home.blank? and
@user.no_home.eql?('true')
-# command << "type=#{@user.type}" if not @user.type.blank?
-# command << "batchmode"

# FIXME mandatory parameters must be required on web-client side...
config = {
"type" => [ "s", "local" ]
}
data = {
- "uid" => [ "s", @user.login_name ]
+ "uid" => [ "s", @user.uid]
}
- data["cn"] = [ "s", @user.full_name ] unless
@user.full_name.blank?
- data["userPassword"] = [ "s", @user.password ] unless
@user.password.blank?
+#FIXME convert @user hash to data hash
+ data["cn"] = [ "s", @user.cn ] unless
@user.cn.blank?
+ data["userPassword"] = [ "s", @user.userPassword ] unless
@user.userPassword.blank?

ret = YastService.Call("YaPI::USERS::UserAdd", config, data)

logger.debug "Command returns: #{ret.inspect}"

return true if ret == ""
-
-# @error_id = ret[:exit] FIXME
@error_string = ret
return false
end

+ # -------------------------------------------------------
+ # delete existing local user
def delete_user
- command = ["/sbin/yast2", "users", "delete", "delete_home"]
- command << "uid=#{@user.uid}" if not @user.uid.blank?
- command << "username=#{@user.login_name}" if not @user.login_name.blank?
- command << "ldap_password=#{@user.ldap_password}" if not
@user.ldap_password.blank?
- command << "type=#{@user.type}" if not @user.type.blank?

- command << "batchmode"
+ config = {
+ "type" => [ "s", "local" ],
+ "uid" => [ "s", @user.uid ]
+ }
+
+ ret = YastService.Call("YaPI::USERS::UserDelete", config)

- ret = @scr.execute(command)
return true if ret[:exit] == 0

@error_id = ret[:exit]
@@ -256,12 +233,12 @@ class UsersController < ApplicationController
render ErrorResult.error(403, 1, "no permission") and return
end
@user = User.new
- if params[:users] && params[:users][:login_name]
- params[:id] = params[:users][:login_name] #for sync only
+ if params[:users] && params[:users][:uid]
+ params[:id] = params[:users][:uid] #for sync only
end
get_user params[:id]
if @user.update_attributes(params[:users])
- udate_user params[:id]
+ update_user params[:id]
if @error_id!=0
render ErrorResult.error(404, @error_id, @error_string) and return
end
diff --git a/plugins/users/app/models/user.rb b/plugins/users/app/models/user.rb
index e53c3a1..6e74268 100644
--- a/plugins/users/app/models/user.rb
+++ b/plugins/users/app/models/user.rb
@@ -1,65 +1,58 @@

class User

- attr_accessor :full_name,
- :groups,
- :grouplist,
- :default_group,
- :home_directory,
- :login_name,
- :login_shell,
+ attr_accessor :cn,
:uid,
- :password,
- :ldap_password,
- :type,
- :new_uid,
- :new_login_name,
- :no_home,
+ :uidNumber,
+ :gidNumber,
+ :grouplist,
+ :groupname,
+ :homeDirectory,
+ :loginShell,
+ :userPassword,
+ :addit_data,
+ :type,
:sshkey

+# :new_uid,
+# :new_login_name,
+# :no_home,
def id
- @login_name
+ @uid
end

def id=(id_val)
- @login_name = id_val
+ @uid = id_val
end

def initialize
- @no_home = false
- @full_name = ""
- @groups = ""
- @grouplist = {}
- @default_group = ""
- @home_directory = ""
- @login_shell = ""
- @login_name = ""
- @uid = ""
- @password = ""
- @ldap_password = ""
- @type = ""
- @new_uid = ""
- @new_login_name = ""
- @sshkey = ""
+ @cn = ""
+ @uid = ""
+ @uidNumber = ""
+ @grouplist = {}
+ @groupname = ""
+ @homeDirectory = ""
+ @loginShell = ""
+ @userPassword = ""
+ @type = "local"
+# @new_uid = ""
+# @new_login_name = ""
+ @sshkey = ""
end

def update_attributes usr
return false if usr==nil
- @no_home = usr[:no_home]
- @groups = usr[:groups]
- @grouplist = usr[:grouplist]
- @home_directory = usr[:home_directory]
- @type = usr[:type]
- @new_login_name = usr[:new_login_name]
- @default_group = usr[:default_group]
- @login_name = usr[:login_name]
- @uid = usr[:uid]
- @ldap_password = usr[:ldap_password]
- @login_shell = usr[:login_shell]
- @full_name = usr[:full_name]
- @password = usr[:password]
- @new_uid = usr[:new_uid]
- @sshkey = usr[:sshkey]
+ @grouplist = usr[:grouplist]
+ @homeDirectory = usr[:homeDirectory]
+ @type = usr[:type]
+ @groupname = usr[:groupname]
+ @loginShell = usr[:loginShell]
+ @userPassword = usr[:userPassword]
+ @uid = usr[:uid]
+ @uidNumber = usr[:uidNumber]
+ @cn = usr[:cn]
+
+ @sshkey = usr[:sshkey]
return true
end

@@ -69,26 +62,14 @@ class User

xml.user do
xml.tag!(:id, id )
- xml.tag!(:full_name, full_name )
- xml.tag!(:no_home, no_home, {:type => "boolean"} )
- xml.tag!(:default_group, default_group )
- xml.tag!(:home_directory, home_directory )
- xml.tag!(:login_shell, login_shell )
- xml.tag!(:login_name, login_name )
- xml.tag!(:uid, uid, {:type => "integer"})
- xml.tag!(:password, password )
- xml.tag!(:ldap_password, ldap_password )
+ xml.tag!(:cn, cn )
+ xml.tag!(:groupname, groupname)
+ xml.tag!(:loginShell, loginShell )
+ xml.tag!(:uid, uid )
+ xml.tag!(:uidNumber, uidNumber, {:type => "integer"})
+ xml.tag!(:userPassword, userPassword )
xml.tag!(:type, type )
- xml.tag!(:new_uid, new_uid )
- xml.tag!(:new_login_name, new_login_name )
xml.tag!(:sshkey, sshkey )
- xml.groups({:type => "array"}) do
- groups.split( "," ).each do |group|
- xml.group do
- xml.tag!(:id, group)
- end
- end
- end
xml.grouplist({:type => "array"}) do
grouplist.each do |group, val|
xml.group do
--
To unsubscribe, e-mail: yast-commit+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: yast-commit+help@xxxxxxxxxxxx

< Previous Next >
This Thread
  • No further messages