1c 8.3 responsible current user. How to find out if a certain role is available to the current user

The parameters under consideration in 1C:Enterprise are presented as a metadata object. Essentially, it is nothing more than a global variable bound to the current session.

A global variable is the same variable as any other, but its peculiarity is that it can be accessed from anywhere in the program, and in the case of a session parameter, this works only within the current session.

Because the session parameter is a metadata object, it has certain features:

  • It may be of a certain type. The allowed types are platform specific. The list of them is quite extensive, but even if this list does not contain the one you need, you can always serialize the value and store it in the parameter as a string.
  • The rights to it, as well as to any other metadata object, can be limited by roles (both for writing and for reading). At the same time, there is a peculiarity when using it in RLS, but this will be discussed below.
  • It has a limit on the amount of data placed in serialized form. Their volume should not exceed 4 GB.

If session parameter type:

  • FixedArray
  • FixedCollection
  • FixedStructure

Then the value of the collection element can be Undefined.

The main area of ​​parameters is the use of their values ​​in RLS requests (restriction of access at the record level).

For example, we need to set a condition for the current user in an RLS request. To do this, we set the session parameter "CurrentUser", from the code of the built-in language, set the value:

SessionParameters.CurrentUser =<значение>

Table.User = &CurrentUser

Using the session parameter in this way does not take into account the read rights of the parameter, but you can try to get their value from the built-in language:

CurrentUser = SessionParameters.CurrentUser;


You can set a session parameter, that is, its value, only programmatically and only on the server. To do this, you need to call a server procedure from the client. When accessing a session parameter (setting, getting), if the parameter is not initialized, the procedure will be called SettingSessionParameters in the session module. This procedure has one parameter Required Options– an array of session parameter identifiers to be set. SettingSessionParameters also called when a connection is established with information base before calling all other handlers. In this case Required Options will be equal to Undefined.

It is recommended to use deferred (lazy) initialization, that is, initialize session parameters on demand, and not at system startup, since not all session parameters are required directly at system startup. Lazy initialization is done like this:

Procedure SettingSessionParameters(SessionParameterNames) If SessionParameterNames is Undefined Then IfParameterName = "CurrentUser" Then SessionParameters.CurrentUser = ; ElseIf ParameterName = " CurrentOrganization" Then SessionParameters.CurrentOrganization = ; // etc. EndIf; EndIf; EndProcedurevalue>value>>

Since the session parameter is bound to the session, it will not be possible to access the session parameter from a method running in the background, since it will be a different session. This nuance can come as a surprise, so it's best to prepare for it in advance by passing the desired value as a method parameter and initializing from a session parameter at the beginning of the procedure.

  • CURRENT RELEASES 1C
  • CODE EXAMPLES ON THE 1C PLATFORM
Roles, access rights in 1C 8.x
How can I find out if a certain role is available to the current user?
If Not RoleAvailable("Manager") Then Report("Viewing orders from buyers is not allowed!"); EndIf;
How to get information about configuration roles?
Function List of Possible Configuration Roles() List of Roles = new List of Values; ConfigRoles = Metadata.Roles; For each Role from RoleConfiguration Loop ListRoles.Add(Role.Name); EndCycle; Return List of Roles; EndFunctions
How to execute code without checking rights?
1. Use privileged module 2. Placement program code, which should be executed WITHOUT RESTRICTION CONTROL, into a common module with the PRIVILEGE flag set for the module. Use privileged mode of program code execution Similar to the mode of operation of the code of privileged modules. The mode can be enabled/disabled using the built-in language: SetPrivilegedMode(<Включить>) Parameter<Включить>(required) Type: Boolean. Determines whether the privileged mode will be enabled: True - enable the mode; False - turn off the mode. the PrivilegedMode() function allows you to determine whether privileged mode is enabled or not. Using the privileged mode allows, firstly, to speed up the work, since there will be no restrictions on access to data, and secondly, it allows you to perform operations with data on behalf of users to whom this data is not available. Privileged mode is recommended when it is logically necessary to turn off permissions checks, or when you can turn off permissions checks to speed things up. It is permissible to use the privileged mode when working with data on behalf of a certain user does not violate the access rights set for this user.

Session parameters 1C 8.3- a variable that stores the value desired parameter for the duration of the user session. In fact, this is a kind of global variable tied to the session of the current user.

Using session parameters in 1C

Session parameters are set only programmatically; there is no universal interface for setting session parameters in the system. Usually they are set at system startup, in the "Session module". If the parameter is not defined, an error will be raised while accessing it.

An example of setting the session parameter 1C

Let's look at a typical use case for session parameters - setting the current user. I will take an example from preparation for .

In the metadata tree, let's create a new session parameter - CurrentUser, assign a type to it - DirectoryReference.Individuals:

Get 267 1C video lessons for free:

In the session module, let's create a procedure that will determine the current session parameter:

Procedure code:

Procedure SettingSessionParameters(RequiredParameters) //we are looking for physical. face by username CurrentUser = Directories. Individuals. FindByName(UserName() ) ; // if not found, create a new one If CurrentUser. Empty() Then NewUser = Directories. Individuals. CreateElement() ; NewUser. Name = Username() ; NewUser. Write() ; CurrentUser = NewUser. Link; EndIf ; //assign the CurrentUser session parameter a link to the directory of individuals SessionParameters. CurrentUser = CurrentUser; EndProcedure

Loading...
Top