Page 1 sur 1

@UserRoles en Ls

MessagePublié: 27 Juil 2005 à 13:55
par Michael DELIQUE
la fonction renvois tous les roles de la LCA avec true si lapersonne a le role et false si elle ne l'a pas

Code : Tout sélectionner
Function UserRoles_LS(wnmUser As NotesName) As Variant
   
   'Indique pour l'utilisateur si il a ou pas le role déclaré dans la LCA de la base
   'chaque role de la base est passé en renvu. si le role est a true, l'utilsateur à le role si le role est a false l'utilsateur n'a pas le role
   
   'Déclaration des Variables
   Dim Session As NotesSession
   Dim DB As NotesDatabase
   Dim lstUR List As Integer
   Dim ACL As NotesACL
   Dim ACLEntry As NotesACLEntry
   
   On Error Goto ErreurUserRoles_LS
   
   lstUR("0") = False
   
   If wnmUser Is Nothing Then
      UserRoles_LS = lstUR
      Exit Function
   End If
   
   Set Session = New NotesSession
   Set DB = Session.CUrrentdatabase
   
   
   Set ACL = Nothing
   Set ACL = DB.ACL
   If ACL Is Nothing Then
      UserRoles_LS = lstUR
      Exit Function
   End If
   
   lstUR("DBAccess") = db.CurrentAccessLevel
   Forall Value In ACL.Roles
      lstUR(Strleft(Strright(Trim(Cstr(Value)),"["),"]")) = False
   End Forall
   
   Set ACLEntry = Nothing
   
   Set ACLEntry = ACL.GetEntry(wnmUser.Common)
   If ACLEntry Is Nothing Then
      Set ACLEntry = ACL.GetEntry(wnmUser.Abbreviated)
      If ACLEntry Is Nothing Then
         Set ACLEntry = ACL.GetEntry(wnmUser.Canonical)
         If ACLEntry Is Nothing Then
            Set ACLEntry = ACL.GetfirstEntry()
            If ACLEntry Is Nothing Then
               UserRoles_LS = lstUR
               Exit Function
            End If
         End If
      End If
   End If
   
   If ACLEntry Is Nothing Then
      UserRoles_LS = lstUR
   Else
      lstUR("0") = True
      Forall Value In ACLEntry.Roles
         lstUR(Strleft(Strright(Trim(Cstr(Value)),"["),"]")) = True
      End Forall
      UserRoles_LS = lstUR
   End If
   
   Set ACL = Nothing
   Set ACLEntry = Nothing
   Erase lstUR
   
   Exit Function
ErreurUserRoles_LS:
   
   Msgbox "(UserRoles_LS) Erreur " + Str(Err) + " : " + Cstr(Error)+Chr(10)+"Ligne N° "+Cstr(Erl),16," ERREUR !"
   lstUR("0") = False
   UserRoles_LS = lstUR
   Erase lstUR
   Exit Function
End Function

MessagePublié: 16 Mai 2006 à 14:20
par loutente
Est ce que ce code renvoi exactement l'equivalent de @UserRoles. Il me semble que non mais je me trompe peut etre :roll: . Que se passe t'il si la personne ne figure pas dans la LCA mais dans un groupe qui lui est dans la LCA :?: :?:

MessagePublié: 16 Mai 2006 à 19:19
par Michael DELIQUE
salut

Non, le code ne le gère pas dans ce cas le mieux est passer par un evaluate

dim vrValue as variant


vrValue = Evaluate("@ismember("+Role+";@userroles)")

MessagePublié: 22 Juin 2006 à 11:30
par Sylvain-PEPIN
Salut,

Ce matin j'ai reçu ça d'une newsletter à laquelle je suis abonné :

Code : Tout sélectionner
In the @formula language, you can easily check whether a user has a role with a single line of code:

@IsMember("[Admin]"; @UserRoles)

Before Notes/Domino 6, there was no equivalent in LotusScript, so you had to use the Evaluate function to get to the same result. This is still a viable method, it just takes more code:

Dim boolIsAdmin As Boolean
Dim varRoles As Variant
 
varRoles = Evaluate ("@UserRoles")

boolIsAdmin = False
Forall role In varRoles
  If role = "[Admin]" Then
    boolIsAdmin = True
    Exit Forall
  End If
End Forall

Notes/Domino 6 introduced a new method in the NotesDatabase class called QueryAcceessRoles. When you supply it with a name, it returns a list of roles the user has. It works the same as the previous method, but with the added flexibility of letting you query roles of other users. For example, this method is handy when you're processing multiple users and their security context relative to a collection of documents.

Dim session As New NotesSession
Dim db As NotesDatabase
Dim boolIsAdmin As Boolean
Dim varRoles As Variant

Set db = session.CurrentDatabase
varRoles = db.QueryAccessRoles(session.UserName)

boolIsAdmin = False
Forall role In varRoles
  If role = "[Admin]" Then
    boolIsAdmin = True
    Exit Forall
  End If
End Forall

@+
Sylvain