mardi 3 décembre 2019

How to specify user restrictions in domain driven design?

How to specify user restrictions in domain driven.

I am using asp.net application web api and application service to use from web api.

[ApiController]
public class TicketController : ControllerBase
{
    ....
    ....
    [HttpPost]
    [Route("change-date")]
    public async Task<IActionResult> ChangeTicketDate(TicketChangeCommand command)
    {
        var response = await _ticketService.ChangeTicketDate(command, User.Identity.Name);

        return Ok(response);
    }
    ....
    ....

}

To prevent the tickets, I am sending the authenticated username to _ticketService. Because a user may change another user ticket. So I have two rules for ticket date change logic.

1- User should be owner of ticket. 2- Or User sholud be in Administrator role.

(These rules also will be using other services. For example User can only change his own password.)

public class TicketService : ITicketService
{
    ....

    public TicketChange ChangeTicketDate(TicketChangeCommand command, string requestedUsername){
            // 1. Check requested user is ticket creator or Administrator               
    }

    ....
}

To check the user role and owner, should I create a domain service? Should I create a domain authorization service to check roles?

Aucun commentaire:

Enregistrer un commentaire