SetPeriodAccess(Begin_: DateTime; End_: DateTime; Grant: Boolean);
Begin_. Start time of time period.
End_. End time of time period.
Grant. The parameter determines accessibility in the specified time interval.
The SetPeriodAccess method sets parameters of the user access for the specified time interval.
If True is sent as a value of the Grant parameter, access in this time interval is allowed. If value of the parameter is False, the access will be denied.
A time interval is formed by setting start and end time in the Begin_ and End_ parameters, respectively. The Grant parameter determines whether access is available in this time interval.
The SetPeriodAccess method sets time interval with accuracy up to a second, the millisecond field must contain the 0 value.
To execute the example, make sure that security manager contains the USER user.
Add a link to the Metabase system assembly.
Sub UserProc;
Var
MB: IMetabase;
MS: IMetabaseSecurity;
MP: IMetabasePolicy;
User: ISecuritySubject;
LogonHP: ILogonHoursPolicy;
LH: ILogonHours;
d1, d2, d3, d4: DateTime;
i: Integer;
Lic: Object;
Begin
MB := MetabaseClass.Active;
// Check out license to work with security manager
Lic := MB.RequestLicense(UiLicenseFeatureType.Adm);
MS := MB.Security;
MP := MS.Policy;
// Get user parameters
User := MS.ResolveName("USER");
// Add schedule to enable access
LogonHP := MP.LogonHoursPolicy(User);
d1 := DateTime.ComposeTimeOfDay(0, 0, 0, 0);
d2 := DateTime.ComposeTimeOfDay(9, 0, 0, 0);
d3 := DateTime.ComposeTimeOfDay(18, 0, 0, 0);
d4 := DateTime.ComposeTimeOfDay(23, 59, 0, 0);
For i := 1 To 5 Do
LH := LogonHP.WeekDayHours(i As CalendarDayOfWeek);
LH.SetPeriodAccess(d1, d2, False);
LH.SetPeriodAccess(d2, d3, True);
LH.SetPeriodAccess(d3, d4, False);
LogonHP.WeekDayHours(i As CalendarDayOfWeek) := LH;
End For;
LH := LogonHP.WeekDayHours(CalendarDayOfWeek.Saturday); // Saturday
LH.SetPeriodAccess(d1, d4, False);
LogonHP.WeekDayHours(CalendarDayOfWeek.Saturday) := LH;
LH := LogonHP.WeekDayHours(CalendarDayOfWeek.Sunday); // Sunday
LH.SetPeriodAccess(d1, d4, False);
LogonHP.WeekDayHours(CalendarDayOfWeek.Sunday) := LH;
// Save changes
MS.Apply;
// Check in license
Lic := Null;
End Sub UserProc;
After executing the example, access parameters by days of week for the USER user are changed. The access under this user is allowed from Monday till Friday from 9 AM till 6 PM.
See also: