Пример #1
0
        //CAMBIOS PERMISOS
        public static Permission GetRoleObjectPermission(int roleId, int objectId = 0, int moduleId = 0, int attributeId = 0)
        {
            if (!_tokenManager.GenerateToken("admin", "admin"))
            {
                throw new ArgumentException("Unable to Authorize the application");
            }
            if (objectId == 0 && attributeId != 0)
            {
                _ISpartan_MetadataApiConsumer.SetAuthHeader(_tokenManager.Token);
                var resultMeta = _ISpartan_MetadataApiConsumer.GetByKey(attributeId, false).Resource;
                objectId = Convert.ToInt32(resultMeta.Related_Object_Id);
            }
            if (System.Web.HttpContext.Current.Session["Permissions"] == null)
            {
                SetPermissions();
            }
            List <Permission> ret = (List <Permission>)System.Web.HttpContext.Current.Session["Permissions"];

            if (ret != null)
            {
                ret = ret.Where(x => x.Role == roleId).ToList();
                if (moduleId != 0)
                {
                    ret = ret.Where(x => x.Module == moduleId).ToList();
                }
                if (objectId != 0)
                {
                    ret = ret.Where(x => x.Object == objectId).ToList();
                }
                if (ret.Count == 0)
                {
                    ret.Add(new Permission());
                }
                return(ret.FirstOrDefault());
            }
            return(null);
        }
Пример #2
0
        private static void ProcessObject(int idLanguage, string nameObject, int idTraduction)
        {
            string language = _cultures[idLanguage - 1];

            string url = ConfigurationManager.AppSettings["BaseDirectoyPhysical"] + "Uploads\\Resources\\" + nameObject + "Resource." + language + ".xml";

            try
            {
                XDocument fullFile          = XDocument.Load(url);
                var       traductionsDetail = _spartan_Traduction_DetailApiConsumer.ListaSelAll(0, 9999, "Spartan_Traduction_Detail.Concept=5 AND Spartan_Traduction_Process.LanguageT=" + idLanguage + " AND Spartan_Traduction_Process.IdTraduction= " + idTraduction, "").Resource;
                if (traductionsDetail != null)
                {
                    int    AttributeId           = 0;
                    string traductionDescription = "";
                    foreach (var traductionDetail in traductionsDetail.Spartan_Traduction_Details)
                    {
                        AttributeId = traductionDetail.IdConcept.Value;
                        Spartan_Metadata metadata = _spartaneMetadataApiConsumer.GetByKey(AttributeId, false).Resource;
                        traductionDescription = traductionDetail.Translated_Text;
                        var nodeToChange =
                            (from p in fullFile.Descendants("resource")
                             where p.Attribute("name").Value == metadata.Physical_Name
                             select p).FirstOrDefault();
                        if (nodeToChange != null)
                        {
                            nodeToChange.Attribute("value").Value = traductionDescription;
                        }
                    }
                    fullFile.Save(url);
                }
            }
            catch (Exception ex)
            {
                string error = ex.ToString();
            }
        }
Пример #3
0
        /// <summary>
        /// Used to get the Permission for Role Object
        /// </summary>
        /// <param name="roleId"></param>
        /// <param name="objectId"></param>
        /// <returns></returns>
        public static Permission GetRoleObjectPermission(int roleId, int objectId = 0, int moduleId = 0, int attributeId = 0)
        {
            try
            {
                if (!_tokenManager.GenerateToken("admin", "admin"))
                {
                    throw new ArgumentException("Unable to Authorize the application");
                }

                if (objectId == 0 && attributeId != 0)
                {
                    _ISpartan_MetadataApiConsumer.SetAuthHeader(_tokenManager.Token);
                    var resultMeta = _ISpartan_MetadataApiConsumer.GetByKey(attributeId, false).Resource;
                    objectId = Convert.ToInt32(resultMeta.Related_Object_Id);
                    moduleId = 0;
                }


                _spartaneUserRoleObjectFunctionApiConsumer.SetAuthHeader(_tokenManager.Token);
                _spartaneFunctionApiConsumer.SetAuthHeader(_tokenManager.Token);
                string where = "spartan_user_rule_object_function.Object_Id=" + objectId +
                               " AND spartan_user_rule_object_function.Spartan_User_Rule=" + roleId;
                if (moduleId != 0)
                {
                    where += " AND spartan_user_rule_object_function.Module_Id=" + moduleId;
                }
                var userRoleObjectFunctions = _spartaneUserRoleObjectFunctionApiConsumer.ListaSelAll(1, int.MaxValue, where, "").Resource;

                if (userRoleObjectFunctions == null ||
                    userRoleObjectFunctions.Spartan_User_Rule_Object_Functions == null)
                {
                    return(new Permission());
                }

                var spartaneFuctions = new List <SpartaneFunction>();

                foreach (var userRoleObjectFunction in userRoleObjectFunctions.Spartan_User_Rule_Object_Functions)
                {
                    spartaneFuctions.Add(_spartaneFunctionApiConsumer.GetByKey(userRoleObjectFunction.Fuction_Id, true).Resource);
                }

                Permission ObjectPermissions = GetSpartanePermission(spartaneFuctions);
                //WorkFlows Permissions
                #region WorkFlows Permissions
                if (System.Web.HttpContext.Current.Session != null)
                {
                    if (System.Web.HttpContext.Current.Session["Phase"] != null)
                    {
                        if (System.Web.HttpContext.Current.Session["Phase"].ToString() != "")
                        {
                            //Consult if the object has workflow assigned
                            _Spartan_WorkFlowApiConsumer.SetAuthHeader(_tokenManager.Token);
                            var workflowObject = _Spartan_WorkFlowApiConsumer.ListaSelAll(1, int.MaxValue, "spartan_workflow.object = " + objectId.ToString() + " and spartan_workflow.status=1", "").Resource;
                            if (workflowObject != null)
                            {
                                if (workflowObject.Spartan_WorkFlows.Count != 0)
                                {
                                    //Consultar id de Fase
                                    _Spartan_WorkFlow_PhasesApiConsumer.SetAuthHeader(_tokenManager.Token);
                                    var phaseObject = _Spartan_WorkFlow_PhasesApiConsumer.ListaSelAll(1, int.MaxValue, "Spartan_WorkFlow_Phases.WorkFlow=" + workflowObject.Spartan_WorkFlows[0].WorkFlowId.ToString() + " and Spartan_WorkFlow_Phases.Phase_Number=" + System.Web.HttpContext.Current.Session["Phase"].ToString() + " and Spartan_WorkFlow_Phases.phase_status=1", "").Resource;
                                    if (phaseObject != null)
                                    {
                                        if (phaseObject.Spartan_WorkFlow_Phasess.Count != 0)
                                        {
                                            //Consultar Permisos
                                            _Spartan_WorkFlow_Roles_by_StateApiConsumer.SetAuthHeader(_tokenManager.Token);
                                            var rolesObject = _Spartan_WorkFlow_Roles_by_StateApiConsumer.ListaSelAll(1, int.MaxValue, "Spartan_WorkFlow_Roles_by_State.Spartan_WorkFlow=" + workflowObject.Spartan_WorkFlows[0].WorkFlowId.ToString() + " and Spartan_WorkFlow_Roles_by_State.Phase=" + phaseObject.Spartan_WorkFlow_Phasess[0].PhasesId.ToString() + " and Spartan_WorkFlow_Roles_by_State.User_Role=" + roleId.ToString(), "").Resource;
                                            if (rolesObject != null)
                                            {
                                                if (rolesObject.Spartan_WorkFlow_Roles_by_States.Count != 0)
                                                {
                                                    if (rolesObject.Spartan_WorkFlow_Roles_by_States[0].Permission_To_New == false)
                                                    {
                                                        ObjectPermissions.New = false;
                                                    }

                                                    if (rolesObject.Spartan_WorkFlow_Roles_by_States[0].Permission_To_Modify == false)
                                                    {
                                                        ObjectPermissions.Edit = false;
                                                    }

                                                    if (rolesObject.Spartan_WorkFlow_Roles_by_States[0].Permission_to_Delete == false)
                                                    {
                                                        ObjectPermissions.Delete = false;
                                                    }

                                                    if (rolesObject.Spartan_WorkFlow_Roles_by_States[0].Permission_To_Export == false)
                                                    {
                                                        ObjectPermissions.Export = false;
                                                    }

                                                    if (rolesObject.Spartan_WorkFlow_Roles_by_States[0].Permission_To_Print == false)
                                                    {
                                                        ObjectPermissions.Print = false;
                                                    }

                                                    if (rolesObject.Spartan_WorkFlow_Roles_by_States[0].Permission_Settings == false)
                                                    {
                                                        ObjectPermissions.Configure = false;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                #endregion
                return(ObjectPermissions);
            }
            catch (ArgumentException)
            {
                return(new Permission());
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }