Copyright 2004 by gINT Software. All rights reserved worldwide.
GR009.TXT
gINT Rules Code Samples - 009
Requires gINT version 6.1.016 or later.
NOTE: Code samples are provided free of charge and as-is. gINT Software makes no claim or warranty as to the accuracy of the samples. It is the responsibility of the user to ensure that the code performs as it should. Comments, suggestions, and error reports are appreciated.
Description
===========
(Our thanks to Bill Reynolds of Manitoba Hydro for the idea for this code sample. He has implemented a more sophisticated version of this code on the Manitoba Hydro system.)
Illustrates the use of gINT Rules to restrict modification of particular tables in a project database by reading the network user name of the currently logged-in user and looking up his department in the organization. Each table allows different categories of personnel to perform edits. If the current user does not belong to one of the categories that has modification rights to the current table, the modifications are not saved.
This code is based on a library table list of all personnel. See Data Design:Library Data for the structure used by this sample. You can change it to meet your needs. This table assigns a department to each person that will need to have access to projects in Input. You could store this list in code or in an external data file. Note that none of this security code works if all users have access to the gINT Rules code and the library table with the personnel. You must lock the library to prevent general access. Do this in the Utilities:Lib Merge/Copy application under the File:Secure Library menu item.
Besides the library table, you will also have to modify the GR009 DEPARTMENTS lookup list (Data Design:Lookup Lists) to reflect your categories.
For each table that you wish to restrict access, you need to create a gINT Rules procedure and assign it to the "gINT Rules Procedure on Save" property of the table. At the top of each of these procedures you would have the following code:
If NoRightToTableFnB(xxxxx) Then Exit Sub
where "xxxxx" are the categories of personnel that have modification rights to the table. These categories are specified in the sample code as the sum of the constants that represent each category. These are defined in the Declarations section of the GR009 COMMON PROCEDURES module:
Public Const gi_TableType_Administrator As Integer = 0
Public Const gi_TableType_Lab As Integer = 1
Public Const gi_TableType_Geotech As Integer = 2
Public Const gi_TableType_Clerical As Integer = 4
You would change these categories to match your needs. They must match those defined in the library table of personnel. However, except for the Administrator that has full rights to all tables and can have any value less than 1, the category constants must increase by a factor of 2 from the preceeding category. The NoRightToTableFnB function relies on this.
If a table allows just geotechnical personnel to edit the data, the above code becomes:
If NoRightToTableFnB(gi_TableType_Geotech) Then Exit Sub
That is, if the currently logged-in user does not fall under the Geotech personnel category, edits cannot be made.
If a table allows both geotechnical and lab personnel to edit the data:
If NoRightToTableFnB(gi_TableType_Geotech + gi_TableType_Lab) Then Exit Sub
If only an adminstrator can perform edits:
If NoRightToTableFnB(gi_TableType_Administrator) Then Exit Sub
This is the only case where the gi_TableType_Administrator constant is needed. The NoRightToTableFnB always allows edits by an administrator with all other combinations.
The network user name is obtained using a Windows API call (GetUserName). The declaration is in the Declarations section of the common procedures module.
To allow all users access to a table, just omit the above line of code.
!!!!!
IMPORTANT NOTE:
You must put in actual network log-in names that exist on your network in the library table to exercise the code.
!!!!!
*************************************************
Revision History
================
10 April 2004:
Initial upload
*************************************************
INCLUDED FILES:
GR009.GLB:
gINT Rules code modules:
GR009 Main
LabTesting
Lithology
Point
Project
Sample
GR009 COMMON PROCEDURES NetworkUserNameFnS
NoRightToTableFnB
Library Tables : GR009 PERSONNEL
Lookup Lists : GR009 DEPARTMENTS
GR009.GPJ:
Sample project that makes use of the code modules.
*************************************************
INSTALLATION PROCEDURE:
Copy the files wherever you prefer. To see the gINT Rules code modules you must either merge the GLB into your library (Utilities:Lib Merge/Copy) or change to the included library (File:Change Library).
*************************************************