public Edit_Incident_Handler(IUser user)
 {
     APF = Australian_Parachute_Federation.Instance;
     //user = APF.Searcher.Find_User("13E98653-675F-44E6-A0A2-E2E40261F8FE");
     //role = APF.Searcher.Find_Role("70CAAFBC-B595-4D98-85CF-FCDC913FDB9D");
     _userInRole = (IUserInRole)APF.Searcher.Find_User_In_Role(user.User_ID);
 }
 public ModifyIncidentHandler()
 {
     APF = Australian_Parachute_Federation.Instance;
     _reporter = APF.Searcher.Find_User("13E98653-675F-44E6-A0A2-E2E40261F8FE");
     _role = APF.Searcher.Find_Role("70CAAFBC-B595-4D98-85CF-FCDC913FDB9D");
     _userInRole = (IUserInRole)APF.Searcher.Find_User_In_Role(_reporter.User_ID, _role.Role_ID);
 }
예제 #3
0
        /// <summary>
        /// 获取指定用户Id的审批角色列表
        /// </summary>
        /// <param name="workflowName">工作流名称</param>
        /// <param name="userId">用户Id</param>
        /// <returns>用户所在的审批角色</returns>
        public static List <ApprovalRole> GetUserRoles(string workflowName, string userId)
        {
            List <ApprovalRole> rolesList = new List <ApprovalRole>();

            //如果用户id为空,那么返回空角色集合
            if (string.IsNullOrEmpty(userId))
            {
                return(rolesList);
            }

            IUserInRole          userInRole = WorkflowRuntime.Current.GetService <IIdentityService>().GetUserInRole();
            StateMachineWorkflow workflow   = (StateMachineWorkflow)WorkflowRuntime.Current.GetService <IWorkFlowDefinePersistService>().GetWorkflowDefine(workflowName);

            foreach (ApprovalRole approvalRole in workflow.Roles)
            {
                if (userInRole.IsUserInRole(userId, approvalRole.Name))
                {
                    if (!rolesList.Contains(approvalRole))
                    {
                        rolesList.Add(approvalRole);
                    }
                }
            }
            return(rolesList);
        }
        /// <summary>
        /// 判断某用户是否具有对指定实例进行指定动作的执行权限
        /// </summary>
        /// <param name="instance">工作流实例</param>
        /// <param name="actionName">执行动作</param>
        /// <returns></returns>
        public virtual bool CanDoAction(WorkflowInstance instance, string actionName)
        {
            if (instance == null)
            {
                throw new ArgumentNullException("instance");
            }
            if (string.IsNullOrEmpty(actionName))
            {
                throw new ArgumentNullException("actionName");
            }
            IUserInRole   userInRole   = WorkflowRuntime.Current.GetService <IIdentityService>().GetUserInRole();
            IUserIdentity userIdentity = WorkflowRuntime.Current.GetService <IIdentityService>().GetUserIdentity();

            if (GetActionRole(instance, userIdentity.GetUserId(), actionName) != null)
            {
                return(true);
            }
            ApprovalEvent        approvalEvent   = ((StateMachineWorkflowInstance)instance).CurrentState.GetEventByName(actionName);
            IApprovalSaveService approvalService = WorkflowRuntime.Current.GetService <IApprovalSaveService>();
            List <ApprovalAgent> agentList       = approvalService.GetValidAgentInfoByToUser(userIdentity.GetUserId());

            if (agentList != null && agentList.Count > 0)
            {
                foreach (ApprovalAgent agentInfo in agentList)
                {
                    foreach (EventRole role in approvalEvent.Roles)
                    {
                        if (IsAuthorized(agentInfo.SetUserId, approvalEvent, instance))
                        {
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
        /// <summary>
        /// Determines whether the specified user id is authorized.
        /// </summary>
        /// <param name="userId">The user id.</param>
        /// <param name="approvalEvent">The approval event.</param>
        /// <param name="isOwner">if set to <c>true</c> [is owner].</param>
        /// <param name="role">The role.</param>
        /// <returns>
        ///     <c>true</c> if the specified user id is authorized; otherwise, <c>false</c>.
        /// </returns>
        public virtual bool IsAuthorized(string userId, ApprovalEvent approvalEvent, bool isOwner, EventRole role)
        {
            IUserInRole userInRole = WorkflowRuntime.Current.GetService <IIdentityService>().GetUserInRole();

            return(userInRole.IsUserInRole(userId, role.Name) && ((isOwner && approvalEvent.Authorization == Authorization.OwnerOnly.ToString()) || (!isOwner && approvalEvent.Authorization == Authorization.DenyOwner.ToString()) || approvalEvent.Authorization == Authorization.All.ToString()));
        }