示例#1
0
        /// <summary>
        /// Converts to a simpler instance object that includes some application metadata
        /// </summary>
        public static MessageBoxInstance ConvertToMessageBoxInstance(Instance instance)
        {
            InstanceStatus status       = instance.Status ?? new InstanceStatus();
            DateTime?      visibleAfter = instance.VisibleAfter;

            string instanceGuid = instance.Id.Contains("/") ? instance.Id.Split("/")[1] : instance.Id;

            DateTime createdDateTime = visibleAfter != null && visibleAfter > instance.Created ? (DateTime)visibleAfter : instance.Created.Value;

            MessageBoxInstance messageBoxInstance = new MessageBoxInstance
            {
                CreatedDateTime = createdDateTime,
                DueDateTime     = instance.DueBefore,
                Id = instanceGuid,
                InstanceOwnerId    = instance.InstanceOwner.PartyId,
                LastChangedBy      = FindLastChangedBy(instance),
                Org                = instance.Org,
                AppName            = instance.AppId.Split('/')[1],
                ProcessCurrentTask = GetSBLStatusForCurrentTask(instance),
                AllowNewCopy       = false,
                DeletedDateTime    = status.SoftDeleted,
                ArchivedDateTime   = status.Archived,
                DeleteStatus       = status.SoftDeleted.HasValue ? DeleteStatusType.SoftDeleted : DeleteStatusType.Default,
                ReadStatus         = status.ReadStatus
            };

            return(messageBoxInstance);
        }
示例#2
0
        /// <summary>
        /// Converts to a simpler instance object that includes some application metadata
        /// </summary>
        public static MessageBoxInstance ConvertToMessageBoxInstance(Instance instance)
        {
            InstanceStatus status       = instance.Status ?? new InstanceStatus();
            DateTime?      visibleAfter = instance.VisibleAfter;

            string instanceGuid = instance.Id.Contains('/') ? instance.Id.Split('/')[1] : instance.Id;

            DateTime createdDateTime = visibleAfter != null && visibleAfter > instance.Created ? (DateTime)visibleAfter : instance.Created.Value;

            MessageBoxInstance messageBoxInstance = new MessageBoxInstance
            {
                CreatedDateTime = createdDateTime,
                DueDateTime     = instance.DueBefore,
                Id = instanceGuid,
                InstanceOwnerId    = instance.InstanceOwner.PartyId,
                LastChangedBy      = FindLastChanged(instance).LastChangedBy,
                Org                = instance.Org,
                AppName            = instance.AppId.Split('/')[1],
                ProcessCurrentTask = GetSBLStatusForCurrentTask(instance),
                AllowNewCopy       = false,
                DeletedDateTime    = status.SoftDeleted,
                ArchivedDateTime   = status.Archived,
                DeleteStatus       = status.SoftDeleted.HasValue ? DeleteStatusType.SoftDeleted : DeleteStatusType.Default,
                ReadStatus         = status.ReadStatus,
                DataValues         = instance.DataValues
            };

            if (instance.PresentationTexts is not null)
            {
                messageBoxInstance.PresentationText = string.Join(", ", instance.PresentationTexts.Select(pt => pt.Value).ToArray());
            }

            if (instance.Status?.Substatus != null)
            {
                messageBoxInstance.Substatus = new Substatus
                {
                    Label       = instance.Status.Substatus.Label,
                    Description = instance.Status.Substatus.Description
                };
            }

            return(messageBoxInstance);
        }
示例#3
0
        /// <summary>
        /// Converts to a simpler instance object that includes some application metadata
        /// </summary>
        public static MessageBoxInstance ConvertToMessageBoxInstance(Instance instance)
        {
            InstanceStatus status       = instance.Status ?? new InstanceStatus();
            DateTime?      visibleAfter = instance.VisibleAfter;

            string instanceGuid = instance.Id.Contains("/") ? instance.Id.Split("/")[1] : instance.Id;

            DateTime createdDateTime = visibleAfter != null && visibleAfter > instance.Created ? (DateTime)visibleAfter : instance.Created.Value;

            string lastChangedBy = FindLastChangedBy(instance);

            // last changed by is set to null if instance has only been modified by an organisation
            // to ensure correct rendering in messagebox.
            if (instance.Created.Value == instance.LastChanged.Value && IsValidOrganizationNumber(lastChangedBy))
            {
                lastChangedBy = "0";
            }

            MessageBoxInstance messageBoxInstance = new MessageBoxInstance
            {
                CreatedDateTime = createdDateTime,
                DueDateTime     = instance.DueBefore,
                Id = instanceGuid,
                InstanceOwnerId    = instance.InstanceOwner.PartyId,
                LastChangedBy      = lastChangedBy,
                Org                = instance.Org,
                AppName            = instance.AppId.Split('/')[1],
                ProcessCurrentTask = GetSBLStatusForCurrentTask(instance),
                AllowNewCopy       = false,
                DeletedDateTime    = status.SoftDeleted,
                ArchivedDateTime   = status.Archived,
                DeleteStatus       = status.SoftDeleted.HasValue ? DeleteStatusType.SoftDeleted : DeleteStatusType.Default,
            };

            return(messageBoxInstance);
        }
示例#4
0
 /// <summary>
 /// Returns app id
 /// </summary>
 public static string GetAppId(MessageBoxInstance instance)
 {
     return(instance.Org.ToLower() + "/" + instance.AppName);
 }
        /// <summary>
        /// Authorize instances, and returns a list of MesseageBoxInstances with information about read and write rights of each instance.
        /// </summary>
        public async Task <List <MessageBoxInstance> > AuthorizeMesseageBoxInstances(ClaimsPrincipal user, List <Instance> instances)
        {
            if (instances.Count <= 0)
            {
                return(new List <MessageBoxInstance>());
            }

            List <MessageBoxInstance> authorizedInstanceeList = new List <MessageBoxInstance>();
            List <string>             actionTypes             = new List <string> {
                "read", "write"
            };

            _logger.LogInformation($"// AuthorizationHelper // AuthorizeMsgBoxInstances // User: {user}");
            _logger.LogInformation($"// AuthorizationHelper // AuthorizeMsgBoxInstances // Instances count: {instances.Count()}");
            _logger.LogInformation($"// AuthorizationHelper // AuthorizeMsgBoxInstances // Action types: {actionTypes}");
            XacmlJsonRequestRoot xacmlJsonRequest = CreateMultiDecisionRequest(user, instances, actionTypes);

            _logger.LogInformation($"// AuthorizationHelper // AuthorizeMsgBoxInstances // xacmlJsonRequest: {JsonConvert.SerializeObject(xacmlJsonRequest)}");
            XacmlJsonResponse response = await _pdp.GetDecisionForRequest(xacmlJsonRequest);

            foreach (XacmlJsonResult result in response.Response)
            {
                if (DecisionHelper.ValidateDecisionResult(result, user))
                {
                    string instanceId = string.Empty;
                    string actiontype = string.Empty;

                    // Loop through all attributes in Category from the response
                    foreach (XacmlJsonCategory category in result.Category)
                    {
                        var attributes = category.Attribute;

                        foreach (var attribute in attributes)
                        {
                            if (attribute.AttributeId.Equals(XacmlResourceActionId))
                            {
                                actiontype = attribute.Value;
                            }

                            if (attribute.AttributeId.Equals(AltinnXacmlUrns.InstanceId))
                            {
                                instanceId = attribute.Value;
                            }
                        }
                    }

                    // Find the instance that has been validated to add it to the list of authorized instances.
                    Instance authorizedInstance = instances.FirstOrDefault(i => i.Id == instanceId);

                    // Checks if the instance has already been authorized
                    if (authorizedInstanceeList.Any(i => i.Id.Equals(authorizedInstance.Id.Split("/")[1])))
                    {
                        // Only need to check if the action type is write, because read do not add any special rights to the MessageBoxInstane.
                        if (actiontype.Equals("write"))
                        {
                            authorizedInstanceeList.Where(i => i.Id.Equals(authorizedInstance.Id.Split("/")[1])).ToList().ForEach(i => i.AuthorizedForWrite = i.AllowDelete = true);
                        }
                    }
                    else
                    {
                        MessageBoxInstance messageBoxInstance = InstanceHelper.ConvertToMessageBoxInstance(authorizedInstance);

                        if (actiontype.Equals("write"))
                        {
                            messageBoxInstance.AuthorizedForWrite = true;
                            messageBoxInstance.AllowDelete        = true;
                        }

                        authorizedInstanceeList.Add(messageBoxInstance);
                    }
                }
            }

            return(authorizedInstanceeList);
        }