Пример #1
0
        public void InitWorkflow(string className)
        {
            //Get the workflow object by class name
            if (Workflow.LoadByObjectName(className))
            {
                //Get all unique owners for this workflow
                WFOwnerGroups.Load(Workflow.ID);

                //Add an owner group to the work flow owners
                foreach (ENTWFOwnerGroupEO entWFOwnerGroup in WFOwnerGroups)
                {
                    Nullable <int> entUserAccountId = null;

                    if (entWFOwnerGroup.IsDefaultSameAsLast)
                    {
                        //Get this user's last request and set it as the default.
                        var lastUser = new ENTWFItemOwnerData().SelectLastUserByGroupId(entWFOwnerGroup.ID, WFItem.SubmitterENTUserAccountId);
                        if ((lastUser != null) && (lastUser.ENTUserAccountId != null))
                        {
                            entUserAccountId = lastUser.ENTUserAccountId;
                        }
                    }
                    else
                    {
                        //set the owner to the default one selected for this group.
                        entUserAccountId = entWFOwnerGroup.DefaultENTUserAccountId;
                    }

                    string userName = "";
                    if (entUserAccountId != null)
                    {
                        //get the user's name
                        var userAccount = new ENTUserAccountEO();
                        userAccount.Load((int)entUserAccountId);
                        userName = userAccount.DisplayText;
                    }

                    //Add this item owner with the default user.
                    WFOwners.Add(new ENTWFItemOwnerEO {
                        ENTUserAccountId = entUserAccountId, ENTWFOwnerGroupId = entWFOwnerGroup.ID, UserName = userName
                    });
                }

                //Load the transitions based on the current state.
                WFTransitions.Load(WFItem.CurrentWFStateId);
            }
            else
            {
                throw new Exception("Workflow not set correctly.  Please associate this item with a workflow.");
            }
        }
Пример #2
0
        public bool HasAccessToMenu(ENTUserAccountEO userAccount, ENTRoleEOList roles)
        {
            if (IsAlwaysEnabled)
            {
                return(true);
            }
            //Loop through all the roles this user is in.  The first time the user has
            //access to the menu item then return true.  If you get through all the
            //roles then the user does not have access to this menu item.
            foreach (var role in roles)
            {
                //Check if this user is in this role
                if (role.RoleUserAccounts.IsUserInRole(userAccount.ID))
                {
                    //Try to find the capability with the menu item Id.
                    IEnumerable <ENTRoleCapabilityEO> capabilities = role.RoleCapabilities.GetByMenuItemId(ID);

                    if (capabilities.Any(capability => (capability != null) &&
                                         (capability.AccessFlag != ENTRoleCapabilityEO.CapabiiltyAccessFlagEnum.None)))
                    {
                        return(true);
                    }
                }
            }

            //If it gets here then the user didn't have access to this menu item.  BUT they may have access
            //to one of its children, now check the children and if they have access to any of  them  then
            //return true.
            if (ChildMenuItems.Count > 0)
            {
                return(ChildMenuItems.Any(child => child.HasAccessToMenu(userAccount, roles)));
            }

            //If it never found a role with any capability then return false.
            return(false);
        }
Пример #3
0
        public bool SaveWorkflow(HRPaidTimeOffDataContext db, ref ENTValidationErrors validationErrors,
                                 ENTBaseEO item, int userAccountId)
        {
            WFItem.ItemId = item.ID;

            ValidateWorkflow(db, ref validationErrors, item);

            if (validationErrors.Count == 0)
            {
                //Set the ID for all the child owner objects
                foreach (ENTWFItemOwnerEO entWFItemOwner in WFOwners)
                {
                    entWFItemOwner.ENTWFItemId = item.ID;
                }

                foreach (ENTWFItemStateHistoryEO entWFItemStateHistory in WFStateHistory)
                {
                    entWFItemStateHistory.ENTWFItemId = item.ID;
                }

                if (WFItem.Save(db, ref validationErrors, userAccountId))
                {
                    foreach (ENTWFItemOwnerEO wfItemOwner in WFOwners)
                    {
                        wfItemOwner.ENTWFItemId = WFItem.ID;

                        if (wfItemOwner.Save(db, ref validationErrors, userAccountId) == false)
                        {
                            return(false);
                        }
                    }

                    foreach (ENTWFItemStateHistoryEO wfItemStateHistory in WFStateHistory)
                    {
                        if (wfItemStateHistory.IsNewRecord())
                        {
                            //A state history is only added if an item changes state or a different person becomes the owner.
                            //Send notification if user became owner, Chapter 8.
                            //Check if the new owner is registered to recieve a notification when they become the owner of an item.
                            ENTNotificationEO myNotification = new ENTNotificationEO();
                            if (myNotification.Load(db, ENTNotificationEO.NotificationType.IBecameOwnerOfIssue, wfItemStateHistory.ENTUserAccountId))
                            {
                                //Get the new owner's email address
                                ENTUserAccountEO newOwner = new ENTUserAccountEO();
                                newOwner.Load(db, wfItemStateHistory.ENTUserAccountId);

                                ENTEmailEO email = new ENTEmailEO
                                {
                                    FromEmailAddress = myNotification.FromEmailAddress,
                                    Subject          = ReplaceTokens(myNotification.Subject, item),
                                    Body             = ReplaceTokens(myNotification.Body, item),
                                    EmailStatusFlag  = ENTEmailEO.EmailStatusFlagEnum.NotSent,
                                    ToEmailAddress   = newOwner.Email
                                };

                                email.Save(db, ref validationErrors, userAccountId);
                            }
                        }

                        wfItemStateHistory.ENTWFItemId = WFItem.ID;

                        if (wfItemStateHistory.Save(db, ref validationErrors, userAccountId) == false)
                        {
                            return(false);
                        }
                    }

                    //Call any methods the transition requires
                    if (ENTWFTransitionId != 0)
                    {
                        ENTWFTransitionEO entWFTransition = WFTransitions.Get(ENTWFTransitionId);

                        if (entWFTransition.PostTransitionMethodName != null)
                        {
                            //Create an instance of the object
                            Type objectType = Type.GetType(Workflow.ENTWorkflowObjectName);
                            //object listObject = Activator.CreateInstance(objectType);

                            //Call the method to load the object
                            objectType.InvokeMember(entWFTransition.PostTransitionMethodName, BindingFlags.InvokeMethod, null, item, new object[] { db });
                        }

                        //Send notifications if user requests to be notified when their issue changes state, Chapter 8.
                        ENTNotificationEO issueChangedStateNotification = new ENTNotificationEO();
                        if (issueChangedStateNotification.Load(db, ENTNotificationEO.NotificationType.MyRequestChangedState, WFItem.SubmitterENTUserAccountId))
                        {
                            //Get the submitters email address.
                            ENTUserAccountEO submitter = new ENTUserAccountEO();
                            submitter.Load(db, WFItem.SubmitterENTUserAccountId);

                            ENTEmailEO email = new ENTEmailEO
                            {
                                FromEmailAddress = issueChangedStateNotification.FromEmailAddress,
                                Subject          = ReplaceTokens(issueChangedStateNotification.Subject, item),
                                Body             = ReplaceTokens(issueChangedStateNotification.Body, item),
                                EmailStatusFlag  = ENTEmailEO.EmailStatusFlagEnum.NotSent,
                                ToEmailAddress   = submitter.Email
                            };

                            email.Save(db, ref validationErrors, userAccountId);
                        }

                        //Check if anyone registered for this notification for the current state.
                        ENTNotificationENTUserAccountEOList goesToStateNotification = new ENTNotificationENTUserAccountEOList();
                        goesToStateNotification.Load(db, WFItem.CurrentWFStateId, ENTNotificationEO.NotificationType.IssueIOwnedGoesToState);

                        if (goesToStateNotification.Count > 0)
                        {
                            //Get the notification details to send the email.
                            ENTNotificationEO notification = new ENTNotificationEO();
                            notification.Load(db, (int)ENTNotificationEO.NotificationType.IssueIOwnedGoesToState);

                            //Send notifications if user requests to be notified if they owned an issue an it reaches a specific state.
                            foreach (ENTWFItemOwnerEO owner in WFOwners)
                            {
                                ENTNotificationENTUserAccountEO notifyForState = goesToStateNotification.GetByENTUserAccountId((int)owner.ENTUserAccountId);
                                if (notifyForState != null)
                                {
                                    //Get the owner's email address.
                                    ENTUserAccountEO ownerUserAccount = new ENTUserAccountEO();
                                    ownerUserAccount.Load(db, (int)owner.ENTUserAccountId);

                                    ENTEmailEO email = new ENTEmailEO
                                    {
                                        FromEmailAddress = notification.FromEmailAddress,
                                        Subject          = ReplaceTokens(notification.Subject, item),
                                        Body             = ReplaceTokens(notification.Body, item),
                                        EmailStatusFlag  = ENTEmailEO.EmailStatusFlagEnum.NotSent,
                                        ToEmailAddress   = ownerUserAccount.Email
                                    };

                                    email.Save(db, ref validationErrors, userAccountId);
                                }
                            }
                        }
                    }

                    return(true);
                }
                else
                {
                    //Failed item save.
                    return(false);
                }
            }
            else
            {
                //Failed Validation
                return(false);
            }
        }