private static string FormatMessage(string userName, EnumSystemPermission permission) { return string.Format("User {0} does not have permission {1}", userName, permission); }
public SystemPermissionDeniedException(string userName, EnumSystemPermission permission) : base(FormatMessage(userName, permission)) { this.UserName = userName; this.Permission = permission; }
public bool HasSystemPermission(string userName, EnumSystemPermission permission) { var permissionData = this.GetUserEffectivePermissions(this._userIdentity.UserName); if(permissionData == null || permissionData.SystemPermissions == null) { return false; } EnumPermissionAccess access; switch(permission) { case EnumSystemPermission.EditSystemPermissions: access = permissionData.SystemPermissions.EditSystemPermissionsAccess; break; case EnumSystemPermission.EditUsers: access = permissionData.SystemPermissions.EditUsersAccess; break; case EnumSystemPermission.EditDeploymentCredentials: access = permissionData.SystemPermissions.EditDeploymentCredentialsAccess; break; case EnumSystemPermission.EditBuildPurgeRules: access = permissionData.SystemPermissions.EditBuildPurgeRulesAccess; break; default: throw new UnknownEnumValueException(permission); } return (access == EnumPermissionAccess.Grant); }
public void VerifySystemPermission(string userName, EnumSystemPermission permission) { if(!this.HasSystemPermission(userName, permission)) { throw new SystemPermissionDeniedException(userName, permission); } }
public bool CurrentUserHasSystemPermission(EnumSystemPermission permission) { return this.HasSystemPermission(_userIdentity.UserName, permission); }
public void VerifyCurrentUserSystemPermission(EnumSystemPermission permission) { this.VerifySystemPermission(_userIdentity.UserName, permission); }