Hello,
I realize there has been a change in XafApplication initialization from 22.1.3 to 22.1.5 but it's caused my application to break. I've created a sample application which illustrates the problem.
To reproduce the error, run the solution and log in as "User" (case sensitive as it's an InMemoryDataStore).
Click on the "Attachment.png" file in the list and the file is unable to download. If you convert the project back to 22.1.3, it works as expected.
This is caused by our ActiveOrgHelper class which relies on the IValueManager system to store an active guid value. We then use this value as part of our criteria:
defaultRole.AddObjectPermission<Container>(SecurityOperations.FullObjectAccess, "[CreatedBy.Oid] = CurrentUserId() OR [Organization.Oid] = **CurrentOrgId()**", SecurityPermissionState.Allow);
Since the change, we can no longer use this criteria in any non-XAF application initialized middleware such as your IFileUrlService. This breaks the structure of our application and now I'm looking for a solution.
Any help is appreciated.
Thanks
-Dave
Hello Dave,
ValueManager has never been designed for XAF Blazor UI, Web API Service, and other non-XAF UI apps. It might have worked in Blazor UI by accident, but in fact, we have internal tests for ValueManager API only in WinForms and WebForms.
We will emphasize this at https://docs.devexpress.com/eXpressAppFramework/DevExpress.Persistent.Base.ValueManager and probably remove this help topic in future versions so that XAF users will not accidentally rely on this internal API.
ValueManager did not change in v22.1.5, but XAF's Blazor FileService did. The FileService class no longer relies on a BlazorApplication instance to upload data (BlazorApplication is in charge for initializing the ValueManager context). We intentionally made this change for performance reasons to avoid creating and configuring BlazorApplication every time one uploads a file or media data.
In your application, you can notice that the FileAttachmentTestModule.Setup method is not called when you try to upload a file. XAF v22.2 will bring yet more changes like this one. Our ultimate goal is to use more and more REST API services inside these modern apps.
As a temporary workaround (to return the old FileService behavior), you can do the following in XAF Blazor UI v22.1:
public class MyObjectSpaceFactoryWrapper : DevExpress.ExpressApp.AspNetCore.Core.Internal.IObjectSpaceFactoryWrapper { private readonly IXafApplicationProvider xafApplicationProvider; public MyObjectSpaceFactoryWrapper(IXafApplicationProvider xafApplicationProvider) { this.xafApplicationProvider = xafApplicationProvider; } public IObjectSpace CreateObjectSpace(Type objectType) { return xafApplicationProvider.GetApplication().CreateObjectSpace(objectType); } // Register this service at the end of the Startup.ConfigureServices method: services.AddScoped<DevExpress.ExpressApp.AspNetCore.Core.Internal.IObjectSpaceFactoryWrapper, MyObjectSpaceFactoryWrapper>(); }
NOTE: this workaround will not work in other usage scenarios, e.g. in Web API Service. Thus, we strongly recommend that you remove this code once we have a better solution available in v22.2.
When talking about the XAF Blazor UI, Web API Service, and other non-XAF UI apps, our general recommendation is to avoid using SecuritySystem.CurrentUser, ValueManager, ActiveOrgHelper.Instance, and other static properties in the following cases:
application.LoggedOn += (s, args) => { ActiveOrgHelper.Instance.ActiveOrganizationOid = ((ApplicationUser)application.Security.User).Organization.Oid; };
Session.GetObjectByKey<OrganizationDetails>(ActiveOrgHelper.Instance.ActiveOrganizationOid);
P.S.
In your application, you can also use the ApplicationUser class instead of PermissionPolicyUser for the CreatedBy properties and API calls (unless you intentionally want to use the base class here).