Base solution for your next web application

Activities of "sergii"

Not answer, just to understand, why you need SiteId field in mapping table UserRoles ?

Hi, Could somebody clarify why I get aways "An internal error occurred during your request!" on any kind of exceptions ?

[HttpPost]
public async Task<AjaxResponse> Save()
{
            try
            {
                throw new Exception("Any Exception");
            }
            catch (AbpValidationException ex)
            {
                string message = String.Join(Environment.NewLine, ex.ValidationErrors.Select(x => x.ErrorMessage));
                result = new AjaxResponse(false)
                {
                    Error = new ErrorInfo("Error occurred while verifying form data", message)
                };
            }
            catch (Exception ex)
            {
                result = new AjaxResponse(new ErrorInfo("An error occurred while processing form data", ex.Message));
            }

            return result ?? new AjaxResponse(true);
}
{
__abp: true,
error: {
  code: 0,
  details: null,
  message: "An internal error occurred during your request!",
  validationErrors: null
},
result: null,
success: false,
targetUrl: null ,
unAuthorizedRequest: false}

Hi, the proposed approach implies two submits to server:

  1. submit file only;
  2. dto with file id;

Is it correct ? Then how about validation or other erors on second step, we have a risk to loose related file data. Maybe someone can propose other approach with single submit and server side data validation like it works for DTO's ?

Hi, Could some one explaing what is RoleManagementConfig anf how it can be used ? Thanks.

Yes, this is it. Why customErrors setting change content type of a response? - this this unexpected behavior for UI. Developers should switch off custom errors to check appropriate response handlers... not very useful.

Good qustion, I've used userRoleRepository to do this

Hi, Could somebody help to understand why any AbpValidationException is returned as html for the conntroller method call like below ?

public class ExampleController : AbpController
{
        [HttpPost]
        [WrapResult(WrapOnSuccess = true, WrapOnError = true)]
        public JsonResult ProcessSubmitAction(MyFormViewModel vm)
        {
            var response = new AjaxResponse(true);
            try
            {
              // my logic here
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Error = new Abp.Web.Models.ErrorInfo(ex.Message);
            }

            return Json(response);
        }
}

    public class MyFormViewModel 
    {
        [Required(AllowEmptyStrings = false, ErrorMessage = ValidationMessages.EmailRequired)]
        [StringLength(Abp.Authorization.Users.AbpUserBase.MaxEmailAddressLength, ErrorMessage = ValidationMessages.EmailLengthExceeded)]
        [EmailAddress(ErrorMessage = ValidationMessages.EmailFormatInvalid)]
        [DataType(DataType.EmailAddress)]
        public string Email { get; set; }

        public string ReturnUrl { get; set; }
    }
$http.post('Example/ProcessSubmitAction', { Email: 'invalidemailvalue' })
                    .then(onSuccess, onError)
                    .finally(onFinished);

All permissions could be defined in your custom AuthorizationProvider

public class MyAuthorizationProvider : AuthorizationProvider
    {
        public override void SetPermissions(IPermissionDefinitionContext context)
        {
            SetPagePermissions(context);

            SetEntityPermissions(context);

            var permission = context.GetPermissionOrNull(PermissionNames.Impersonation.Name);
            if (permission == null)
            {
                context.CreatePermission(PermissionNames.Impersonation.Name);
            }
        }
  }

Also permissions should be assigned to users or roles, you can do it easely in EF Seeds:

private Role CreateAdminRole(int? tenantId)
        {
            var adminRole = _context.Roles.Include(e => e.Permissions).FirstOrDefault(e => e.Name == StaticRoleNames.Tenants.Admin && e.TenantId == tenantId);
            if(adminRole == null)
            {
                adminRole = _context.Roles.Add(new Role(tenantId, StaticRoleNames.Tenants.Admin, StaticRoleNames.Tenants.Admin) { IsStatic = true, IsActive = false });
                _context.SaveChanges();
            }

            // Grant all permissions to admin role
            var permissions = PermissionFinder
                .GetAllPermissions(new MyAuthorizationProvider())
                .Where(p => p.MultiTenancySides.HasFlag(tenantId.HasValue?MultiTenancySides.Tenant: MultiTenancySides.Host))
                .ToList();

            var existPermissions = adminRole.Permissions?.ToList() ?? new List<RolePermissionSetting>(0);
            if (existPermissions.Count != permissions.Count)
            {
                foreach (var permission in permissions)
                {
                    if (existPermissions.Any(e => e.Name == permission.Name && e.TenantId == tenantId)) continue;

                    AddPermissionForRole(adminRole, permission, tenantId);
                }
                // remove obsolete permissions
                foreach (var permission in existPermissions)
                {
                    if (!permissions.Any(e => e.Name == permission.Name)) {
                        _context.Permissions.Remove(permission);
                    }
                }

                _context.SaveChanges();
            }

            return adminRole;
        }
        private void AddPermissionForRole(Role role, Permission permission, int? tenantId)
        {
            _context.Permissions.Add(
                new RolePermissionSetting
                {
                    TenantId = tenantId,
                    Name = permission.Name,
                    IsGranted = true,
                    RoleId = role.Id
                });
        }

Hi, is there any way to cache response from dynamic controllers? I found configuration parameter SetNoCacheForAllResponses, but it just force "no cache" mode for all responses We are looking a way to enable and manage output cache only for a one AppService methods.

For example like it done here : CacheCow CacheOutput

Seems I found small issues with that approach and looks like it should be fixed in Abp core:

public override int SaveChanges()
        {
            try
            {
                return base.SaveChanges();
            }
            catch (DbEntityValidationException ex)
            {
                this.Logger.Warn(FriendlyMessages.FormDataValidationFailed, ex);
                var validationErrors = ex.EntityValidationErrors?.SelectMany(e => e.ValidationErrors?.Select(v => new ValidationResult(v.ErrorMessage, new string[] { v.PropertyName }))).ToList();
                throw new AbpValidationException(FriendlyMessages.FormDataValidationFailed, validationErrors);
            }
        }

Below exception rised by running seed with invalid data for entity. Ideally there should be AbpValidationException details but another SerializationException raised instead...

System.Runtime.Serialization.SerializationException: Type is not resolved for member 'Abp.Runtime.Validation.AbpValidationException,Abp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
   at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
   at System.Data.Entity.Migrations.Design.ToolingFacade.Run(BaseRunner runner)
   at System.Data.Entity.Migrations.Design.ToolingFacade.Update(String targetMigration, Boolean force)
   at System.Data.Entity.Migrations.UpdateDatabaseCommand.<>c__DisplayClass2.<.ctor>b__0()
   at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command)
Type is not resolved for member 'Abp.Runtime.Validation.AbpValidationException,Abp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
Showing 1 to 10 of 17 entries