On Sat, Jan 27, 2018 at 7:56 PM, Craig Russell <[email protected]> wrote:
>
>> On Jan 27, 2018, at 4:25 PM, Sam Ruby <[email protected]> wrote:
>>
>> ASF::Person[userName] will return nil if the person does not exist,
>> otherwise it will return the ASF::Person object associated with this
>> person.
>
> Can you see what is wrong with this code?
>
>   def getMember(userId)
>     user = ASF::Person.find(userId)

Change above line to:

  user = ASF::Person[userId]

[question: is the above line needed?  user isn't used...]

>     mockId = params['mock']
>     if ASF::Person.find(mockId) != nil

Change the above line to:

  if mockId and ASF::Person[mockId]

ASF::Person.find will always return an object that can be used to query LDAP.

>       # if mock is set, set member to mock value
>       return mockId
>     else
>      return userId
>     end
>   end
>
> What I see is:
>
> http://whimsy.local/project/icla?token=1&mock=rubys
>
> member: rubys
>
> http://whimsy.local/project/icla?token=1
>
> member: null
>
>
>>
>> - Sam Ruby
>>
>> On Sat, Jan 27, 2018 at 7:11 PM, Craig Russell <[email protected]> wrote:
>>> Hi,
>>>
>>> I'm allowing users of project/icla to pretend to be another user for the 
>>> purpose of testing.
>>>
>>> I have this code that doesn't quite work:
>>>
>>>  def getUser(userName)
>>>    user = ASF::Person.find(userName)
>>>    mockName = params['mock']
>>>    if mockName != '' and ASF::Person.find(mockName).id == mockName
>>>      # if mock is set, set member to mock value
>>>      return mockName
>>>    else
>>>     return userName
>>>    end
>>>  end
>>>
>>> What I'm trying to do is to see if the mocked user actually exists.
>>>
>>> The code returns the mock name even if the mock name does not exist.
>>>
>>> What is the correct test for user exists?
>>>
>>> Thanks,
>>>
>>> Craig
>>>
>>> Craig L Russell
>>> Secretary, Apache Software Foundation
>>> [email protected] http://db.apache.org/jdo
>>>
>
> Craig L Russell
> Secretary, Apache Software Foundation
> [email protected] http://db.apache.org/jdo
>

Reply via email to