API Platform - Custom subresource path doesn't work - api-platform.com

API Platform version(s) affected: 2.5.6
Description
Following this documentation: https://api-platform.com/docs/core/subresources/#using-custom-paths
I try to override the path (and security, and requirements) of a subresource.
It works for the security, but not for path (and so requirements).
How to reproduce
Clone this repo and follow the very small README :
https://github.com/bastoune/api-platform-issue-1581
Having this route with debug:router :
api_organizations_users_get_subresource GET ANY ANY /v2/organizations/{id}/users.{_format}
and this annotation :
* subresourceOperations={
* "api_organizations_users_get_subresource"={
* "method"="GET",
* "path"="/TEEEST/organizations/{organization_id}/users",
* "requirements"={"organization_id": StringHelper::UUIDv4Regex},
* "security"="is_granted('readOrganization', organization_id)"
* }
* }
The security works but not the rest.
If I remove the security, it doesn't work anyway.

As mentioned here : https://github.com/api-platform/api-platform/issues/1581#issuecomment-662503549
There is a bug with the operation name:
Try with "users_get_subresource" as operation name (instead of
"api_organizations_users_get_subresource").
api-platform/docs#1109
This PR was merge api-platform/docs#370 but this commit revert the changes api-platform/docs#b8304bc

Related

ASP.NET Core 6 MVC : adding identity failing

I'm using VS 2022, ASP.NET Core 6 MVC and Microsoft SQL Server 2019 (v15).
Git project: [https://github.com/Wizmi24/MVC_BookStore]
I'm trying to add --> new scaffolded item --> identity.
Default layout page, override all files and mine Data context
when I click add, I get this error:
There was an error running the selected code generator:
'Package restore failed. Rolling back package changes for 'MyProjectName'
I cleared NuGet Package cache as I saw it may help, but all it do is just prolong and this same error is visible after trying to install Microsoft.EntityFrameworkCore.SqlServer, which is installed. I checked the packages and made sure they are the same version (6.0.11).
I cloned your project to test, and the problem you mentioned did appear. Not sure why, but I finally got it working by updating the NuGet package:
I updated the two packages Microsoft.EntityFrameworkCore and Microsoft.EntityFrameworkCore.Relational to version 7.0.1 (you need to pay attention to the sequence when updating), then add scaffolded Identity, and I succeeded.
You can try my method, if the Identity is successfully added, but the following exception is encountered at runtime:
You need to add builder.Services.AddDbContext<MyBookContext>(); before
builder.Services.AddDefaultIdentity<IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true)
.AddEntityFrameworkStores<MyBookContext>();
MyBookContext is the Data context class selected when you add Identity:
In addition, if there is a 404 error in your area routing, you can refer to this document to modify it.
Hope this can help you.
Edit1:
I think it might be a problem caused by naming duplication. Please try to change the name of the context generated by Identity.
As you can see, the ApplicationDbContext generated by Identity is consistent with the ApplicationDbContext namespace in your MyBook.DataAccess:
So naming the same will cause conflict:
So you need to change the naming to avoid conflicts. For example:
builder.Services.AddDbContext<ApplicationDbContext>(options => options.UseSqlServer(
builder.Configuration.GetConnectionString("DefaultConnection")
));
builder.Services.AddDbContext<ApplicationDbContextIdentity>();
builder.Services.AddDefaultIdentity<IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true)
.AddEntityFrameworkStores<ApplicationDbContextIdentity>();
Edit2:
As I mentioned in the original answer, if you get a 404 error, you can try to refer to this link to fix the area routing.
The easiest way is to directly change the routing settings in Program.cs:
app.MapAreaControllerRoute(
name: "Customer",
areaName: "Customer",
pattern: "{area:exists}/{controller=Home}/{action=Index}/{id?}");
Then add the Area property to the controller:
[Area("Customer")]
public class HomeController : Controller{}
There seems to be a problem with your Repository.cs, so I changed the Index to only output a string to test the result.
public string Index()
{
return "success";
}
Test Result:
If your Repository.cs also has problems when you test it, you can make a new post for everyone to help you fix this problem(Because this question strays so far from your original question, one post is better off addressing only one question).
Good Luck.

Elsa workflow versioning

I have created a simple workflow, first time publish it is working fine when I change something and publish then it is throwing an exception: "The call is ambiguous and matches multiple workflows". How to handle this?
I was experiencing the same issue. There appears to be an issue in Elsa where the "IsLatest" flag on the WorkflowDefinition table doesn't get turned off for the prior version of that workflow. There is some documentation around the issue here:
https://gitmemory.com/issue/elsa-workflows/elsa-core/1293/886656398
In my case, I fixed this by manually setting the prior version's IsLatest to 0 and restarting Elsa. The restart was important, as there appears to be some caching related to the workflow newness.
TL;DR : there are multiple workflows with the same path
Check if you are building a workflow through ELSA DESIGNER and at the same time there is a workflow that is triggered when HTTP requests are made to the same URL
public class HelloWorld : IWorkflow
{
public void Build(IWorkflowBuilder builder)
{
builder
.HttpEndpoint("/hello") // this is the endpoint that is causing conflict
.When(OutcomeNames.Done)
.WriteHttpResponse(HttpStatusCode.OK, "<h1>Hello World!</h1>", "text/html");
}
}

Why does hyperledger composer acl file not take effect?

EDIT: rest-server gives the option "Specify if you want the generated REST API to be secured: (y/N)", is this to enforce the acl?
I've been trying to setup a simple test using hyperledger-composer node js client. In my config I have the following:
"connection-info" : {
"participantId" : "gk1",
"participantPwd" :"CjysyeLjriRT",
"businessNetworkIdentifier" : "myBizNetwork",
"connectionProfile" : "defaultProfile"}
In my business network definition I have the following:
rule Default {
description: "DENY all participants access to all resources"
participant: "ANY"
operation: ALL
resource: "net.name.myBizNetwork"
action: DENY }
When I call the following code in node js app, I can still see the resources:
this.bizNetworkConnection.getAssetRegistry('net.name.myBizNetwork.TestAsset');
}).then((registry) => {
return registry.find('testAssetId = ' + id);
Obviously I'd like to do more scenarios with access control, but in my understanding this should work.
A good first point of call is to try out your model, acl, and script files in the online playground here https://composer-playground.mybluemix.net/
Note - you are an admin by default, to simulate being a participant you can do so by:
Clicking 'admin' in the top right of the playground
'+ Issue New ID'
Supply a User ID (whatever you like) and participant (will be one you created earlier) and then press 'Create New'
Select Option 2: '+ Add to my Wallet' (This will allow you to then use the identity and you will 'be' that participant
From looking at your code, the resource you deny is "net.name.myBizNetwork".
Following the documentation here https://hyperledger.github.io/composer/reference/acl_language.html I think that to deny access to the resources within your network you will need to add a '*' wildcard (see the Examples section in the link). If that doesn't work it may have something to do with identities.
Another note, from my understanding, you need to secure the API if you want to use identities. However, you also need to create/bind identities to existing participants, and then use those identities to 'be' that participant. See the article here https://hyperledger.github.io/composer/managing/identity-issue.html
By default, you are a Null participant (you can see what participant you currently 'are' by pinging the network)

unable to connect to back4app using parse4cn1 lib

Good day all, I tried connecting to the back4app back end service using the new parse4cn1 lib .....I supplied the keys required but my app could not connect to the backend for some strange reasons.kept reporting (unable to connect to back end.........codename one revisions some long numbers)
Some help or direction will be appreciated.Thanks all
What keys are you using? You need to pass your App Id and Client Key to parse4cn1. I just ran the regression tests against back4app and I didn't get any connection error. Can you provide more details (e.g. a dump) of the error you're getting?
Where are you putting your Parse.initialize? Just went for some digging on parse4cn1 and it seems that it needs to be inside a "initVars" function, usually created within a state machine as you can see in the example below:
public class StateMachine extends StateMachineBase {
/**
* this method should be used to initialize variables instead of
* the constructor/class scope to avoid race conditions
*/
protected void initVars(Resources res) {
Parse.initialize(API_ENDPOINT, APP_ID, CLIENT_KEY);
}
}
Maybe that can help you on this connection issue. Also check the link below (A very useful guide) for further info:
https://github.com/sidiabale/parse4cn1/wiki/Usage-Examples

How To Detect User Profile Change (Event) in Joomla Programmatically?

We are in the process of building a user synchronization plugin for Joomla 2.5 (gets Joomla users and sends them to another platform via a JSON API call). This all works fine, however once copied, the updates on the profiles in Joomla don't get reflected to the external platform.
I see that there are some events such as onUserAfterSave and onUserBeforeSave, but as far as I understand, these are only available for plugins and not for components (we are building a component with frontend and backend).
So my question is, how do we detect programmatically that the user has changed his profile somehow (name, email or password) and execute something in our component accordingly.
You need to create a user profile plugin. You can pack the plugin together with your component in a package when distributing it. It is quite common in Joomla to have extensions contain 1-2 components, a module and a plugin. This is how Joomla separates specific jobs in specific extensions.
Good examples on how to do it are already inside here:
/plugins/user/
Here is your method signature:
/**
* #param array $user Holds the new user data.
* #param boolean $isnew True if a new user is stored.
* #param boolean $success True if user was succesfully stored in the database.
* #param string $msg Message.
*/
public function onUserAfterSave($user, $isnew, $success, $msg)
{}
Basically inside the method you can do whatever you want, in your case probably updating some tables from your component.

Resources