Manage Learn to apply best practices and optimize your operations.

Restrict access to design elements using reader fields

Design elements are also Notes documents so access to these documents could be restricted using reader fields.

Design elements are also Notes documents so access to these documents could be restricted using reader fields. The following example shows how to restrict access to an agent so it can be executed just by a privileged group of users ([admin] role) without modifying the original code of the agent. There are some situations when the code of the agent cannot be modified (e.g. imported java agents). This method could be extended if it is necessary for other design elements like forms and views.
I'm using the function <getNoteID> that I've posted previously.  It is published at https://searchdomino.techtarget.com/tip/Change-Agents-from-PRIVATE-to-SHARED-and-vice-versa.  The function gets the NoteID of a design element that is referenced by name and type(e.g. "getUserInfo" - AGENT)
-----------------------------
Option Public

Declare Function NIFFindDesignNote Lib "nnotes.dll" (Byval hDb As Long, Byval noteName As Lmbcs String, Byval classType As Integer, hNote As Long) As Integer
Declare Function NSFDbOpen Lib "nnotes.dll" (Byval sDbName As Lmbcs String ,	hDb As Long) As Integer
Declare Function NSFDbClose Lib "nnotes.dll" (Byval hDb As Long) As Integer
Declare Function OSPathNetConstruct Lib "nnotes.dll" (Byval portName As Integer, Byval serverName As Lmbcs String, Byval fileName As Lmbcs String, Byval pathName As Lmbcs String) As Integer

Const MAXPATH = 256
Const	NOTE_CLASS_FORM = 0004		' form note 
Const	NOTE_CLASS_VIEW = 0008		' view note 
Const	NOTE_CLASS_FILTER = 0512		' filter note 
Const	NOTE_CLASS_FIELD	= 1024		' field note 

Function getNoteID(Byval servername As String,Byval filename As String,Byval notename As String, Byval notetype As Integer) As Long
	Dim hdb As Long
	Dim hnote As Long
	Dim pathname As String*MAXPATH
	Dim result As Integer
	'OSPathNetConstruct creates a full network path - pathname - specification for a Domino database file
	Call OSPathNetConstruct(0, servername, filename, pathname)
	'NSFDbOpen returns a handle  - hdb - to a database - pathname -
	result = NSFDbOpen(pathname, hdb)
	If result <> 0 Then
		Messagebox("Cannot open the database!")
		getNoteID = -1
		Goto endf
	End If
	'NIFFindDesignNote function returns the note ID of a form, view, shared folder, agent, or field note, given the name and NOTE_CLASS_xxx
	result = NIFFindDesignNote(hdb, notename, notetype, hnote)
	If result <> 0 Then
		Messagebox("Cannot find the note!")
		getNoteID = -1
		Goto dbclose
	End If
	getNoteID = hnote
	
dbclose:
	'NSFDbClose closes a previously opened database
	result = NSFDbClose(hdb)
	If result <> 0 Then
		Messagebox("Cannot close the database!")	
	End If
endf:	
End Function

-----------------------------------
The Sub is adding the reader field to the agent document 
-----------------------------------
Sub Initialize
Dim s As New NotesSession
	Dim db As NotesDatabase
	Dim noteID As Long
	Dim strNID As String
	Dim servername, dbname, notename As String
	
	servername="SEARCHDOMINO" ' "" for local
	dbname="TIPS.NSF"
	notetype = NOTE_CLASS_FILTER ' agent
	notename = "getUserInfo"
	
	Set db = s.GetDatabase(servername, dbname) 
	noteID = getNoteID(servername, dbname, notename, NOTE_CLASS_FILTER)
	If noteID = -1 Then 
		Goto ends
	End If
	strNID = Hex(noteID)
	Set doc = db.GetDocumentByID (strNID)
	If (Not doc Is Nothing )Then
	Dim newValues( 1 To 1 ) As String
		newValues( 1 ) = "[admin]"
		Dim readersItem As New NotesItem(doc, "docReaders", newValues, READERS)
		Call doc.Save( True, True )
		
		
	End If
ends:	
End Sub

Dig Deeper on Domino Resources - Part 5

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchWindowsServer

Search400

  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...

SearchDataCenter

SearchContentManagement

Close