为了在Rally中唯一标识用户,我们希望更新用户的“显示名称”字段,以便识别具有相同名称的2个人。
e.g. John D(johnd@test.com)
John G(johng@test.com)
尝试下面的代码段以获取Rally中的所有用户,然后使用update()
OR post()
方法更改displyname格式。
import sys
from pyral import Rally, rallyWorkset
options = [arg for arg in sys.argv[1:] if arg.startswith('--')]
args = [arg for arg in sys.argv[1:] if arg not in options]
server = "rally1.rallydev.com"
apikey = "<rally_api_key>"
workspace = "<myworkspace>"
#project = "<myproject>"
rally = Rally(server,apikey=apikey, workspace=workspace)
rally.enableLogging('mypyral.log')
all_users = rally.getAllUsers()
for user in all_users:
tz = user.UserProfile.TimeZone or 'default'
role = user.Role or '-No Role-'
values = (int(user.oid), user.Name, user.UserName, role, tz)
print("%12.12d %-24.24s %-30.30s %-12.12s" % values)
不提供任何输出 - 逻辑变为无限循环
是否有其他方法可以更新所有用户的“显示名称”字段。
答案 0 :(得分:0)
不确定这是否有帮助,但它适用于Ruby:
$ cat -n Print-All-Users-short.rb
1 #!/usr/bin/env ruby
2 $my_base_url = 'http://rally1.rallydev.com'
3 $my_username = 'Secret'
4 $my_password = 'MoreSecret'
5 $my_workspace = 'Integrations'
6
7 require './MyVars.rb' if FileTest.exist?( './MyVars.rb' )
8 require 'rally_api'
9
10 @rallycon = RallyAPI::RallyRestJson.new({
11 :base_url => $my_base_url,
12 :username => $my_username,
13 :password => $my_password,
14 :workspace => $my_workspace,
15 :version => 'v2.0',
16 :headers => RallyAPI::CustomHttpHeader.new(:name=>'Print-All-Users-short.rb', :vendor=>'MySelf', :version=>'3.14159')
17 })
18
19 all_users = @rallycon.find(RallyAPI::RallyQuery.new(
20 :type => :user,
21 :query_string => "(ObjectID > 0)",
22 :fetch => true))
23
24 if all_users.count < 1 then # Did we find too few?
25 print "ERROR: Query returned nothing.\n"
26 exit (-1)
27 end
28 print "Query returned #{all_users.count} users.\n"
$ ./Print-All-Users-short.rb
Query returned 109 users.
答案 1 :(得分:0)
我能够使用以下代码更新displayname字段。
require 'rally_api'
#require 'rally_user_management'
require 'csv'
require './lib/go_update_user_attributes.rb'
$input_filename_arg = ARGV[0]
if $input_filename_arg == nil
# This is the default of the file to be used for uploading user permissions
$input_filename = 'update_user_attributes_template.txt'
else
$input_filename = File.dirname(__FILE__) + "/" + $input_filename_arg
end
begin
go_update_user_attributes($input_filename)
end
您唯一需要确保的是您作为参数提供的输入文件应该是文本文件而不是CSV,Excel等。 您的输入文件 - update_user_attributes_template.txt
UserID LastName FirstName DisplayName Role OfficeLocation Department CostCenter Phone NetworkID DefaultWorkspaceName DefaultProjectName TimeZone
testuser@cisco.com dummy name (testuser)
$ update_user_attributes.rb update_user_attributes_template.txt