Ejemplo n.º 1
0
        public async Task <IActionResult> ValidateInstantiation(string org, string app, [FromQuery] int partyId)
        {
            UserContext userContext = await _userHelper.GetUserContext(HttpContext);

            UserProfile user = await _profile.GetUserProfile(userContext.UserId);

            List <Party> partyList = await _authorization.GetPartyList(userContext.UserId);

            Application application = _appResourcesService.GetApplication();

            if (application == null)
            {
                return(NotFound("Application not found"));
            }

            PartyTypesAllowed partyTypesAllowed   = application.PartyTypesAllowed;
            Party             partyUserRepresents = null;

            // Check if the user can represent the supplied partyId
            if (partyId != user.PartyId)
            {
                Party represents = InstantiationHelper.GetPartyByPartyId(partyList, partyId);
                if (represents == null)
                {
                    // the user does not represent the chosen party id, is not allowed to initiate
                    return(Ok(new InstantiationValidationResult
                    {
                        Valid = false,
                        Message = "The user does not represent the supplied party",
                        ValidParties = InstantiationHelper.FilterPartiesByAllowedPartyTypes(partyList, partyTypesAllowed)
                    }));
                }

                partyUserRepresents = represents;
            }

            if (partyUserRepresents == null)
            {
                // if not set, the user represents itself
                partyUserRepresents = user.Party;
            }

            // Check if the application can be initiated with the party chosen
            bool canInstantiate = InstantiationHelper.IsPartyAllowedToInstantiate(partyUserRepresents, partyTypesAllowed);

            if (!canInstantiate)
            {
                return(Ok(new InstantiationValidationResult
                {
                    Valid = false,
                    Message = "The supplied party is not allowed to instantiate the application",
                    ValidParties = InstantiationHelper.FilterPartiesByAllowedPartyTypes(partyList, partyTypesAllowed)
                }));
            }

            return(Ok(new InstantiationValidationResult
            {
                Valid = true,
            }));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Get(string org, string app, bool allowedToInstantiateFilter = false)
        {
            UserContext  userContext = _userHelper.GetUserContext(HttpContext).Result;
            List <Party> partyList   = _authorization.GetPartyList(userContext.UserId);

            if (allowedToInstantiateFilter)
            {
                Application  application  = _appResourcesService.GetApplication();
                List <Party> validParties = InstantiationHelper.FilterPartiesByAllowedPartyTypes(partyList, application.PartyTypesAllowed);
                return(Ok(validParties));
            }

            return(Ok(partyList));
        }