Exemplo n.º 1
0
        public ActionResult Subjects_Select(long entityId, long instanceId)
        {
            var subjectManager          = new SubjectManager();
            var entityPermissionManager = new EntityPermissionManager();

            try
            {
                var subjects = new List <EntityPermissionGridRowModel>();
                foreach (var subject in subjectManager.Subjects)
                {
                    var rights          = entityPermissionManager.GetRights(subject.Id, entityId, instanceId);
                    var effectiveRights = entityPermissionManager.GetEffectiveRights(subject.Id, entityId, instanceId);

                    subjects.Add(EntityPermissionGridRowModel.Convert(subject, rights, effectiveRights));
                }

                return(View(new GridModel <EntityPermissionGridRowModel> {
                    Data = subjects
                }));
            }
            finally
            {
                subjectManager.Dispose();
                entityPermissionManager.Dispose();
            }
        }
        public ActionResult Subjects_Select(GridCommand command, long entityId, long instanceId)
        {
            var subjectManager          = new SubjectManager();
            var entityPermissionManager = new EntityPermissionManager();

            try
            {
                var subjectsDb = new List <Subject>();
                var count      = 0;
                if (command != null)// filter subjects based on grid filter settings
                {
                    FilterExpression  filter  = TelerikGridHelper.Convert(command.FilterDescriptors.ToList());
                    OrderByExpression orderBy = TelerikGridHelper.Convert(command.SortDescriptors.ToList());

                    subjectsDb = subjectManager.GetSubjects(filter, orderBy, command.Page, command.PageSize, out count);
                }
                else
                {
                    subjectsDb = subjectManager.Subjects.ToList();
                    count      = subjectsDb.Count();
                }

                var subjects = new List <EntityPermissionGridRowModel>();
                //using (PartyManager partyManager = new PartyManager())

                //foreach (var subject in subjectsDb)
                //{
                //    var rights = entityPermissionManager.GetRights(subject.Id, entityId, instanceId);
                //    var effectiveRights = entityPermissionManager.GetEffectiveRights(subject.Id, entityId, instanceId);

                //    subjects.Add(EntityPermissionGridRowModel.Convert(subject, rights, effectiveRights));
                //}

                var rightsDic          = entityPermissionManager.GetRights(subjectsDb, entityId, instanceId);
                var effectiveRightsDic = entityPermissionManager.GetEffectiveRights(subjectsDb, entityId, instanceId);

                foreach (var item in rightsDic)
                {
                    var subject         = subjectsDb.Where(s => s.Id.Equals(item.Key)).FirstOrDefault();
                    var rights          = item.Value;
                    var effectiveRights = effectiveRightsDic[item.Key];

                    subjects.Add(EntityPermissionGridRowModel.Convert(subject, rights, effectiveRights));
                }

                return(View(new GridModel <EntityPermissionGridRowModel> {
                    Data = subjects, Total = count
                }));
            }
            finally
            {
                subjectManager.Dispose();
                entityPermissionManager.Dispose();
            }
        }
Exemplo n.º 3
0
        private DatasetFilesModel LoadDatasetModel(long versionId)
        {
            using (EntityPermissionManager entityPermissionManager = new EntityPermissionManager())
                using (EntityManager entityManager = new EntityManager())
                    using (UserManager userManager = new UserManager())
                        using (DatasetManager dm = new DatasetManager())
                        {
                            var datasetVersion = dm.GetDatasetVersion(versionId);
                            var model          = new DatasetFilesModel
                            {
                                ServerFileList = GetDatasetFileList(datasetVersion),
                                FileSize       = this.Session.GetTenant().MaximumUploadSize
                            };

                            //Parse user right

                            var entity = entityManager.EntityRepository.Query(e => e.Name.ToUpperInvariant() == "Dataset".ToUpperInvariant() && e.EntityType == typeof(Dataset)).FirstOrDefault();

                            var userTask = userManager.FindByNameAsync(HttpContext.User.Identity.Name);
                            userTask.Wait();
                            var user   = userTask.Result;
                            int rights = 0;
                            if (user == null)
                            {
                                rights = entityPermissionManager.GetEffectiveRights(subjectId: null, entity.Id, datasetVersion.Dataset.Id);
                            }
                            else
                            {
                                rights = entityPermissionManager.GetEffectiveRights(user.Id, entity.Id, datasetVersion.Dataset.Id);
                            }
                            model.UploadAccess   = (((rights & (int)RightType.Write) > 0) || ((rights & (int)RightType.Grant) > 0));
                            model.DeleteAccess   = (((rights & (int)RightType.Delete) > 0) || ((rights & (int)RightType.Grant) > 0));
                            model.DownloadAccess = ((rights & (int)RightType.Read) > 0 || ((rights & (int)RightType.Grant) > 0));
                            model.ViewAccess     = ((rights & (int)RightType.Read) > 0 || ((rights & (int)RightType.Grant) > 0));


                            return(model);
                        }
        }
Exemplo n.º 4
0
        /// <summary>
        /// create a model to fill the table of My Dataset
        /// </summary>
        /// <remarks></remarks>
        /// <seealso cref="ShowMyDatasets"/>
        /// <param>NA</param>
        /// <returns>model</returns>
        public ActionResult _CustomMyDatasetBinding()
        {
            DataTable model = new DataTable();

            ViewData["PageSize"]    = 10;
            ViewData["CurrentPage"] = 1;

            #region header
            List <HeaderItem> headerItems = CreateHeaderItems();
            ViewData["DefaultHeaderList"] = headerItems;

            #endregion

            model = CreateDataTable(headerItems);


            DatasetManager          datasetManager          = new DatasetManager();
            EntityPermissionManager entityPermissionManager = new EntityPermissionManager();
            UserManager             userManager             = new UserManager();
            EntityManager           entityManager           = new EntityManager();


            try
            {
                var entity = entityManager.FindByName("Dataset");
                var user   = userManager.FindByNameAsync(GetUsernameOrDefault()).Result;

                List <long> gridCommands = datasetManager.GetDatasetLatestIds();
                gridCommands.Skip(Convert.ToInt16(ViewData["CurrentPage"])).Take(Convert.ToInt16(ViewData["PageSize"]));

                foreach (long datasetId in gridCommands)
                {
                    //get permissions
                    int rights = entityPermissionManager.GetEffectiveRights(user?.Id, entity.Id, datasetId);

                    if (rights > 0)
                    {
                        DataRow  dataRow  = model.NewRow();
                        Object[] rowArray = new Object[8];

                        if (datasetManager.IsDatasetCheckedIn(datasetId))
                        {
                            //long versionId = datasetManager.GetDatasetLatestVersionId (datasetId); // check for zero value
                            //DatasetVersion dsv = datasetManager.DatasetVersionRepo.Get(versionId);

                            DatasetVersion dsv = datasetManager.GetDatasetLatestVersion(datasetId);

                            //MetadataStructureManager msm = new MetadataStructureManager();
                            //dsv.Dataset.MetadataStructure = msm.Repo.Get(dsv.Dataset.MetadataStructure.Id);

                            string title       = xmlDatasetHelper.GetInformationFromVersion(dsv.Id, NameAttributeValues.title);
                            string description = xmlDatasetHelper.GetInformationFromVersion(dsv.Id, NameAttributeValues.description);

                            rowArray[0] = Convert.ToInt64(datasetId);
                            rowArray[1] = title;
                            rowArray[2] = description;
                        }
                        else
                        {
                            rowArray[0] = Convert.ToInt64(datasetId);
                            rowArray[1] = "";
                            rowArray[2] = "Dataset is just in processing.";
                        }

                        rowArray[3] = (rights & (int)RightType.Read) > 0 ? "✔" : "✘";
                        rowArray[4] = (rights & (int)RightType.Write) > 0 ? "✔" : "✘";
                        rowArray[5] = (rights & (int)RightType.Delete) > 0 ? "✔" : "✘";
                        rowArray[6] = (rights & (int)RightType.Download) > 0 ? "✔" : "✘";
                        rowArray[7] = (rights & (int)RightType.Grant) > 0 ? "✔" : "✘";

                        dataRow           = model.NewRow();
                        dataRow.ItemArray = rowArray;
                        model.Rows.Add(dataRow);
                    }
                }

                return(View(new GridModel(model)));
            }
            finally
            {
                datasetManager.Dispose();
                entityPermissionManager.Dispose();
                entityManager.Dispose();
                userManager.Dispose();
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// create a model to fill the table of My Dataset
        /// </summary>
        /// <remarks></remarks>
        /// <seealso cref="ShowMyDatasets"/>
        /// <param>NA</param>
        /// <returns>model</returns>
        public ActionResult _CustomMyDatasetBinding()
        {
            DataTable model = new DataTable();

            ViewData["PageSize"]    = 10;
            ViewData["CurrentPage"] = 1;

            #region header

            List <HeaderItem> headerItems = CreateHeaderItems();
            ViewData["DefaultHeaderList"] = headerItems;

            #endregion header

            model = CreateDataTable(headerItems);

            DatasetManager          datasetManager          = new DatasetManager();
            EntityPermissionManager entityPermissionManager = new EntityPermissionManager();
            UserManager             userManager             = new UserManager();
            EntityManager           entityManager           = new EntityManager();

            try
            {
                var entity = entityManager.FindByName("Dataset");
                var user   = userManager.FindByNameAsync(GetUsernameOrDefault()).Result;

                List <long> gridCommands = datasetManager.GetDatasetLatestIds();
                gridCommands.Skip(Convert.ToInt16(ViewData["CurrentPage"])).Take(Convert.ToInt16(ViewData["PageSize"]));

                List <DatasetVersion> datasetVersions = datasetManager.GetDatasetLatestVersions(gridCommands, false);
                foreach (var dsv in datasetVersions)
                {
                    var datasetId = dsv.Dataset.Id;

                    //get permissions
                    int rights = entityPermissionManager.GetEffectiveRights(user?.Id, entity.Id, datasetId);

                    if (rights > 0)
                    {
                        DataRow  dataRow  = model.NewRow();
                        Object[] rowArray = new Object[8];
                        string   isValid  = "no";

                        if (datasetManager.IsDatasetCheckedIn(datasetId))
                        {
                            string title       = dsv.Title;
                            string description = dsv.Description;

                            if (dsv.StateInfo != null)
                            {
                                isValid = DatasetStateInfo.Valid.ToString().Equals(dsv.StateInfo.State) ? "yes" : "no";
                            }

                            rowArray[0] = Convert.ToInt64(datasetId);
                            rowArray[1] = title;
                            rowArray[2] = description;
                        }
                        else
                        {
                            rowArray[0] = Convert.ToInt64(datasetId);
                            rowArray[1] = "";
                            rowArray[2] = "Dataset is just in processing.";
                        }

                        rowArray[3] = (rights & (int)RightType.Read) > 0 ? "✔" : "✘";
                        rowArray[4] = (rights & (int)RightType.Write) > 0 ? "✔" : "✘";
                        rowArray[5] = (rights & (int)RightType.Delete) > 0 ? "✔" : "✘";
                        //rowArray[6] = (rights & (int)RightType.Download) > 0 ? "✔" : "✘";
                        rowArray[6] = (rights & (int)RightType.Grant) > 0 ? "✔" : "✘";
                        rowArray[7] = isValid;

                        dataRow           = model.NewRow();
                        dataRow.ItemArray = rowArray;
                        model.Rows.Add(dataRow);
                    }
                }

                return(View(new GridModel(model)));
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                datasetManager.Dispose();
                entityPermissionManager.Dispose();
                entityManager.Dispose();
                userManager.Dispose();
            }
        }