Group roles on the Web

The core of our parts website is created by Domino web agents. These agents are written in lotusscript and Several of the items are shown or hidden base on user roles.

Since there wasn't a function capable of checking roles for groups I wrote verifyUserRole. You pass in the Role, Session, and Canonical User name and it returns true or false.

As a test copy this code into an agent and call it via url from your web browser.

Sub Initialize
 Dim s As New NotesSession
 Dim db As NotesDatabase
 Dim acl As NotesACL
 Dim entry As NotesACLEntry
 Dim doc As notesdocument
 Dim nn As notesname
 Set doc = s.documentcontext
 Set nn = New notesname(doc.remote_user(0))
 role$ = "[com]"
 roleIsEnabled = verifyUserRole (role$, s, nn.Canonical)
 If roleIsEnabled Then
  Print role$ & " is enabled for user " & nn.Abbreviated
  Print role$ & " isn't enabled for user " & nn.Abbreviated
 End If
End Sub

Function verifyUserRole (role As String, s As NotesSession, user_Name As String) As Variant
 Dim acl As NotesACL 
 Dim entry As NotesACLEntry
 Dim currdb As NotesDatabase 
 Dim GroupsView As NotesView
 Dim groupdoc As NotesDocument
 Set currdb = s.CurrentDatabase
 Dim NAdb As New NotesDatabase(currdb.Server,"names.nsf")
 Set acl = currdb.ACL
 Set GroupsView = NAdb.GetView("Groups")
 roleIsEnabled = False
'Check to see if the user is listed directly in the ACL  
 Set entry = acl.GetEntry( user_Name )
 If Not entry Is Nothing Then
  If entry.Isroleenabled(role$) Then
   verifyUserRole = True
   '  print "User role" & role & " is enabled for " & user_Name
   Exit Function
  End If
'User is not listed get first entry in the ACL to look for groups
  Set entry = acl.GetFirstEntry 
  While Not entry Is Nothing 
   '  print "entry " & entry.name & " <br>"
   If entry.Isgroup Then
    '  print entry.name & " is a group<br>"
    If entry.IsRoleEnabled(role)Then
     '  print "The " & role & " role is enabled for " & user_Name & " in group " & entry.name & "<br>"
'Find group in the Address Book
     Set groupdoc = GroupsView.GetDocumentByKey(entry.name) 
     If Not groupdoc Is Nothing Then
'Roll through members and check for current user
      Forall names In groupdoc.members 
       If user_Name = names Then
        '  print "verified <br>"
        verifyUserRole =True 'role is enabled for user
        Exit Function
        Exit Forall
       End If
      End Forall
     End If
    End If
   End If
'Get next ACL entry
   Set entry = acl.GetNextEntry(entry)
 End If
End Function

This was first published in July 2002

There are Comments. Add yours.

TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.