public UserAccessLevelEditor(int targetUserId, UserAccessLevel newAccessLevel)
        {
            Data = new Dictionary <string, object>
            {
                ["aclUserId"] = targetUserId
            };

            switch (newAccessLevel)
            {
            case UserAccessLevel.Normal:
            {
                Data["userAccess"] = "remove";
                break;
            }

            case UserAccessLevel.ReadOnly:
            {
                Data["userAccess"] = "read-only";
                break;
            }

            case UserAccessLevel.ReadWrite:
            {
                Data["userAccess"] = "read-write";
                break;
            }

            case UserAccessLevel.Owner:
            {
                Data["userAccess"] = "owner";
                break;
            }
            }
        }
        private void btnAddNewItemToInventory_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (UserAccessLevel.getInstance().gsCurrentUserAccessLevel == "Admin")
                {
                    _ItemAdder.ShowDialog();
                }
                else
                {
                    MessageBoxResult result;
                    result = MessageBox.Show("You are NOT logged in as an Administrator and Therefore Have No Permission To Add " +
                                             " Items to The Inventory. Click OK To Retry Login or Cancel To Quit", "Access Denied",
                                             MessageBoxButton.OKCancel, MessageBoxImage.Hand);

                    if (result == MessageBoxResult.OK)
                    {
                        new LoginWindow().ShowDialog();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Esempio n. 3
0
 public User(string strName, string strUsername, string strPassword, UserAccessLevel usrAccess)
 {
     this.strName = strName;
     this.strUsername = strUsername;
     this.strPassword = strPassword;
     this.usrAccess = usrAccess;
 }
        /// <inheritdoc/>
        public override int GetHashCode()
        {
            var hashCode = base.GetHashCode();

            hashCode = hashCode *
                       -1521134295 + IsValueType.GetHashCode();
            hashCode = hashCode *
                       -1521134295 + Value.GetHashSafe();
            hashCode = hashCode *
                       -1521134295 + Timestamp.GetHashSafe();
            hashCode = hashCode *
                       -1521134295 + StatusCode.GetHashSafe();
            hashCode = hashCode *
                       -1521134295 + DataType.GetHashSafe();
            hashCode = hashCode *
                       -1521134295 + ValueRank.GetHashSafe();
            hashCode = hashCode *
                       -1521134295 + ArrayDimensions.GetHashSafe();
            hashCode = hashCode *
                       -1521134295 + AccessLevelEx.GetHashSafe();
            hashCode = hashCode *
                       -1521134295 + AccessLevel.GetHashSafe();
            hashCode = hashCode *
                       -1521134295 + UserAccessLevel.GetHashSafe();
            hashCode = hashCode *
                       -1521134295 + MinimumSamplingInterval.GetHashSafe();
            hashCode = hashCode *
                       -1521134295 + Historizing.GetHashSafe();
            return(hashCode);
        }
        public void GetWantedListenedGroups(UserAccessLevel currentAccessLevel, ISet <string> groups)
        {
            if (!InfoReady)
            {
                return;
            }

            var fetchedInfo = Info;

            if (fetchedInfo == null)
            {
                return;
            }

            // Want to listen to our user updates
            var idStr = Convert.ToString(fetchedInfo.Id);

            groups.Add(NotificationGroups.UserUpdatedPrefix + idStr);

            // Admins can get more info about themselves
            if (IsAdmin)
            {
                groups.Add(NotificationGroups.UserUpdatedPrefixAdminInfo + idStr);
            }
        }
        private void ReadRestrictionFromXML(UserAccessLevel accessLevel, XElement restrictionElement)
        {
            XAttribute attributeName = restrictionElement.Attribute("name");

            if (attributeName == null)
            {
                return;
            }

            RestrictionNode node = FindNode(attributeName.Value);

            if (node == null)
            {
                return;
            }

            XAttribute           attributeValue = restrictionElement.Attribute("value");
            UserRestrictionState state;

            if (attributeValue == null || !Enum.TryParse(attributeValue.Value, out state))
            {
                state = node.GetDefaultRestriction(accessLevel);
            }

            node.SetRestriction(accessLevel, node.name, state);
        }
        private void gridAccessLevels_SelectionChanged(object sender, EventArgs eventArgs)
        {
            if (gridAccessLevels.Selection.Count == 0)
            {
                return;
            }

            if (gridUsers.Selection.Count > 0)
            {
                gridUsers.Selection.Clear();
                gridUsers.QueueDraw();
                selectedUserId = null;
            }

            btnReset.Sensitive = false;
            UserAccessLevel newAccessLevel = (UserAccessLevel)((KeyValuePair <int, string>)gridAccessLevels.Model [gridAccessLevels.Selection [0]]).Key;

            if (newAccessLevel == selectedAccessLevel)
            {
                return;
            }

            selectedAccessLevel = newAccessLevel;
            UpdateTreeStore(restsRoot, TreeIter.Zero, true);
        }
        /// <summary>
        ///   Variant that returns also information if user login details were not provided at all
        /// </summary>
        public static AuthenticationResult HasAuthenticatedUserWithAccessExtended(this HttpContext context,
                                                                                  UserAccessLevel requiredAccess, AuthenticationScopeRestriction?requiredRestriction)
        {
            // Non-logged in is always allowed (even if scope restrictions don't match as in that case the user could
            // just not authenticate at all to have access, so preventing that seems a bit silly)
            if (requiredAccess == UserAccessLevel.NotLoggedIn)
            {
                return(AuthenticationResult.Success);
            }

            var user = context.AuthenticatedUser();

            if (user == null)
            {
                return(AuthenticationResult.NoUser);
            }

            if (!user.HasAccessLevel(requiredAccess))
            {
                return(AuthenticationResult.NoAccess);
            }

            if (requiredRestriction != null)
            {
                if (context.AuthenticatedUserRestriction() != requiredRestriction)
                {
                    return(AuthenticationResult.NoAccess);
                }
            }

            return(AuthenticationResult.Success);
        }
        public void SetRestriction(UserAccessLevel level, string restName, UserRestrictionState state)
        {
            if (restName == name)
            {
                int levelId = GetAccessLevelId(level);
                if (restrictions.ContainsKey(levelId))
                {
                    restrictions [levelId].State = state;
                }
                else
                {
                    restrictions.Add(levelId, new UserRestriction(levelId, restName, state));
                }

                return;
            }

            RestrictionNode node = FindNode(restName);

            if (node == null)
            {
                return;
            }

            node.SetRestriction(level, restName, state);
        }
        private void boolCellRend_Toggled(object o, ToggledArgs args)
        {
            TreeIter iter;

            restsTreeStore.GetIterFromString(out iter, args.Path);
            bool oldVal = (bool)restsTreeStore.GetValue(iter, 1);
            bool newVal = !oldVal;

            SetTreeStoreChildren(iter, newVal);
            if (newVal)
            {
                SetTreeStoreParent(iter, true);
            }

            btnApply.Sensitive = true;
            if (selectedAccessLevel == null)
            {
                return;
            }

            UserAccessLevel changedAccessLevel = selectedAccessLevel.Value;

            if (!changedAccessLevels.Contains(changedAccessLevel))
            {
                changedAccessLevels.Add(changedAccessLevel);
            }
        }
 private void btnProceedeToCheckout_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         if (UserAccessLevel.getInstance().gsCurrentUserAccessLevel != string.Empty)
         {
             double total;
             double.TryParse(txtblkReceiptTotalPrice.Text, out total);
             _Checkout.gsTotal      = total;
             _Checkout.gsNames      = receiptItemsNames;
             _Checkout.gsPrices     = receiptItemsPrice;
             _Checkout.gsQuantities = receiptItemsQty;
             _Checkout.ShowDialog();
         }
         else
         {
             MessageBoxResult result = MessageBox.Show("You are NOT logged in as an Administrator and Therefore Have No Permission To Sell " +
                                                       " Items. Click OK To Retry Login or Cancel To Quit", "Access Denied",
                                                       MessageBoxButton.OKCancel, MessageBoxImage.Hand);
             if (result == MessageBoxResult.OK)
             {
                 new LoginWindow().ShowDialog();
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Esempio n. 12
0
        public static bool HasAccess(this UserAccessLevel currentAccess, UserAccessLevel requiredAccess)
        {
            if (currentAccess == requiredAccess)
            {
                return(true);
            }

            switch (requiredAccess)
            {
            case UserAccessLevel.NotLoggedIn:
                // All possible currentAccess values are acceptable here
                return(true);

            case UserAccessLevel.RestrictedUser:
                return(currentAccess != UserAccessLevel.NotLoggedIn);

            case UserAccessLevel.User:
                return(currentAccess != UserAccessLevel.NotLoggedIn &&
                       currentAccess != UserAccessLevel.RestrictedUser);

            case UserAccessLevel.Developer:
                return(currentAccess == UserAccessLevel.Developer || currentAccess == UserAccessLevel.Admin);

            case UserAccessLevel.Admin:
                return(currentAccess == UserAccessLevel.Admin);

            default:
                throw new ArgumentOutOfRangeException(nameof(requiredAccess), requiredAccess, null);
            }
        }
Esempio n. 13
0
        public static UserAccessLevelVM SetSubData(UserAccessLevel item, Guid aid)
        {
            var model = UserAccessLevelVM.MToVM(item);

            model.AccessLevel  = StatusTypesReferencesVM.MToVM(StatusTypesReferencesService.GetByID(item.AccessLevelID));
            model.DateTimeData = DateTimeStorageVM.MToVM(DateTimeStorageService.GetByID(item.DateTimeStorageID));
            return(model);
        }
        private UserRestrictionState GetDefaultRestriction(UserAccessLevel level)
        {
            int levelId = GetDefaultAccessLevelId(level);

            return(restrictions.ContainsKey(levelId) ?
                   restrictions [levelId].State :
                   UserRestrictionState.Allowed);
        }
Esempio n. 15
0
 public ExcelUser(string firstName, string lastName, UserAccessLevel accessLevel = UserAccessLevel.Default)
 {
     Id          = Guid.NewGuid();
     FirstName   = firstName;
     LastName    = lastName;
     AccessLevel = accessLevel;
     //OnAccessLevelChanged += AccessLevelChanged;
 }
Esempio n. 16
0
        public static UserAccessLevelVM SetSubDataAdmin(UserAccessLevel model)
        {
            var data = UserAccessLevelVM.MToVM(model);

            data.AccessLevel  = StatusTypesReferencesVM.MToVM(StatusTypesReferencesService.GetByID(model.AccessLevelID));
            data.DateTimeData = DateTimeStorageVM.MToVM(DateTimeStorageService.GetByID(model.DateTimeStorageID));
            data.Application  = ApplicationInformationVM.MToVM(ApplicationInformationService.GetByID(model.ApplicationID));
            return(data);
        }
Esempio n. 17
0
        public static bool IsDeveloper(this UserAccessLevel level)
        {
            switch (level)
            {
            case UserAccessLevel.Admin:
            case UserAccessLevel.Developer:
                return(true);
            }

            return(false);
        }
        private void SetAccessLevelRestrictions(IList <UserAccessLevel> accessLevels)
        {
            if (accessLevels.Count == 0)
            {
                return;
            }

            string message;

            KeyValuePair <int, string> [] allAccessLevels = User.GetAllAccessLevels();
            if (accessLevels.Count == 1)
            {
                message = Translator.GetString("The default permissions for the access level of {0} were changed. " +
                                               "Do you want to reset the permissions of all users with access level of {0} to the new defaults?");
                message = string.Format(message, string.Format("\"{0}\"", allAccessLevels [(int)accessLevels [0]].Value));
            }
            else
            {
                message = Translator.GetString("The default permissions for the access levels of {0} were changed. " +
                                               "Do you want to reset the permissions of all users with access levels of {0} to the new defaults?");
                StringBuilder accessLevelsBuilder = new StringBuilder();
                for (int i = 0; i < accessLevels.Count; i++)
                {
                    UserAccessLevel accessLevel = accessLevels [i];
                    accessLevelsBuilder.AppendFormat("\"{0}\"", allAccessLevels.First(k => k.Key == (int)accessLevel).Value);
                    if (i < accessLevels.Count - 2)
                    {
                        accessLevelsBuilder.Append(", ");
                    }
                    else if (i < accessLevels.Count - 1)
                    {
                        accessLevelsBuilder.AppendFormat(" {0} ", Translator.GetString("and"));
                    }
                }
                message = string.Format(message, accessLevelsBuilder);
            }

            if (Message.ShowDialog(Translator.GetString("Access Level Permissions"), null,
                                   message, "Icons.Question32.png", MessageButtons.YesNo) == ResponseType.Yes)
            {
                foreach (UserAccessLevel level in accessLevels)
                {
                    foreach (User user in users)
                    {
                        if (user.UserLevel == level)
                        {
                            restsRoot.ResetLevelRestrictions(user.Id, level);
                        }
                    }
                }
            }

            accessLevels.Clear();
        }
Esempio n. 19
0
        private void btnLogin_Click(object sender, RoutedEventArgs e)
        {
            if (checkCredentials(txtbxUsername.Text, txtbxPassword.Password, ref accessLevel) == true)
            {
                UserAccessLevel.getInstance().gsCurrentUserAccessLevel = accessLevel;
                UserAccessLevel.getInstance().gsCurrentUserName        = currentUser;

                this.Close();
            }
            else
            {
                MessageBox.Show("The Credentials Entered Did NOT Match, Please Revise and Try Again", "Login Error", MessageBoxButton.OK, MessageBoxImage.Exclamation);
            }
        }
        private static bool CheckFolderContentsAccess(User?user, UserAccessLevel baseAccessLevel, StorageItem?folder)
        {
            if (!RequireAccessLevel(baseAccessLevel, user))
            {
                return(false);
            }

            // Base folder is null, and it has public read by default
            if (folder == null)
            {
                return(true);
            }

            return(folder.IsReadableBy(user));
        }
        private static bool RequireAccessLevel(UserAccessLevel level, User?user)
        {
            // All site visitors have the not logged in access level
            if (level == UserAccessLevel.NotLoggedIn)
            {
                return(true);
            }

            // All other access levels require a user
            if (user == null)
            {
                return(false);
            }

            return(user.HasAccessLevel(level));
        }
        private void WriteRestrictionToXML(XContainer parent, UserAccessLevel accessLevel)
        {
            UserRestrictionState state = GetRestriction(accessLevel);

            if (state != GetDefaultRestriction(accessLevel))
            {
                XElement restrictionElement = new XElement("restriction");
                restrictionElement.Add(new XAttribute("name", name));
                restrictionElement.Add(new XAttribute("value", state));
                parent.Add(restrictionElement);
            }

            foreach (RestrictionNode child in children)
            {
                child.WriteRestrictionToXML(parent, accessLevel);
            }
        }
        public void ResetLevelRestrictions(long userId, UserAccessLevel level)
        {
            UserRestrictionState state = GetRestriction(level);

            if (restrictions.ContainsKey(userId))
            {
                restrictions [userId].State = state;
            }
            else if (state != UserRestrictionState.Allowed)
            {
                restrictions.Add(userId, new UserRestriction(userId, name, state));
            }

            foreach (RestrictionNode child in Children)
            {
                child.ResetLevelRestrictions(userId, level);
            }
        }
        private void ReloadAccessLevelDefaults(UserAccessLevel level)
        {
            UserRestrictionState state = GetDefaultRestriction(level);
            int levelId = GetAccessLevelId(level);

            if (restrictions.ContainsKey(levelId))
            {
                restrictions [levelId].State = state;
            }
            else if (state != UserRestrictionState.Allowed)
            {
                restrictions.Add(levelId, new UserRestriction(levelId, name, state));
            }

            foreach (RestrictionNode child in Children)
            {
                child.ReloadAccessLevelDefaults(level);
            }
        }
Esempio n. 25
0
        private void SetProperties(t_user_access entity)
        {
            byte languageId = IidCulture.CurrentLanguageId;

            UserAccessId = entity.user_access_id;
            UserId       = entity.user_id;
            UserFullName = entity.user.full_name;

            if (entity.activity_id.HasValue)
            {
                AccessType = UserAccessType.Activity;
                Id         = entity.activity_id;
                Name       = entity.t_activity.get_name_translated(languageId);
            }
            else if (entity.country_id.HasValue)
            {
                AccessType = UserAccessType.Country;
                Id         = entity.country_id;
                Name       = entity.t_country.get_name_translated(languageId);
            }
            else if (entity.administrative_division_id.HasValue)
            {
                AccessType = UserAccessType.AdministratitveDivision;
                Id         = entity.administrative_division_id;
                Name       = entity.t_administrative_division.get_name_translated(languageId);
            }
            else if (entity.site_id.HasValue)
            {
                AccessType = UserAccessType.Site;
                Id         = entity.site_id;
                Name       = entity.t_site.name;
            }

            AccessLevel = entity.update_access ? UserAccessLevel.Update :
                          entity.view_access ?   UserAccessLevel.View :
                          UserAccessLevel.None;
        }
Esempio n. 26
0
        protected override void btnEdit_Clicked(object o, EventArgs args)
        {
            int selectedRow = grid.FocusedRow;

            if (selectedRow < 0)
            {
                return;
            }

            User user = entities [selectedRow];

            selectedId = user.Id;

            if (user.Id == User.DefaultId)
            {
                MessageError.ShowDialog(string.Format(Translator.GetString("Cannot edit the default user \"{0}\"!"), user.Name), "Icons.User16.png");
                return;
            }

            if (!user.CanEdit())
            {
                MessageError.ShowDialog(Translator.GetString("Editing users with access level higher or equal of the current\'s one is not allowed!"));
                return;
            }

            // Added transaction to ensure that we are connected to the same server in case of
            // master-slave replication
            using (new DbMasterScope(BusinessDomain.DataAccessProvider)) {
                UserAccessLevel oldUserLevel = user.UserLevel;
                using (EditNewUser dialog = new EditNewUser(user, selectedGroupId)) {
                    if (dialog.Run() != ResponseType.Ok)
                    {
                        ReinitializeGrid(true, null);
                        return;
                    }

                    user       = dialog.GetUser().CommitChanges();
                    selectedId = user.Id;

                    bool refreshRestrictions = false;
                    if (oldUserLevel != user.UserLevel)
                    {
                        if (Message.ShowDialog(Translator.GetString("Reset Permissions"), null,
                                               Translator.GetString("The access level of the user was changed. " +
                                                                    "Do you want to reset the permissions of this user to the default ones for the new access level?"), "Icons.Question32.png",
                                               MessageButtons.YesNo) == ResponseType.Yes)
                        {
                            BusinessDomain.RestrictionTree.ResetLevelRestrictions(user.Id, user.UserLevel);
                            BusinessDomain.RestrictionTree.SaveRestrictions();
                            refreshRestrictions = true;
                        }
                    }

                    if (BusinessDomain.LoggedUser.Id == user.Id)
                    {
                        PresentationDomain.RefreshMainFormStatusBar();
                        if (refreshRestrictions)
                        {
                            PresentationDomain.RefreshMainFormRestrictions();
                        }
                    }
                }

                OnEntitiesChanged(user.Deleted ? UsersGroup.DeletedGroupId : user.GroupId);
            }
        }
Esempio n. 27
0
 private void InventoryEditorUI_Activated(object sender, EventArgs e)
 {
     userStatus = UserAccessLevel.getInstance().gsCurrentUserAccessLevel;
 }
Esempio n. 28
0
 private void InventoryEditorUI_GotFocus(object sender, RoutedEventArgs e)
 {
     userStatus = UserAccessLevel.getInstance().gsCurrentUserAccessLevel;
 }
Esempio n. 29
0
        public static Task ChangeUserAccessLevelAsync(this ActionScheduler actionScheduler, int userId, UserAccessLevel newLevel)
        {
            var action = new UserAccessLevelEditor(userId, newLevel);

            return(actionScheduler.ScheduleActionAsync <bool>(action));
        }
Esempio n. 30
0
        public static Task ChangeUserAccessLevelAsync(this ActionScheduler actionScheduler, Chat.User user, UserAccessLevel newLevel)
        {
            user.ThrowIfNull(nameof(user));

            return(ChangeUserAccessLevelAsync(actionScheduler, user.Id, newLevel));
        }
 public abstract void GetWantedListenedGroups(UserAccessLevel currentAccessLevel, ISet <string> groups);
 public UserAccessLevelAuthorizeAttribute(UserAccessLevel level)
 {
     _level = level;
 }