/// <inheritdoc />
        /// <summary>
        /// Check if user is an (possibly indirect) member of an identity group
        /// </summary>
        /// <param name="body">Method XML body item</param>
        /// <returns>'true' as string result if membership matches</returns>
        public override Item DoApply(Item body)
        {
            XmlPropertyAttribute.BindXml(body.node, this);

            var userId = Innovator.getUserID();

            var userAlias = Innovator.newItem("Alias", "get");

            userAlias.setAttribute("select", "related_id");
            userAlias.setProperty("source_id", userId);
            userAlias = Innovator.ApplyItem(userAlias);

            var identityId = userAlias.getProperty("related_id");

            return(Innovator.newResult(CheckIfMemberOfIdentity(identityId) ? "true" : "false"));
        }
Ejemplo n.º 2
0
        /// <inheritdoc />
        /// <summary>
        /// Check if user is an (possibly indirect) member of an identity group
        /// </summary>
        /// <param name="body">Method XML body item</param>
        /// <returns>'true' as string result if membership matches</returns>
        public override Item DoApply(Item body)
        {
            XmlPropertyAttribute.BindXml(body.node, this);

            var userId = Innovator.getUserID();

            var userAlias = Innovator.newItem("Alias", "get");

            userAlias.setAttribute("select", "related_id");
            userAlias.setProperty("source_id", userId);
            userAlias = Innovator.ApplyItem(userAlias);

            var ids = new List <string> {
                userAlias.getProperty("related_id")
            };

            // not the fastest, but it works.
            // should be optimized by asking for batches of identities.
            // (see below for fast recursive SQL .. that Aras doesn't permit in ApplySQL.)
            while (ids.Any())
            {
                var id = ids.Last();
                ids.RemoveAt(ids.Count - 1);

                var identityItem = Innovator.newItem("Identity", "get");
                identityItem.setAttribute("select", "keyed_name");

                var memberRelation = identityItem.createRelationship("Member", "get");
                memberRelation.setAttribute("select", "keyed_name");
                memberRelation.setProperty("related_id", id);
                identityItem = Innovator.ApplyItem(identityItem);

                if (identityItem.Enumerate()
                    .Any(i => i.getProperty("keyed_name") == IdentityName))
                {
                    return(Innovator.newResult("true"));
                }

                ids.AddRange(identityItem.Enumerate().Select(i => i.getID()));
            }

            return(Innovator.newResult("false"));
        }
        /// <summary>
        /// Check if an identity ID is a member of the identity with name `IdentityName`.
        ///
        /// Also takes into account the from and end dates for an identity membership.
        /// </summary>
        /// <param name="identityId">The identity ID to check if it is a member of identity with name `IdentityName`.</param>
        private bool CheckIfMemberOfIdentity(string identityId)
        {
            var identityIds = new List <Tuple <string, DateTime, DateTime> >
            {
                new Tuple <string, DateTime, DateTime>(identityId, DateTime.MinValue, DateTime.MaxValue)
            };

            while (identityIds.Any())
            {
                var identityIdTuple = identityIds.Last();
                identityIds.RemoveAt(identityIds.Count - 1);
                identityId = identityIdTuple.Item1;
                var fromDate = identityIdTuple.Item2;
                var endDate  = identityIdTuple.Item3;

                var identityItems = Innovator.newItem("Identity", "get");
                identityItems.setAttribute("select", "keyed_name");

                var memberRelation = identityItems.createRelationship("Member", "get");
                memberRelation.setAttribute("select", "id, from_date, end_date");
                memberRelation.setProperty("related_id", identityId);
                identityItems = Innovator.ApplyItem(identityItems);

                foreach (var identityItem in identityItems.Enumerate())
                {
                    var memberItem  = identityItem.getRelationships().getItemByIndex(0);
                    var newFromDate = MaxDateTime(fromDate, memberItem.getProperty("from_date")?.ToDateTime());
                    var newEndDate  = MinDateTime(endDate, memberItem.getProperty("end_date")?.ToDateTime());

                    if (identityItem.getProperty("keyed_name") == IdentityName && DateTime.Now >= newFromDate &&
                        DateTime.Now <= newEndDate)
                    {
                        return(true);
                    }

                    identityIds.Add(
                        new Tuple <string, DateTime, DateTime>(identityItem.getID(), newFromDate, newEndDate));
                }
            }

            return(false);
        }
Ejemplo n.º 4
0
        public void Cleanup()
        {
            if (!TempItems.Any())
            {
                return;
            }

            Exception ex = null;

            Console.WriteLine($"Cleaning up {TempItems.Count} temp item(s) from Aras DB...\n");

            foreach (var item in TempItems)
            {
                try
                {
                    // create new item to reduce log spam
                    var delItem = Innovator.newItem(item.getType(), "delete");
                    delItem.setID(item.getID());
                    delItem.setProperty("keyed_name", item.getProperty("keyed_name"));
                    if (item.getProperty("affected_id", "") != "")
                    {
                        delItem.setProperty("affected_id", item.getProperty("affected_id"));
                        delItem.setPropertyAttribute("affected_id", "keyed_name",
                                                     item.getPropertyAttribute("affected_id", "keyed_name"));
                    }
                    Innovator.ApplyItem(delItem, false);
                }
                catch (Exception e)
                {
                    Console.Error.WriteLine(e.Message);
                    ex = e; // lazy, but one exception is better than none on multiple failures
                }
            }

            TempItems.Clear();

            if (ex != null)
            {
                throw ex;
            }
        }