コード例 #1
0
ファイル: BlogService.cs プロジェクト: eouw0o83hf/Blog
        public void GrantUserPermission(int userId, PermissionEnum permission)
        {
            var dbUser = BlogDb.Users.FirstOrDefault(a => a.UserId == userId);
            if (dbUser == null)
            {
                return;
            }

            var dbPermission = BlogDb.Permissions.FirstOrDefault(a => a.Name == permission.ToString());
            if (!dbUser.UserPermissions.Any(a => a.PermissionId == dbPermission.PermissionId))
            {
                BlogDb.UserPermissions.InsertOnSubmit(new UserPermission
                {
                    PermissionId = dbPermission.PermissionId,
                    UserId = dbUser.UserId
                });

                BlogDb.SubmitChanges();
            }
        }
コード例 #2
0
 public BlogAuthorizeAttribute(PermissionEnum permission)
     : base()
 {
     Roles = permission.ToString();
 }
コード例 #3
0
ファイル: Permissions.cs プロジェクト: akoesnan/PraLoup
 private Permission(BaseEntity entity)
 {
     this.entity = entity;
     this.value = PermissionEnum.EmptyMask;
 }
コード例 #4
0
        /// <summary>
        ///     Creates new access budget right
        /// </summary>
        /// <param name="budgetId">ID of a budget</param>
        /// <param name="assignedUserId">Assigned user's ID</param>
        /// <param name="permission">Permission for right</param>
        /// <returns>False if user has already accessright to this budget or when adding failed. True otherwise.</returns>
        public async Task<bool> CreateBudgetAccessRight(Guid budgetId, Guid assignedUserId, PermissionEnum permission)
        {
            // create budget access right only if it isn't already present
            bool budgetAccessRightExists = await _db.BudgetAccessRights.Where(b => b.Budget.Guid == budgetId && b.UserProfile.Guid == assignedUserId).CountAsync() > 0;
            if (budgetAccessRightExists)
            {
                return false;
            }

            // find budget by its Id
            var budget = await this.GetBudgetById(budgetId);
            // finding creator by his ID
            var assignedUser = this.GetAccessRightsCreator(assignedUserId);

            var budgetAccessRight = new BudgetAccessRight
            {
                Budget = budget,
                Permission = permission,
                UserProfile = assignedUser
            };

            this.Validate(budgetAccessRight);
            
            // creating new budget access right
            return await this._db.AddOrUpdateAsync(budgetAccessRight);
        }
コード例 #5
0
        /// <summary>
        ///     Edits budget access right
        /// </summary>
        /// <param name="budgetAccessRightId">ID of changed access right</param>
        /// <param name="permission">New permission</param>
        /// <param name="userProfileId">New ID of a user</param>
        /// <returns></returns>
        public async Task EditBudgetAccessRight(Guid budgetAccessRightId, PermissionEnum permission, Guid userProfileId)
        {
            var accessRightToEdit = await this.GetBudgetAccessRightById(budgetAccessRightId);

            accessRightToEdit.Permission = permission;
            accessRightToEdit.UserProfile = await this.GetUserProfileById(userProfileId);

            this.Validate(accessRightToEdit);

            await this._db.AddOrUpdateAsync(accessRightToEdit);
        }
コード例 #6
0
        /// <summary>
        ///     Edits wallet access right
        /// </summary>
        /// <param name="id">ID of edited wallet access right</param>
        /// <param name="permission">New permission for wallet access right</param>
        /// <param name="userId">ID of new user for wallet access right</param>
        /// <returns></returns>
        public async Task EditWalletAccessRight(Guid id, PermissionEnum permission, Guid userId)
        {
            var walletAccessRight = await this.GetWalletAccessRightById(id);

            walletAccessRight.UserProfile = await this.GetUserProfileById(userId);
            walletAccessRight.Permission = permission;

            this.Validate(walletAccessRight);

            await this._wallets.AddOrUpdateAsync(walletAccessRight);
        }
コード例 #7
0
 public AuthoriseOrchardAttribute(PermissionEnum permissions)
 {
     _permissions = permissions;
 }