/// <summary> /// Initializes the list of objects according to the user rights. /// </summary> public void Init(BaseTable <Obj> objTable, UserRights userRights) { ArgumentNullException.ThrowIfNull(objTable, nameof(objTable)); ArgumentNullException.ThrowIfNull(userRights, nameof(userRights)); try { if (!objTable.TryGetIndex("ParentObjNum", out ITableIndex parentObjIndex)) { throw new ScadaException(CommonPhrases.IndexNotFound); } foreach (Obj obj in objTable.Enumerate()) { if (obj.ParentObjNum == null && userRights.GetRightByObj(obj.ObjNum).View) { Add(new ObjectItem(obj, 0)); AddChildObjects(parentObjIndex, userRights, obj.ObjNum, 0); } } } catch (Exception ex) { throw new ScadaException(Locale.IsRussian ? "Ошибка при инициализации списка объектов" : "Error initializing object list", ex); } }
/// <summary> /// Initializes the user menu. /// </summary> public virtual void Init(IWebContext webContext, User user, UserRights userRights) { ArgumentNullException.ThrowIfNull(webContext, nameof(webContext)); ArgumentNullException.ThrowIfNull(user, nameof(user)); ArgumentNullException.ThrowIfNull(userRights, nameof(userRights)); try { // add menu items from plugins foreach (PluginLogic pluginLogic in webContext.PluginHolder.EnumeratePlugins()) { MergeMenuItems(MenuItems, webContext.PluginHolder.GetUserMenuItems(pluginLogic, user, userRights), 0); } // add default menu items MergeMenuItems(MenuItems, new List <MenuItem> { MenuItem.FromKnownMenuItem(KnownMenuItem.Reports), MenuItem.FromKnownMenuItem(KnownMenuItem.About) }, 0); } catch (Exception ex) { webContext.Log.WriteError(ex, Locale.IsRussian ? "Ошибка при инициализации меню пользователя" : "Error initializing user menu"); } }
/// <summary> /// Adds the child objects of the specified object recursively. /// </summary> private void AddChildObjects(ITableIndex parentObjIndex, UserRights userRights, int parentObjNum, int parentLevel) { foreach (Obj childObj in parentObjIndex.SelectItems(parentObjNum)) { if (userRights.GetRightByObj(childObj.ObjNum).View) { Add(new ObjectItem(childObj, parentLevel + 1)); AddChildObjects(parentObjIndex, userRights, childObj.ObjNum, parentLevel + 1); } } }
/// <summary> /// Initializes the user reports. /// </summary> public override void Init(IWebContext webContext, User user, UserRights userRights) { ArgumentNullException.ThrowIfNull(webContext, nameof(webContext)); ArgumentNullException.ThrowIfNull(user, nameof(user)); ArgumentNullException.ThrowIfNull(userRights, nameof(userRights)); try { foreach (PluginLogic pluginLogic in webContext.PluginHolder.EnumeratePlugins()) { MergeMenuItems(MenuItems, webContext.PluginHolder.GetUserReports(pluginLogic, user, userRights), 0); } } catch (Exception ex) { webContext.Log.WriteError(ex, Locale.IsRussian ? "Ошибка при инициализации отчётов пользователя" : "Error initializing user reports"); } }