Bless you! That was the issue! I need a combination of a default TenantId and strategically placed calls to _unitOfWorkManager.Current.SaveChangesAsync();
to make it work, but the key was that I was creating org units with a null TenantId. Thank you so much! What a great way to kick 2019 off!
Happy New Year! -Gabe
I'm unit testing some functioinality that involves creating organization units. I have no idea if what I've written works because the unit test continues to fail. I've narrowed it down to a situation in which new organization units aren't being added to the DbContext via IRepository<OrganizationUnit>.Insert() or IRepository<OrganizationUnit>.InsertAndGetIdAsync().
As you can see in the image above, according to the organizationUnitRepository which is injected into the constructor of the class this method is in, the collection of OrganizationUnits is unmodified. There are 14 units initialized directly in the DbContext during the test set up and code-first seed process. A new ID is returned, but the collection remains unmodified.
Tryng to assign the new ID as the parent to a new OrganizationUnit fails with the exception "There is no such entity. Entity type: Abp.Organizations.OrganizationUnit, id: 15". The same ID from the first image that was returned after IRespository<OrganizationUnit>.InsertAndGetIdAsync() was called.
I've spent about 13 hours trying to figure this out and I'm not making any progress. I'm desperate for help at this point.
I changed the file to an embedded resource and that solved the problem. Since that was a file that was generated as part of my default project, it never occured to me that I would have to modify it's build properties. Anyway, thanks for the help, glad that's working now :)
We are using Asp.net Zero v 5.1 and localization isn't working properly. I'm getting the following output from ASP.NET Core Web Server, despite the fact that <text> elements are present for all over them in Evsuite.Admin.Core\Localization\Admin\Admin.xml :
Evsuite.Admin.Web.Mvc> [14:11:31 WRN] Can not find 'Tenants' in localization source 'Admin'! Evsuite.Admin.Web.Mvc> [14:11:31 WRN] Can not find 'Editions' in localization source 'Admin'! Evsuite.Admin.Web.Mvc> [14:11:31 WRN] Can not find 'Dashboard' in localization source 'Admin'! Evsuite.Admin.Web.Mvc> [14:11:31 WRN] Can not find 'Administration' in localization source 'Admin'! Evsuite.Admin.Web.Mvc> [14:11:31 WRN] Can not find 'OrganizationUnits' in localization source 'Admin'! Evsuite.Admin.Web.Mvc> [14:11:31 WRN] Can not find 'Roles' in localization source 'Admin'! Evsuite.Admin.Web.Mvc> [14:11:31 WRN] Can not find 'Users' in localization source 'Admin'! Evsuite.Admin.Web.Mvc> [14:11:31 WRN] Can not find 'Languages' in localization source 'Admin'! Evsuite.Admin.Web.Mvc> [14:11:31 WRN] Can not find 'AuditLogs' in localization source 'Admin'! Evsuite.Admin.Web.Mvc> [14:11:31 WRN] Can not find 'Maintenance' in localization source 'Admin'! Evsuite.Admin.Web.Mvc> [14:11:31 WRN] Can not find 'Subscription' in localization source 'Admin'! Evsuite.Admin.Web.Mvc> [14:11:31 WRN] Can not find 'VisualSettings' in localization source 'Admin'! Evsuite.Admin.Web.Mvc> [14:11:31 WRN] Can not find 'Settings' in localization source 'Admin'! Evsuite.Admin.Web.Mvc> [14:11:31 WRN] Can not find 'DemoUiComponents' in localization source 'Admin'!
What do I need to do for the text values for the localization keys to render correctly?
That did it! Thank you!
The problem I encountered is based on some quirks of using smtp.Office365.com. After reading a bit about sending emails with Office365 and MailKit, I solved my problem by replacing DefaultMailKitSmtpBuilderwith a custom one that's exactly the same with the addition of two lines:
client.ServerCertificateValidationCallback = (s, c, h, e) => true; and client.AuthenticationMechanisms.Remove("XOAUTH2");
Here's my complete Office365SmtpBuilder implementation:
public class Office365SmtpBuilder : IMailKitSmtpBuilder
{
private readonly ISmtpEmailSenderConfiguration _smtpEmailSenderConfiguration;
public Office365SmtpBuilder(ISmtpEmailSenderConfiguration smtpEmailSenderConfiguration)
{
_smtpEmailSenderConfiguration = smtpEmailSenderConfiguration;
}
public virtual SmtpClient Build()
{
var client = new SmtpClient();
try
{
ConfigureClient(client);
return client;
}
catch
{
client.Dispose();
throw;
}
}
protected virtual void ConfigureClient(SmtpClient client)
{
client.ServerCertificateValidationCallback = (s, c, h, e) => true; //added this line
client.Connect(
_smtpEmailSenderConfiguration.Host,
_smtpEmailSenderConfiguration.Port,
_smtpEmailSenderConfiguration.EnableSsl
);
client.AuthenticationMechanisms.Remove("XOAUTH2"); //added this line
var userName = _smtpEmailSenderConfiguration.UserName;
if (!userName.IsNullOrEmpty())
{
client.Authenticate(
_smtpEmailSenderConfiguration.UserName,
_smtpEmailSenderConfiguration.Password
);
}
}
}
I replaced the DefaultMailKitSmtpBuilder service by updating my AdminCoreModule in the PreInitialize() method:
if (DebugHelper.IsDebug)
{
//Disabling email sending in debug mode
Configuration.ReplaceService<IMailKitSmtpBuilder, Office365SmtpBuilder>(DependencyLifeStyle.Transient);
}
Hi, I'm using the jQuery version. When I navigate away it does not show the correct image. Here are the steps I took:
Settings > Appearance > Upload_Logo_info isn't working correctly. I upload an image and it changes the logo on the banner. If navigate away, the image reverts to the ASP.NET Zero logo. If I click Save All and navigate away, the image reverts. Any suggestions?
So I was finally able to make this work with a hack. I'll share what I did in case anyone else runs into trouble.
When accessing protected routes, AuthorizationHelper.AuthorizeAsync() is called:
public async Task AuthorizeAsync(IEnumerable<IAbpAuthorizeAttribute> authorizeAttributes)
{
if (!_authConfiguration.IsEnabled)
{
return;
}
if (!AbpSession.UserId.HasValue) //this was ALWAYS NULL for me
{
throw new AbpAuthorizationException(
LocalizationManager.GetString(AbpConsts.LocalizationSourceName, "CurrentUserDidNotLoginToTheApplication")
);
}
foreach (var authorizeAttribute in authorizeAttributes)
{
await PermissionChecker.AuthorizeAsync(authorizeAttribute.RequireAllPermissions, authorizeAttribute.Permissions);
}
}
Digging deeper, I found that userIdClaim in ClaimsAbpSession was ALWAYS NULL as well:
public class ClaimsAbpSession : AbpSessionBase, ISingletonDependency
{
public override long? UserId
{
get
{
if (OverridedValue != null)
{
return OverridedValue.UserId;
}
//userIdClaim is always null because AbpClaimTypes.UserId == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier";
var userIdClaim = PrincipalAccessor.Principal?.Claims.FirstOrDefault(c => c.Type == AbpClaimTypes.UserId);
if (string.IsNullOrEmpty(userIdClaim?.Value))
{
return null;
}
long userId;
if (!long.TryParse(userIdClaim.Value, out userId))
{
return null;
}
return userId;
}
}
The accessToken returned by IdentityServer4 as a "sub" claim with the UserId value in it, so I simply added
AbpClaimTypes.UserId = "sub";
to Evsuite.Admin.Web.Host.AuthConfigurer.Configure();
Now ClaimsAbpSession.UserId is set to the correct AbpUsers.Id.