how to define permission for custom model - liferay-6

How to define permission for custom model like Employee.
I am having one portlet where I can perform CURD operation on Employee object(custom model).
Using this link :
Permission for custom model
In above post they are using ext-plugin. Is it possible any other way?

Related

Relationships in Entity Framework with users from AzureAD

I'm relatively new to Microsoft solutions and I need your guidance. I'm quite certain the answer exist somewhere, but I lack key words for my searches.
My stack is as follows: .NET Core 6, Entity Framework, Azure AD.
Ideally, I wouldn't need to store user's information in my DB. Everything should come from Azure AD. Authentication is already working, and I'm able to retrieve my current user in my controllers and services.
My goal is to add some relationships between my Azure AD users and some of my entities.
For example, let's say I'm doing a collaborative Todo list and I want my users to be able to cancel tasks. So I have an entity named Task, and in it, a column named CanceledBy.
On cancellation, in my TaskService, I want to do something like that:
var task = dbContext.tasks.find(taskId);
task.CancelledBy = User;
"User" is the current user. In a perfect world, it works like that, out of the box. Behind the magic, the user OID would be stored, and the user would be automatically resolved through GraphAPI (or something else?) when needed.
I'm guessing there may be a type that could help me in my entity Task? Like:
public class Task
{
...
AzureADUser CancelledBy {get;set;}
}
And some configuration to add to my Startup.cs.
Or am I completely wrong? Am I doomed to implement myself a service to retrieve my users through GraphAPI with their OID?
In that case my Task would look more like
public class Task
{
...
string? CancelledByOID {get;set;}
[NotMapped]
User? CancelledBy {get;set;}
}
And I'd have to map my users manually in my services every time I need them?
I'm simply looking for direction here. What are key words I could use to help my search? I tried stuff like "Relathionship with Azure AD User in Entity Framework", or "GraphAPI and Entity Framework" without success.
Thank you!
EDIT : After more searches, I think I want to do LinQ on OData connected to Entity Framework and Graph API. I hope it makes sense.

Custom POST/PUT route/endpoint based on meta value

I'm currently making a store which is receiving it's data from external sources. Being new to the world of editing/creating REST API, I've come across a problem. The problem is that the external source have no idea what ID the product gets in woocommerce so update/delete products is not possible with the current endpoints/routes. However, the external source does have it's own ID on it's product and I've stored this in a custom meta field in woo and I can see it and update it through api on Postman.
How can i create a new endpoint/route that uses the custom meta field called externalProductId and use this to update the product instead of the woocommerce ID?
What you can do, which I particularly did in my case ... Create a field id_product_woo in your external bank, the time you create the product in Woocommerce, it returns a JSON with the information of the product created, including the ID inside Woocommerce... When you create or update a product in Woocommerce, you then pass the id stored in the id_product_woo field of your external bank.
Apparently, this for me, worked perfectly.

Linking Marketo Custom Object to Lead via SOAP

How do I link a custom object created via Marketo's SOAP API to an existing lead?
In your custom object, you can define one of the fields as a 'link'.
In the web interface , when you select 'link', it reloads the dialog and gives you the option to select the linked object type (Lead) and the field to link with (ID).
When you create an object using the SOAP API with a link field like this, you can give the custom object your lead ID to link it.

Breeze EFContextProvider per request and based on parameter?

I have a multi-tenant app in which user can select "current company" after they log in.
There is a DB per company but the model is the same, the workflow is the same, and the controller actions are same....The user can switch companies while being logged in and all actions need to be 'directed' to proper DB.
I know it is possible to customize context creation in EFContextProvider<T> by overriding CreateContext() but how do I pass the extra info (parameter, e.g. CompanyId) that would allow me to create context with correct connection string?
Is this possible?
I find the easiest way is to include the tenant id in a custom HTTP header.
Because the tenant id changes during the session, you probably want to create a custom Breeze ajax adapter (wrap the one you're using now) that sets this header dynamically during its implementation of the ajax method.
On the server you fish the header out of the request.
MAKE SURE YOU ARE VALIDATING USER AND HEADER ON THE SERVER

Web.api Get method to show only selected properties from entity

Let's say I have 3 entities: Advert, User and UserRole. And in Web.Api project GetAllAdverts method.
public IEnumerable<Advert> GetAllAdverts()
{
return repository.GetAll<Advert>();
}
When i enter url ../api/advert I get JSON with all Adverts and data about adverts, but I get all data about user and user role too.
How can I get for example all advert data and only UserName form entity User ?
Is this done by creating DTOs ?
Thanks in advance !
Using DTO's is usually a good idea. It is more work, but it gives you full control and it abstracts out peculiarities of a specific data layer.
In your case, if you really only want UserName you even have to use a DTO, because it is impossible to partly load the User as navigation property from Advert.
If it does not matter that you see all properties of User except its navigation properties (like role), you may also consider to (temporarily) turn off lazy loading for the context in the repository and eager load Advert.User by using Include.