Example #1
0
        public void Init()
        {
            using (var db = new SNAPDatabaseDataContext())
            {
                var actors = db.SNAP_Actors.Where(a => a.SNAP_Actor_Group.actorGroupType == TEAMAPPROVALGROUP).ToList();
                teamApprovalActorId = actors[0].pkId;
                teamApprovalUserId = actors[0].userId;
                //actors = db.SNAP_Actors.Where(a => a.actor_groupId == TECHNICALAPPROVALGROUP).ToList();
                actors = db.SNAP_Actors.Where(a => a.SNAP_Actor_Group.actorGroupType == TECHNICALAPPROVALGROUP).ToList();
                windowsServerActorId = actors[0].pkId;
                WindowsServerUserId = actors[0].userId;
                networkShareActorId = actors[1].pkId;
                networkShareUserId = actors[1].userId;
                databaseActorId = actors[2].pkId;
                databaseUserId = actors[2].userId;
                //actors = db.SNAP_Actors.Where(a => a.actor_groupId == MANAGERGROUP).ToList();
                actors = db.SNAP_Actors.Where(a => a.SNAP_Actor_Group.actorGroupType == MANAGERGROUP).ToList();
                if (actors.Count == 1)
                {
                    db.SNAP_Actors.InsertOnSubmit(new SNAP_Actor() {
                        actor_groupId = actors[0].actor_groupId,
                        userId = "pxlee",
                        displayName = "Pong Lee",
                        emailAddress = "*****@*****.**",
                        isActive = true,
                        isDefault = false
                    });

                    db.SubmitChanges();
                    actors = db.SNAP_Actors.Where(a => a.SNAP_Actor_Group.actorGroupType == MANAGERGROUP).ToList();
                }
                managerActorId = actors[0].pkId;
                managerUserId = actors[0].userId;
                secondManagerActorId = actors[1].pkId;
                secondMagerUserId = actors[1].userId;
            }
        }
Example #2
0
        public static void CompleteRequestApprovalCheck(int id)
        {
            using (var db = new SNAPDatabaseDataContext())
            {
                //var twf = db.SNAP_Workflows.Single(w => w.pkId == id);
                var req = db.SNAP_Requests.Single(r => r.pkId == id);
                var accessReq = new AccessRequest(id);
                var accessTeamWF = accessReq.FindApprovalTypeWF(db, (byte) ActorApprovalType.Workflow_Admin)[0];
                var mgrWF = accessReq.FindApprovalTypeWF(db, (byte) ActorApprovalType.Manager)[0];
                var teamApproverWFs = accessReq.FindApprovalTypeWF(db, (byte) ActorApprovalType.Team_Approver);
                var techApproverWFs = accessReq.FindApprovalTypeWF(db, (byte) ActorApprovalType.Technical_Approver);

                // only manager in the approal wf
                if (teamApproverWFs.Count == 0 && techApproverWFs.Count == 0)
                {
                    // make sure manager has not outstanding approval
                    if (mgrWF.SNAP_Workflow_States.OrderByDescending(s => s.pkId).First().completedDate != null)
                    {
                        AccessRequest.stateTransition(ActorApprovalType.Workflow_Admin, accessTeamWF,
                                                      WorkflowState.Workflow_Created, WorkflowState.Approved);
                        Email.SendTaskEmail(EmailTaskType.TransitionToPendingProvisioning,
                                            ConfigurationManager.AppSettings["AIM-DG"], null, req.pkId,
                                            req.userDisplayName);
                    }
                }
                else
                {
                    // we may or may not have team approver in the wf, if we do make sure all team approvers are approved
                    var done = true;

                    foreach (var wf in teamApproverWFs)
                    {
                        if (wf.SNAP_Workflow_States.Count(s => s.completedDate != null && s.workflowStatusEnum == (byte) WorkflowState.Approved) == 1)
                        {
                            done = true;
                        }
                        else
                        {
                            done = false;
                            break;
                        }
                    }

                    // now check technical approvers
                    //wfs = accessReq.FindApprovalTypeWF(db, (byte) ActorApprovalType.Technical_Approver);
                    var totalApproved = 0;
                    var state =
                        accessTeamWF.SNAP_Workflow_States.Single(
                            s => s.workflowStatusEnum == (byte) WorkflowState.Workflow_Created
                                 && s.completedDate == null);
                        // get lastest 'worflow created' for the workflowadmin state

                    foreach (var w in techApproverWFs)
                    {
                        var cnt = w.SNAP_Workflow_States.Count(
                            s => s.workflowStatusEnum == (byte) WorkflowState.Approved
                                 && s.completedDate != null
                                 && s.pkId >= state.pkId);
                        // only check approval for the latest iteration, ignore previously approved interateion

                        totalApproved += cnt;
                    }

                    if (totalApproved == techApproverWFs.Count && done)
                    {
                        AccessRequest.stateTransition(ActorApprovalType.Workflow_Admin, accessTeamWF,
                                                      WorkflowState.Workflow_Created, WorkflowState.Approved);

                        Email.SendTaskEmail(EmailTaskType.TransitionToPendingProvisioning,
                                            ConfigurationManager.AppSettings["AIM-DG"], null, req.pkId,
                                            req.userDisplayName);
                    }
                }

                db.SubmitChanges();
            }
        }
Example #3
0
 public static void UpdateRequestData(List<RequestData> newRequestList, List<usp_open_request_tabResult> requestData)
 {
     var result = UpdatedRequestDataList(newRequestList, requestData);
     if (result.Count > 0)
     {
         using (var db = new SNAPDatabaseDataContext())
         {
             var reqId = requestData[0].requestId;
             foreach(var data in result)
             {
                 var accessUserText = new SNAP_Access_User_Text()
                                          {
                                              requestId = reqId,
                                              access_details_formId = Convert.ToInt16(data.FormId),
                                              userText = data.UserText,
                                              modifiedDate = DateTime.Now
                                          };
                 db.SNAP_Access_User_Texts.InsertOnSubmit(accessUserText);
             }
             db.SubmitChanges();
         }
     }
 }
Example #4
0
        public void SetUp()
        {
            cleanUp();

            using (var db = new SNAPDatabaseDataContext())
            {

                List<RequestData> requestDataList = new List<RequestData>()
                                                        {
                                                            new RequestData() {FormId = "2", UserText = "Request Access 2"},
                                                            new RequestData() {FormId = "3", UserText = "Request Access 3"},
                                                            new RequestData() {FormId = "4", UserText = "Request Access 4"},
                                                            new RequestData() {FormId = "5", UserText = "Request Access 5"}
                                                        };

                var xmlInput = RequestData.ToXml(requestDataList);

                db.usp_insert_request_xml(xmlInput, "UnitTester", "pxlee", "Pong Lee", "Programmer", "gjbelang", "Greg Belanger");
            }
            using (var db = new SNAPDatabaseDataContext())
            {
                var req = db.SNAP_Requests.Single(x => x.submittedBy == "UnitTester");
                db.SNAP_Request_Comments.InsertOnSubmit(new SNAP_Request_Comment()
                {
                    requestId = req.pkId,
                    commentText = "Test Comment",
                    commentTypeEnum = (byte)CommentsType.Acknowledged,
                    createdDate = DateTime.Now
                });
                db.SubmitChanges();
            }
        }
Example #5
0
        public void RUD_SNAP_Workflow()
        {
            using (var db = new SNAPDatabaseDataContext())
            {
                db.SNAP_Workflows.InsertOnSubmit(new SNAP_Workflow()
                {
                    actorId = 0,
                    requestId = 0
                });
                db.SubmitChanges();

                var test1 = db.SNAP_Workflows.Where(t => t.requestId == 0 && t.actorId == 0).ToList();
                Assert.IsTrue(test1.Count > 0);

                foreach (var row in test1)
                {
                    db.SNAP_Workflows.DeleteOnSubmit(row);
                }
                db.SubmitChanges();

                var test2 = db.SNAP_Workflows.Where(t => t.requestId == 0 && t.actorId == 0).ToList();
                Assert.IsTrue(test2.Count == 0);
            }
        }
Example #6
0
        public void RUD_SNAP_Actor_Group()
        {
            using (var db = new SNAPDatabaseDataContext())
            {
                db.SNAP_Actor_Groups.InsertOnSubmit(new SNAP_Actor_Group()
                {
                    groupName = "Test Group",
                    description = "Test Group Description",
                    actorGroupType = 0,
                    isActive = false,
                    isLargeGroup = false
                });
                db.SubmitChanges();

                var test1 = db.SNAP_Actor_Groups.Where(t => t.groupName == "Test Group").ToList();
                Assert.IsTrue(test1.Count > 0);

                foreach (var row in test1)
                {
                    db.SNAP_Actor_Groups.DeleteOnSubmit(row);
                }
                db.SubmitChanges();

                var test2 = db.SNAP_Actor_Groups.Where(t => t.groupName == "Test Group").ToList();
                Assert.IsTrue(test2.Count == 0);
            }
        }
Example #7
0
        public void RUD_SNAP_Access_User_Text()
        {
            using (var db = new SNAPDatabaseDataContext())
            {
                db.SNAP_Access_User_Texts.InsertOnSubmit(new SNAP_Access_User_Text()
                {
                    requestId = 0,
                    access_details_formId = 20,
                    userText = "For unit testing",
                    modifiedDate = DateTime.Now
                });
                db.SubmitChanges();

                var test1 = db.SNAP_Access_User_Texts.Where(t => t.requestId == 0).ToList();
                Assert.IsTrue(test1.Count > 0);

                foreach (var row in test1)
                {
                    db.SNAP_Access_User_Texts.DeleteOnSubmit(row);
                }
                db.SubmitChanges();

                var test2 = db.SNAP_Access_User_Texts.Where(t => t.requestId == 0).ToList();
                Assert.IsTrue(test2.Count == 0);
            }
        }
Example #8
0
        public void RUD_Request_Comment()
        {
            using (var db = new SNAPDatabaseDataContext())
            {
                db.SNAP_Request_Comments.InsertOnSubmit(new SNAP_Request_Comment()
                {
                    requestId = 0,
                    commentText = "Test Comment",
                    commentTypeEnum = 0,
                    createdDate = DateTime.Now
                });
                db.SubmitChanges();

                var test1 = db.SNAP_Request_Comments.Where(t => t.commentText == "Test Comment").ToList();
                Assert.IsTrue(test1.Count > 0);

                foreach (var row in test1)
                {
                    db.SNAP_Request_Comments.DeleteOnSubmit(row);
                }
                db.SubmitChanges();

                var test2 = db.SNAP_Request_Comments.Where(t => t.commentText == "Test Comment").ToList();
                Assert.IsTrue(test2.Count == 0);
            }
        }
Example #9
0
        public WebMethodResponse NoAccess(WorkflowAction action, string comment)
        {
            WebMethodResponse resp = new WebMethodResponse();

            WorkflowState wfState = WorkflowState.Not_Active;
            CommentsType commentType = CommentsType.Cancelled;
            switch (action)
            {
                case WorkflowAction.Denied:
                    wfState = WorkflowState.Closed_Denied;
                    commentType = CommentsType.Denied;
                    break;
                case WorkflowAction.Cancel:
                    wfState = WorkflowState.Closed_Cancelled;
                    commentType = CommentsType.Cancelled;
                    break;
                case WorkflowAction.Abandon:
                    wfState = WorkflowState.Closed_Abandon;
                    commentType = CommentsType.Abandon;
                    break;

            }

            try
            {

                using (var db = new SNAPDatabaseDataContext())
                {
                    var req = db.SNAP_Requests.Single(r => r.pkId == _id);
                    var accessTeamWF = req.SNAP_Workflows.Single(x => x.actorId == AccessTeamActorId);
                    var currentAccessTeamWFState = (WorkflowState) accessTeamWF.SNAP_Workflow_States.Single(s => s.completedDate == null).workflowStatusEnum;
                    var result = reqStateTransition(req, RequestState.Pending, RequestState.Closed,
                                                accessTeamWF, currentAccessTeamWFState, /* WorkflowState.Pending_Workflow,*/
                                                wfState)
                            ||
                            reqStateTransition(req, RequestState.Change_Requested, RequestState.Closed,
                                                accessTeamWF, currentAccessTeamWFState, /* WorkflowState.Pending_Workflow,*/
                                                wfState);

                    if (result)
                    {
                        comment = comment.Replace("<br />", string.Empty);
                        addAccessTeamComment(accessTeamWF, comment, commentType);

                        if (req.submittedBy.ToString() != req.userId.ToString())
                        {
                            Email.SendTaskEmail(EmailTaskType.UpdateRequester, req.userId + "@apollogrp.edu", req.userDisplayName, _id, req.submittedBy, (WorkflowState)wfState, comment);
                        }
                        Email.SendTaskEmail(EmailTaskType.UpdateRequester, req.submittedBy + "@apollogrp.edu", Utilities.GetFullNameByLoginId(req.submittedBy), _id, req.submittedBy, (WorkflowState)wfState, comment);
                        db.SubmitChanges();
                        resp = new WebMethodResponse(true, "Cancel/Deny", "Success");
                    }
                    else
                    {
                        resp = new WebMethodResponse(false, "Cancel/Deny Error", SeeDetailsReqTracking);
                    }

                }
            }
            catch (Exception ex)
            {
                Logger.Fatal("AccessRequest - NoAccess, Message:" + ex.Message + ", StackTrace: " + ex.StackTrace);
                resp = new WebMethodResponse(false, "Cancel/Deny Exception", ex.Message);
            }
            return resp;
        }
Example #10
0
        public void InformApproverForAction()
        {
            bool done = false;
            using (var db = new SNAPDatabaseDataContext())
            {
                // manager approval
                var wfs = FindApprovalTypeWF(db, (byte)ActorApprovalType.Manager);
                // TODO - if request submitter is the manager, it should be auto approved and no need for this activity
                done = emailApproverForAction(wfs);

                // team approval
                if (!done)
                {
                    wfs = FindApprovalTypeWF(db, (byte)ActorApprovalType.Team_Approver);

                    done = emailApproverForAction(wfs);
                }

                // technical approvals
                if (!done)
                {
                    wfs = FindApprovalTypeWF(db, (byte)ActorApprovalType.Technical_Approver);
                    done = emailApproverForAction(wfs);

                }

                db.SubmitChanges();
            }
        }
Example #11
0
        public WebMethodResponse FinalizeRequest()
        {
            WebMethodResponse resp = new WebMethodResponse();
            try
            {
                using (var db = new SNAPDatabaseDataContext())
                {
                    var req = db.SNAP_Requests.Single(r => r.pkId == _id);
                    var accessTeamWF = req.SNAP_Workflows.Single(x => x.actorId == AccessTeamActorId);
                    var result = reqStateTransition(req, RequestState.Pending, RequestState.Closed,
                                                    accessTeamWF, WorkflowState.Pending_Provisioning,
                                                    WorkflowState.Closed_Completed)
                                 ||
                                 reqStateTransition(req, RequestState.Pending, RequestState.Closed,
                                                    accessTeamWF, WorkflowState.Approved,
                                                    WorkflowState.Closed_Completed);

                    if (result)
                    {
                        if (req.submittedBy.ToString() != req.userId.ToString())
                        {
                            Email.SendTaskEmail(EmailTaskType.UpdateRequester, req.userId + "@apollogrp.edu", req.userDisplayName, _id, req.submittedBy, WorkflowState.Closed_Completed, null);
                        }
                        Email.SendTaskEmail(EmailTaskType.UpdateRequester, req.submittedBy + "@apollogrp.edu", Utilities.GetFullNameByLoginId(req.submittedBy), _id, req.submittedBy, WorkflowState.Closed_Completed, null);
                        db.SubmitChanges();
                        resp = new WebMethodResponse(true, "Finalization", "Success");
                    }
                    else
                    {
                        resp = new WebMethodResponse(false, "Finalization Error", SeeDetailsReqTracking);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Fatal("AccessRequest - FinalizeRequest, Message:" + ex.Message + ", StackTrace: " + ex.StackTrace);
                resp = new WebMethodResponse(false, "Finalization Exception", ex.Message);
            }

            return resp;
        }
Example #12
0
        /// <summary>
        /// Call this method when you have a WF in place and in pending approval stage and u want to make mod to the approver list
        /// </summary>
        /// <param name="mgrusrId"></param>
        /// <param name="actorIDs"></param>
        /// <returns></returns>
        public WebMethodResponse EditWorkflow(string mgrusrId, List<int> actorIDs)
        {
            WebMethodResponse resp = new WebMethodResponse();

            var mgrActorId = ApprovalWorkflow.GetActorIdByUserId(ActorGroupType.Manager, mgrusrId);
            if (mgrActorId != 0)
            {
                // who is in pending state, we need to remember to inform the pending approver her new due day
                var currentPendingApproverType = GetPendingApprovalActorType();
                if (currentPendingApproverType != -1)
                {
                    actorIDs.Add(mgrActorId);
                    using (var db = new SNAPDatabaseDataContext())
                    {
                        var check = editWorkflowCheck(db, actorIDs, currentPendingApproverType);
                        if (check.Success)
                        {
                            var req = db.SNAP_Requests.Single(r => r.pkId == _id);
                            var accessTeamWF = req.SNAP_Workflows.Single(x => x.actorId == AccessTeamActorId);
                            // make sure accessTeamWF stat is pending apporal
                            if (
                                accessTeamWF.SNAP_Workflow_States.Count(
                                    s =>
                                    s.completedDate == null &&
                                    s.workflowStatusEnum == (byte) WorkflowState.Workflow_Created) == 1)
                            {
                                var newActorIds = editApprovalWorkFlow(db, actorIDs);
                                db.SubmitChanges();

                                req = db.SNAP_Requests.Single(r => r.pkId == _id);
                                foreach (var wf in req.SNAP_Workflows)
                                {
                                    if (wf.actorId != AccessTeamActorId && newActorIds.Contains(wf.actorId))
                                    {
                                        InformNewPendingApproverNewDueDate(wf, currentPendingApproverType);

                                        // update the request table
                                        if (wf.SNAP_Actor.SNAP_Actor_Group.actorGroupType == (byte)ActorApprovalType.Manager)
                                        {
                                            req.managerUserId = wf.SNAP_Actor.userId;
                                            req.managerDisplayName = wf.SNAP_Actor.displayName;
                                        }
                                    }
                                }

                                //addAccessTeamComment(accessTeamWF, "Workflow editted @" + DateTime.Now, CommentsType.Access_Notes_AccessTeam);
                                db.SubmitChanges();

                                // in case we are removing the last approver who has not approved yet, or removing special approver
                                editWorkflowCompletionCheck(_id, db);
                                resp = new WebMethodResponse(true, "Workflow Change", "Success");

                            }
                            else
                            {
                                resp = new WebMethodResponse(false, "Workflow Change Error", SeeDetailsReqTracking);
                            }
                        }
                        else
                        {
                            resp = check;
                        }
                    }
                }
            }
            return resp;
        }
Example #13
0
        /// <summary>
        /// call this method when one creates the workflow the first time or after request to change
        /// </summary>
        /// <param name="actorIds"></param>
        /// <returns></returns>
        public WebMethodResponse CreateWorkflow(List<int> actorIds)
        {
            WebMethodResponse resp = new WebMethodResponse();
            var result = false;
            try
            {
                using (var db = new SNAPDatabaseDataContext())
                {

                    SNAP_Workflow accessTeamWF;
                    DateTime? dueDate;
                    SNAP_Request req;

                    initializeData(db, WorkflowState.Pending_Workflow, out req, out accessTeamWF, out dueDate);

                    result = reqStateTransition(req, RequestState.Pending, RequestState.Pending,
                                                accessTeamWF, WorkflowState.Pending_Workflow,
                                                WorkflowState.Workflow_Created);

                    if (result)
                    {
                        result = mustHaveManagerInWorkflow(db, actorIds);
                        if (result)
                        {
                            createrApprovalWorkFlow(db, actorIds);
                            addAccessTeamComment(accessTeamWF, "Due Date: " + Convert.ToDateTime(dueDate).ToString("MMM d, yyyy"), CommentsType.Workflow_Created);
                            db.SubmitChanges();
                            resp = new WebMethodResponse(true, "Workflow Creation", "Success");
                        }
                        else
                        {
                            resp = new WebMethodResponse(false, "Workflow Creation Error", "Missing Manager. Please adjust manager. ");
                        }
                    }
                    else
                    {
                        resp = new WebMethodResponse(false, "Workflow Creation Error", SeeDetailsReqTracking);
                    }

                }
                if (result)
                    InformApproverForAction();
            }
            catch (Exception ex)
            {
                Logger.Fatal("AccessRequest - CreateWorkflow, Message:" + ex.Message + ", StackTrace: " + ex.StackTrace);
                resp = new WebMethodResponse(false, "Workflow Creation Exception", ex.Message);
            }
            return resp;
        }
Example #14
0
        private static void InsertActor(string userId, SNAPDatabaseDataContext db, ADUserDetail usrDetail, int actorGroupId)
        {
            db.SNAP_Actors.InsertOnSubmit(new SNAP_Actor()
            {
                displayName =
                    usrDetail.FirstName + " " + usrDetail.LastName,
                actor_groupId = actorGroupId,
                emailAddress = usrDetail.EmailAddress,
                isActive = true,
                isDefault = false,
                userId = userId

            });

            db.SubmitChanges();
        }
Example #15
0
 public WebMethodResponse AddComment(string comment, CommentsType type)
 {
     WebMethodResponse resp = new WebMethodResponse();
     comment = comment.Replace("<br />", string.Empty);
     try
     {
         using (var db = new SNAPDatabaseDataContext())
         {
             var req = db.SNAP_Requests.Single(r => r.pkId == _id);
             req.SNAP_Request_Comments.Add(new SNAP_Request_Comment()
                                               {
                                                   commentText = comment,
                                                   commentTypeEnum = (byte)type,
                                                   createdDate = DateTime.Now
                                                });
             db.SubmitChanges();
             resp = new WebMethodResponse(true, "Add Comment", "Success");
         }
     }
     catch (Exception ex)
     {
         Logger.Fatal("AccessRequest - AddComment, Message:" + ex.Message + ", StackTrace: " + ex.StackTrace);
         resp = new WebMethodResponse(false, "Add Comment Exception", ex.Message);
     }
     return resp;
 }
Example #16
0
        private void updateRequest(long requestId, 
            string submitterId,
            string userId,
            string userName,
            string mgrId,
            string mgrName)
        {
            var change = false;
            ADUserDetail usrDetail = null;

            using (var db = new SNAPDatabaseDataContext())
            {
                var req = db.SNAP_Requests.Single(x => x.pkId == requestId);

                if (req.submittedBy != submitterId)
                {
                    req.submittedBy = submitterId;
                    change = true;
                }

                if (req.userId != userId)
                {
                    req.userId = userId;
                    usrDetail = Apollo.AIM.SNAP.CA.DirectoryServices.GetUserByLoginName(userId);
                    req.userTitle = usrDetail.Title;
                    change = true;
                }

                if (req.userDisplayName != userName)
                {
                    req.userDisplayName = userName;
                    change = true;
                }

                if (req.managerUserId != mgrId)
                {
                    req.managerUserId = mgrId;
                    change = true;
                }

                if (req.managerDisplayName != mgrName)
                {
                    req.managerDisplayName = mgrName;
                    change = true;
                }

                if (change)
                {
                    req.lastModifiedDate = DateTime.Now;
                    db.SubmitChanges();
                }
            }
        }
Example #17
0
        public WebMethodResponse RequestChanged()
        {
            WebMethodResponse resp = new WebMethodResponse();

            try
            {
                using (var db = new SNAPDatabaseDataContext())
                {
                    var req = db.SNAP_Requests.Single(r => r.pkId == _id);
                    var accessTeamWF = req.SNAP_Workflows.Single(x => x.actorId == AccessTeamActorId);
                    var result = reqStateTransition(req, RequestState.Change_Requested, RequestState.Open,
                                                accessTeamWF, WorkflowState.Change_Requested,
                                                WorkflowState.Pending_Acknowledgement);

                    if (result)
                    {
                        db.SubmitChanges();
                        resp = new WebMethodResponse(true, "Request Changed", "Success");
                    }
                    else
                    {
                        resp = new WebMethodResponse(false, "Request Changed Error", SeeDetailsReqTracking);
                    }

                }
            }
            catch (Exception ex)
            {
                Logger.Fatal("AccessRequest - RequestChanged, Message:" + ex.Message + ", StackTrace: " + ex.StackTrace);
                resp = new WebMethodResponse(false, "Request Changed Exception", ex.Message);
            }

            return resp;
        }
Example #18
0
        public WebMethodResponse RequestToChange(string comment)
        {
            WebMethodResponse resp = new WebMethodResponse();

            try
            {
                using (var db = new SNAPDatabaseDataContext())
                {
                    var req = db.SNAP_Requests.Single(r => r.pkId == _id);
                    var accessTeamWF = req.SNAP_Workflows.Single(x => x.actorId == AccessTeamActorId);
                    var result = reqStateTransition(req, RequestState.Pending, RequestState.Change_Requested,
                                                accessTeamWF, WorkflowState.Pending_Workflow,
                                                WorkflowState.Change_Requested);

                    comment = comment.Replace("<br />", string.Empty);

                    if (result)
                    {
                        addAccessTeamComment(accessTeamWF, comment, CommentsType.Requested_Change);
                        // NOTE: don't send AIM extra email when AIM is the one making the change.
                        if (req.submittedBy.ToString() != req.userId.ToString())
                        {
                            Email.SendTaskEmail(EmailTaskType.UpdateRequester, req.userId + "@apollogrp.edu", req.userDisplayName, _id, req.submittedBy, WorkflowState.Change_Requested, comment);
                        }

                        Email.SendTaskEmail(EmailTaskType.UpdateRequester, req.submittedBy + "@apollogrp.edu", Utilities.GetFullNameByLoginId(req.submittedBy), _id, req.submittedBy, WorkflowState.Change_Requested, comment);

                        db.SubmitChanges();
                        resp = new WebMethodResponse(true, "Request Change", "Success");
                    }
                    else
                    {
                        resp = new WebMethodResponse(false, "Request Change Error", SeeDetailsReqTracking);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Fatal("AccessRequest - RequestToChange, Message:" + ex.Message + ", StackTrace: " + ex.StackTrace);
                resp = new WebMethodResponse(false, "Request Change Exception", ex.Message);
            }

            return resp;
        }
Example #19
0
        public void RUD_SNAP_Access_Details_Form()
        {
            using (var db = new SNAPDatabaseDataContext())
            {
                db.SNAP_Access_Details_Forms.InsertOnSubmit(new SNAP_Access_Details_Form()
                {
                    parentId = 20,
                    label = "Test Field",
                    description = "For Unit Testing",
                    isActive = false,
                    isRequired = false
                });
                db.SubmitChanges();

                var test1 = db.SNAP_Access_Details_Forms.Where(t => t.label == "Test Field").ToList();
                Assert.IsTrue(test1.Count > 0);

                foreach (var row in test1)
                {
                    db.SNAP_Access_Details_Forms.DeleteOnSubmit(row);
                }
                db.SubmitChanges();

                var test2 = db.SNAP_Access_Details_Forms.Where(t => t.label == "Test Field").ToList();
                Assert.IsTrue(test2.Count == 0);
            }
        }
Example #20
0
        private WebMethodResponse createCASDTicket(SNAPDatabaseDataContext db, SNAP_Workflow accessTeamWF, DateTime? dueDate, SNAP_Request req)
        {
            var changeRequest = new ServiceDesk.ChangeRequest(Apollo.ServiceDesk.SDConfig.Instance.Login, Apollo.ServiceDesk.SDConfig.Instance.Password);
            string updatedDescription = string.Format("Supplemental Access Process Request Id: {0}\r\nAffected End User Id: {1}\r\nRequested By: {2}\r\n-------------------------------------------------------\r\n{3}"
                , req.pkId, req.userId, req.submittedBy, requestDescription);

            if (requestDescription.Length > 5000)
            {
                return new WebMethodResponse(false, "Ticket Creation Error", "Request Content Too Long. Please split the request");
            }

            changeRequest.CategoryName = "Server.Systems.Privileged Access";
            changeRequest.Submitter.Get("svc_Cap");
            changeRequest.AffectedUser.Get(Regex.Replace(req.userId, @"^a\.", "")); // remove a. acct
            changeRequest.Attributes["description"] = updatedDescription;
            changeRequest.Create();

            req.ticketNumber = changeRequest.Number;
            var handler = changeRequest.Handle.Split(':')[1]; // chg:12345
            var sdlink = ConfigurationManager.AppSettings["SDLink"] + handler;

            addAccessTeamComment(
                accessTeamWF
                , string.Format("Due Date: {0} | Service Desk Ticket: <a target=\"_blank\" href=\"{2}\">{1}</a>"
                    , Convert.ToDateTime(dueDate).ToString("MMM d, yyyy")
                    , req.ticketNumber
                    , sdlink)
                , CommentsType.Ticket_Created);

            db.SubmitChanges();
            return new WebMethodResponse(true, "Ticket Creation", "Success");
        }
Example #21
0
        public void RUD_SNAP_Actor()
        {
            using (var db = new SNAPDatabaseDataContext())
            {
                db.SNAP_Actors.InsertOnSubmit(new SNAP_Actor()
                {
                    userId = "testuser",
                    displayName = "Test User",
                    emailAddress = "*****@*****.**",
                    isActive = false,
                    isDefault = false,
                    isGroup = false,
                    actor_groupId = 0
                });
                db.SubmitChanges();

                var test1 = db.SNAP_Actors.Where(t => t.userId == "testuser").ToList();
                Assert.IsTrue(test1.Count > 0);

                foreach (var row in test1)
                {
                    db.SNAP_Actors.DeleteOnSubmit(row);
                }
                db.SubmitChanges();

                var test2 = db.SNAP_Actors.Where(t => t.userId == "testuser").ToList();
                Assert.IsTrue(test2.Count == 0);
            }
        }
Example #22
0
        private WebMethodResponse createHPSMTicket(SNAPDatabaseDataContext db, SNAP_Workflow accessTeamWF, DateTime? dueDate, SNAP_Request req)
        {
            string updatedDescription = string.Format("Supplemental Access Process Request Id: {0}\r\nAffected End User Id: {1}\r\nRequested By: {2}\r\n-------------------------------------------------------\r\n{3}"
                , req.pkId, req.userId, req.submittedBy, requestDescription);

            Quote q = new Quote();
            q.Category = "apollo request";
            q.Subcategory = "Employee Management Support Service";
            q.Priority = "4 - R3 Regular";
            q.RequestedEndDate = dueDate ?? DateTime.Now.AddDays(1);
            q.CurrentPhase = "Working";
            q.ServiceContact = Regex.Replace(req.userId, @"^a\.", "");
            q.PrimaryContact = Regex.Replace(req.submittedBy, @"^a\.", "");
            q.Description = new List<string>() {updatedDescription};
            q.PartNumber = "ag1144"; //Server Privileged Access - Add, modify, or remove
            q.ItemCount = "1";
            q.ItemQuantity = "1";
            q.SaveTicket(); // uncomment this line to do end-end test

            req.ticketNumber = q.RequestID;

            var hpsmlink = ConfigurationManager.AppSettings["HPSMLink"];

            addAccessTeamComment(
                accessTeamWF
                , string.Format("Due Date: {0} | Service Desk Ticket: <a target=\"_blank\" href=\"{2}\">{1}</a>"
                    , Convert.ToDateTime(dueDate).ToString("MMM d, yyyy")
                    , req.ticketNumber
                    , hpsmlink)
                , CommentsType.Ticket_Created);

            db.SubmitChanges();
            return new WebMethodResponse(true, "Ticket Creation", "Success"); ;
        }
Example #23
0
        public void RUD_SNAP_Request()
        {
            using (var db = new SNAPDatabaseDataContext())
            {
                db.SNAP_Requests.InsertOnSubmit(new SNAP_Request()
                {
                    userId = "testuser",
                    userTitle = "Unit Tester",
                    userDisplayName = "Test Account",
                    managerUserId = "manager",
                    managerDisplayName = "Test Manager",
                    submittedBy = "submitter",
                    isChanged = false,
                    statusEnum = 0,
                    createdDate = DateTime.Now,
                    lastModifiedDate = DateTime.Now,
                    ticketNumber = "0000"
                });
                db.SubmitChanges();

                var test1 = db.SNAP_Requests.Where(t => t.userId == "testuser").ToList();
                Assert.IsTrue(test1.Count > 0);

                foreach (var row in test1)
                {
                    db.SNAP_Requests.DeleteOnSubmit(row);
                }
                db.SubmitChanges();

                var test2 = db.SNAP_Requests.Where(t => t.userId == "testuser").ToList();
                Assert.IsTrue(test2.Count == 0);
            }
        }
Example #24
0
        private void emailApproverForOverdueTask()
        {
            try
            {
                using (var db = new SNAPDatabaseDataContext())
                {
                    var unfinishedtasks = db.SNAP_Workflow_States.Where(s => s.completedDate == null
                                                                             && s.dueDate != null
                                                                             && s.notifyDate != null
                                                                             && s.SNAP_Workflow.SNAP_Request.statusEnum != (byte)RequestState.Closed);
                    foreach (var state in unfinishedtasks)
                    {
                        try
                        {
                            var task = ReminderTask.CreateReminderTask(state);
                            if (task.RemindUser())
                                db.SubmitChanges();

                        }
                        catch (Exception ex)
                        {
                            Utilities.OutputMessage("State id: " + state.pkId + ",WF id: " + state.workflowId + ", Stack Trace : " + ex.StackTrace, EventLogEntryType.Error);
                        }

                    }
                }
            }
            catch(Exception ex)
            {
                Utilities.OutputMessage(ex.Message + ", Stack Trace : " + ex.StackTrace, EventLogEntryType.Error);
            }
        }
Example #25
0
        public void RUD_SNAP_Workflow_State_Type()
        {
            using (var db = new SNAPDatabaseDataContext())
            {
                db.SNAP_Workflow_State_Types.InsertOnSubmit(new SNAP_Workflow_State_Type()
                {
                    pkId = 20,
                    typeName = "TESTTYPE"
                });
                db.SubmitChanges();

                var test1 = db.SNAP_Workflow_State_Types.Where(t=>t.pkId==20).ToList();
                Assert.IsTrue(test1.Count > 0);

                foreach (var row in test1)
                {
                    db.SNAP_Workflow_State_Types.DeleteOnSubmit(row);
                }
                db.SubmitChanges();

                var test2 = db.SNAP_Workflow_State_Types.Where(t => t.pkId == 20).ToList();
                Assert.IsTrue(test2.Count == 0);
            }
        }
Example #26
0
        public void ShouldReturnActorId()
        {
            string usrid = "pxlee";

            //Console.WriteLine("Should return actor id: " + usrid);
            //g.actorGroupType == (byte)ActorGroupType.Manager
            try
            {
                using (var db = new SNAPDatabaseDataContext())
                {
                    var c =
                        db.SNAP_Actors.Count(
                            a => a.userId == usrid && a.SNAP_Actor_Group.actorGroupType == (byte) ActorGroupType.Manager);
                    if (c == 0)
                    {
                        db.SNAP_Actors.InsertOnSubmit(new SNAP_Actor()
                                                          {
                                                              actor_groupId = 4,
                                                              userId = "pxlee",
                                                              displayName = "Pong Lee",
                                                              emailAddress = "*****@*****.**",
                                                              isActive = true,
                                                              isDefault = false
                                                          });
                        db.SubmitChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error("AccessRequest_Test - ShouldReturnActorId, Message:" + ex.Message + ", StackTrace: " + ex.StackTrace);
            }
            removeManagerActorByUserId(usrid);
            Assert.IsTrue(ApprovalWorkflow.GetActorIdByUserId(ActorGroupType.Manager, usrid) != 0);
        }
Example #27
0
        private void cleanUp()
        {
            using (var db = new SNAPDatabaseDataContext())
            {

                var reqs = db.SNAP_Requests.Where(x => x.submittedBy == "UnitTester").ToList();

                foreach (var r in reqs)
                {
                    var wfs = db.SNAP_Workflows.Where(x => x.requestId == r.pkId).ToList();
                    foreach (SNAP_Workflow wf in wfs)
                    {
                        var states = db.SNAP_Workflow_States.Where(x => x.workflowId == wf.pkId);
                        db.SNAP_Workflow_States.DeleteAllOnSubmit(states);

                        var comments = db.SNAP_Workflow_Comments.Where(c => c.workflowId == wf.pkId);
                        db.SNAP_Workflow_Comments.DeleteAllOnSubmit(comments);
                    }

                    db.SNAP_Workflows.DeleteAllOnSubmit(wfs);

                    var uts = db.SNAP_Access_User_Texts.Where(x => x.requestId == r.pkId);
                    db.SNAP_Access_User_Texts.DeleteAllOnSubmit(uts);
                    db.SNAP_Requests.DeleteOnSubmit(r);

                    var reqComments = db.SNAP_Request_Comments.Where(c => c.requestId == r.pkId);
                    db.SNAP_Request_Comments.DeleteAllOnSubmit(reqComments);
                }

                db.SubmitChanges();
            }
        }
Example #28
0
        private void removeManagerActorByUserId(string mgrUid)
        {
            using (var db = new SNAPDatabaseDataContext())
            {
                try
                {
                    var groupId =
                        db.SNAP_Actor_Groups.Single(g => g.actorGroupType == (byte)ActorGroupType.Manager).pkId;
                    var toRemoveActor = db.SNAP_Actors.Single(a => a.userId == mgrUid && a.actor_groupId == groupId);

                    db.SNAP_Actors.DeleteOnSubmit(toRemoveActor);

                    db.SubmitChanges();
                }
                catch (Exception ex)
                {
                    Logger.Error("AccessRequest_Test - removeManagerActorByUserId, Message:" + ex.Message + ", StackTrace: " + ex.StackTrace);
                }
            }
        }
Example #29
0
        static void Main(string[] args)
        {
            Console.WriteLine("Set due date for request to fire the email nag ...");
            Console.WriteLine("What is your intervals(in days):");
            var interval = Convert.ToInt16(Console.ReadLine());
            Console.WriteLine("What is your max over due (in days) to close abandoned  the request:");
            var maxOverDue = Convert.ToInt16(Console.ReadLine());

            Console.WriteLine("Due on 1 - Tomorrow, 2 - Now (for dev mostly)");
            var dueDateOption = Convert.ToInt16(Console.ReadLine());

            var answer = "Y";
            while (answer.Contains("Y")) {

                Console.WriteLine("Enter your request id which has approver waiting to approve the request");
                var requestId = Console.ReadLine();
                using (var db = new SNAPDatabaseDataContext())
                {
                    var req = db.SNAP_Requests.Single(x => (x.pkId == Convert.ToInt32(requestId) && x.statusEnum != (byte)RequestState.Closed) );
                    Console.WriteLine("req id: " + req.pkId + " - " + req.userDisplayName);
                    foreach(var wf in req.SNAP_Workflows)
                    {
                        var latestState = wf.SNAP_Workflow_States.OrderByDescending(s => s.pkId).First();
                        if (canChangeDueDate(latestState))
                        {
                            Console.WriteLine(wf.SNAP_Actor.displayName + "... " + Enum.GetName(typeof(WorkflowState), latestState.workflowStatusEnum));
                            var newDueDate = askUserToSelectDueDate(interval, dueDateOption, maxOverDue);

                            latestState.dueDate = newDueDate;
                            db.SubmitChanges();
                        }
                    }
                }

                Console.WriteLine("Press 'y' to continue .... any key to quit ...");
                answer = Console.ReadLine().ToUpper();
            }
            Console.WriteLine("Have a good day! Press enter ....");
            Console.ReadKey();
        }
Example #30
0
        public WebMethodResponse Ack()
        {
            WebMethodResponse resp = new WebMethodResponse() ;
            try
            {
                using (var db = new SNAPDatabaseDataContext())
                {

                    SNAP_Workflow accessTeamWF;
                    DateTime? dueDate;
                    SNAP_Request req;

                    initializeData(db, WorkflowState.Pending_Acknowledgement, out req, out accessTeamWF, out dueDate);

                    var result = reqStateTransition(req, RequestState.Open, RequestState.Pending,
                                                accessTeamWF, WorkflowState.Pending_Acknowledgement,
                                                WorkflowState.Pending_Workflow);

                    if (result)
                    {
                        addAccessTeamComment(accessTeamWF, "Due Date: " + Convert.ToDateTime(dueDate).ToString("MMM d, yyyy"), CommentsType.Acknowledged);
                        db.SubmitChanges();
                        resp = new WebMethodResponse(true, "Acknowledgement", "Success");
                    }
                    else
                    {
                        resp = new WebMethodResponse(false, "Acknowledgement Error", SeeDetailsReqTracking);
                    }

                }
            }
            catch (Exception ex)
            {
                Logger.Fatal("AccessRequest - Ack, Message:" + ex.Message + ", StackTrace: " + ex.StackTrace);
                resp = new WebMethodResponse(false, "Acknowledgement Exception", ex.Message);
            }

            return resp;
        }