吉拉 +萨翁+红宝石问题

发布于 2024-12-02 02:25:35 字数 3271 浏览 0 评论 0原文

我正在尝试将我的新应用程序与 JIRA 集成,以管理客户的支持票证。我设想系统所做的是在 before_filter 中从 JIRA 中收集用户帐户 - 从中​​我可以提取帐户列表以及没有的帐户列表,如果他们没有帐户列表,那么我们根据他们的详细信息创建一个帐户Rails 应用程序。问题是,我在做一些事情时遇到了重大问题,例如从 jira-users 组中删除用户并将其添加到我为客户创建的名为客户支持的单独组中。这是我当前拥有的代码:

def current_jira_user
    # Fetch the current user in JIRA, if we don't exist, create it!
    user_try = @jira.request :get_user do |soap|
      soap.body = { :token => @token, :username => "#{current_user.username}" }
    end
    if user_try.to_hash[:get_user_response][:get_user_return][:href].nil?
      # We need to create the user
      @jira.request :create_user do |soap|
        soap.body = {
            :token => @token,
            :username => "#{current_user.username}",
            :password => UUID.new.to_s,
            :fullName => current_user.full_name,
            :email => "[email protected]" #this is such a hack to get around JIRA's "you've got an account" email
        }
      end
      new_user = RemoteUser.find(current_user.username)
      @jira.request :remove_user_from_group do |soap|
        soap.body = { :token => @token, :group => RemoteGroup.find('jira-users'), :ruser => new_user }
      end
      @jira.request :add_user_to_group do |soap|
        soap.body = { :token => @token, :group => RemoteGroup.find('customer-support'), :ruser => new_user }
      end
      new_user[:email] = current_user.email
      @jira.request :update_user do |soap| # change their email to the valid one
        soap.body = { :token => @token, :ruser => new_user }
      end
      new_user
    else
      user_try.to_hash[:get_user_response][:get_user_return]
    end
  end

  def verify_jira_connection
    # Verify that we can reach the JIRA instance
    @jira = Savon::Client.new do
      wsdl.document = JIRA_SOAP_URI
    end
    @jira.http.read_timeout = 300
    @jira.http.auth.ssl.verify_mode = :none

    @auth = @jira.request :login do |soap|
      soap.body = { :username => JIRA_LOGIN, :password => JIRA_PASSWORD }
    end
    @token = @auth.to_hash[:login_response][:login_return]
  end

## REMOTE CLASSES
  class RemoteUser
    include Savon::Model

    client do
      http.headers["Pragma"] = "no-cache"
      http.auth.ssl.verify_mode = :none
    end

    namespace "http://beans.soap.rpc.jira.atlassian.com"
    endpoint JIRA_SOAP_URI

    basic_auth JIRA_LOGIN, JIRA_PASSWORD

    actions :get_user

    def self.find(username)
      get_user(:username => username).to_hash
    end
  end

  class RemoteGroup
    include Savon::Model

    client do
      http.headers["Pragma"] = "no-cache"
      http.auth.ssl.verify_mode = :none
    end

    namespace "http://beans.soap.rpc.jira.atlassian.com"
    endpoint JIRA_SOAP_URI

    basic_auth JIRA_LOGIN, JIRA_PASSWORD

    actions :get_group

    def self.find(group)
      get_group(:groupName => group).to_hash
    end
  end

用户创建得很好,但是当我进行removeUserFromGroup 调用时,我得到 (soapenv:Server.userException) com.atlassian.jira.rpc.exception.RemoteValidationException: group name can为 null,需要一个值。由于我们使用了 Ruby 1.9.2,因此不再使用 Jira4R gem。任何帮助表示赞赏。谢谢!

I am trying to get my new application integrated with JIRA for management of our customer's support tickets. What I had envisioned the system doing was in a before_filter gathering a user's account from within JIRA - from that I can pull up a list of accounts and what not, and if they don't have one then we create one based on their details in the Rails application. Thing is I'm having major issues doing things like removing the user from the jira-users group and adding them to a separate group I have for customers called customer-support. This is the code I have currently:

def current_jira_user
    # Fetch the current user in JIRA, if we don't exist, create it!
    user_try = @jira.request :get_user do |soap|
      soap.body = { :token => @token, :username => "#{current_user.username}" }
    end
    if user_try.to_hash[:get_user_response][:get_user_return][:href].nil?
      # We need to create the user
      @jira.request :create_user do |soap|
        soap.body = {
            :token => @token,
            :username => "#{current_user.username}",
            :password => UUID.new.to_s,
            :fullName => current_user.full_name,
            :email => "[email protected]" #this is such a hack to get around JIRA's "you've got an account" email
        }
      end
      new_user = RemoteUser.find(current_user.username)
      @jira.request :remove_user_from_group do |soap|
        soap.body = { :token => @token, :group => RemoteGroup.find('jira-users'), :ruser => new_user }
      end
      @jira.request :add_user_to_group do |soap|
        soap.body = { :token => @token, :group => RemoteGroup.find('customer-support'), :ruser => new_user }
      end
      new_user[:email] = current_user.email
      @jira.request :update_user do |soap| # change their email to the valid one
        soap.body = { :token => @token, :ruser => new_user }
      end
      new_user
    else
      user_try.to_hash[:get_user_response][:get_user_return]
    end
  end

  def verify_jira_connection
    # Verify that we can reach the JIRA instance
    @jira = Savon::Client.new do
      wsdl.document = JIRA_SOAP_URI
    end
    @jira.http.read_timeout = 300
    @jira.http.auth.ssl.verify_mode = :none

    @auth = @jira.request :login do |soap|
      soap.body = { :username => JIRA_LOGIN, :password => JIRA_PASSWORD }
    end
    @token = @auth.to_hash[:login_response][:login_return]
  end

## REMOTE CLASSES
  class RemoteUser
    include Savon::Model

    client do
      http.headers["Pragma"] = "no-cache"
      http.auth.ssl.verify_mode = :none
    end

    namespace "http://beans.soap.rpc.jira.atlassian.com"
    endpoint JIRA_SOAP_URI

    basic_auth JIRA_LOGIN, JIRA_PASSWORD

    actions :get_user

    def self.find(username)
      get_user(:username => username).to_hash
    end
  end

  class RemoteGroup
    include Savon::Model

    client do
      http.headers["Pragma"] = "no-cache"
      http.auth.ssl.verify_mode = :none
    end

    namespace "http://beans.soap.rpc.jira.atlassian.com"
    endpoint JIRA_SOAP_URI

    basic_auth JIRA_LOGIN, JIRA_PASSWORD

    actions :get_group

    def self.find(group)
      get_group(:groupName => group).to_hash
    end
  end

Users are created just fine, but when I get to the removeUserFromGroup call, I get (soapenv:Server.userException) com.atlassian.jira.rpc.exception.RemoteValidationException: group name cannot be null, needs a value. Using the Jira4R gem is out thanks to our using Ruby 1.9.2. Any help is appreciated. Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

攀登最高峰 2024-12-09 02:25:35

也许您需要明确发送名称?

:group => RemoteGroup.find('jira-users').name

如果您愿意进行一些重写

:group => RemoteGroup.find('jira-users')

,您可以尝试使用与 Ruby 1.9 兼容的 jira4r 分支

Maybe you need to explicitly send the name?

:group => RemoteGroup.find('jira-users').name

instead of this

:group => RemoteGroup.find('jira-users')

If you were willing to do some rewriting, you could try using a Ruby 1.9-compatible fork of jira4r

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文