Internet Windows Android

1c 8.3 get the current user on the client. How to find out if a specific role is available to the current user

The considered parameters 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 only works within the current session.

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

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

If the type of the session parameter is:

  • FixedArray
  • Fixed collection
  • Fixed structure

Then the value of the collection item can be Undefined.

The main scope of parameters is the application of their values ​​in RLS (record-level access restriction) requests.

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

Session Parameters.CurrentUser =<значение>

Table.User = & CurrentUser

This use of the session parameter does not take into account the read permissions of the parameter, but you can try to get their value from the embedded language:

CurrentUser = SessionParameters.CurrentUser;


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

It is recommended to use deferred (lazy) initialization, that is, to 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 Setting SessionParameters (SessionParameterNames) If SessionParameterNames Are Undefined Then If ParameterName = "CurrentUser" Then SessionParameters.CurrentUser =; ElseIf ParameterName = "CurrentOrganization" Then SessionParameters.CurrentOrganization =; // etc. EndIf; EndIf; EndProcedure value> value >>

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

Parameters sessions 1C 8.3- a variable that stores the value of the required parameter for the duration of the user's 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 thrown during the call to it.

An example of setting the 1C session parameter

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

In the metadata tree, create a new session parameter - CurrentUser, assign it a type - ReferenceLink.

Get 267 1C video tutorials for free:

In the session module, we will create a procedure in which the current session parameter will be determined:

Procedure code:

Procedure for Setting SessionParameters (RequiredParameters) // looking for physical. face by username CurrentUser = Directories. Individuals. FindByDesign (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 reference of individuals Session Parameters. CurrentUser = CurrentUser; End of Procedure

5
When more fine tuning of access is required, the RLS - Record Level Security mechanism comes to the rescue. The configuration of the 1C: Enterprise 8 system was initially positioned as a program for multi-company accounting, and one of ... 3
Starting from the 8.0 platform of the 1C Enterprise system, it is possible to restrict user access rights at the record level. For this, the RLS (Record Level Security) mechanism is used. Such a "fine-tuning" can be ... 3
I often come across questions related to software creation and setting up user rights. In this article, I will provide examples for Normal and Managed applications that programmatically create a user in ... 2
Question: I have added a new user. I create new interface(copying the existing one) and indicate this interface as the main one for this user. The problem is that the created new interface ...

  • CURRENT RELEASES 1C
  • EXAMPLES OF CODE ON PLATFORM 1C
Roles, access rights in 1C 8.x
How do I know if a specific role is available to the current user?
If No RoleAvailable ("Manager") Then Report ("Viewing requests from buyers is not allowed!"); EndIf;
How do I get information about configuration roles?
FunctionPossibleConfigurationPossibleRoles () RoleList = newList of Values; RolesConfigurations = Metadata.Roles; For each Role from RoleConfiguration Cycle Role List.Add (Role.Name); End of Cycle; Return Role List; EndFunction
How can I execute code without checking rights?
1. Use a privileged module 2. Placement of the program code, which should be executed WITHOUT RESTRICTIONS CONTROL, in common module with the installation of the PRIVILEGED flag at the module. Use the privileged mode of execution of the program code Similar to the mode of operation of the code of privileged modules. The mode can be enabled / disabled by means of the built-in language: Set Preferred Mode (<Включить>) 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 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 who do not have access to this data. It is recommended to use the privileged mode when, from a logical point of view, you need to disable checking of rights, or when you can disable checking of rights to speed up the work. 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.