Sam Ruby wrote on 1/27/18 11:10 PM:
> On Sat, Jan 27, 2018 at 11:03 PM, Craig Russell <[email protected]> wrote:
>> I'm confused I guess.
Craig - it's not just you - I got caught by this exact problem earlier,
and couldn't figure out why until I had Sam code review. To add
insult... er, beautiful code separation to a complicated class
structure, the actual find() method is not in the person.rb file!
ASF::Person.find(id) will get you a Person, but it might not be real.
ASF::Person[id] will get you the Person, or nil.
The easiest thing is to look at the code (although I still want to
review the website to ensure the API docs are clearly pointed to), and
the comments do explain part of it. I don't remember where .find() is
declared, but ldap.rb line 650 defines [] like so:
# return person only if it actually exits
def self.[] id
person = super
person.attrs['dn'] ? person : nil
end
Since all this stuff is both a set of Ruby classes, plus actual lookups
into our actual LDAP system, that's why it's a bit complicated/
Make sense? It took me a while, but the complexity of where classes are
defined in whimsy/asf does make sense, since they provide a lot of
functionality from a pretty complex backend of data.
>>
>> I've seen lots of ASF::Person.find(id)
>>
>> Is there a way to determine if this is a real person?
>
> By issuing an LDAP query that either will return a result (if the
> person exists) or nil (if the person does not). For example:
>
> ASF::Person.find('rubys').attrs['dn']
>
>> Why are you suggesting ASF::Person[id]
>
> Because it is shorter and easier to type (and read) than the example I
> provided above.
>
>> I could not find the doc for these...
>>
>> ?
>
> https://whimsy.apache.org/docs/api/ASF/Person.html
> https://whimsy.apache.org/docs/api/ASF/Base.html
>
>> Craig
>
> - Sam Ruby
>
>>> On Jan 27, 2018, at 5:24 PM, Sam Ruby <[email protected]> wrote:
>>>
>>> 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
>>>>
>>
>> Craig L Russell
>> Secretary, Apache Software Foundation
>> [email protected] http://db.apache.org/jdo
>>
--
- Shane
https://www.apache.org/foundation/marks/resources