CreateDataPermission() public method

public CreateDataPermission ( long subjectId, long entityId, long dataId, RightType rightType, PermissionType permissionType = PermissionType.Grant ) : DataPermission
subjectId long
entityId long
dataId long
rightType RightType
permissionType PermissionType
return BExIS.Security.Entities.Authorization.DataPermission
コード例 #1
0
ファイル: ImportController.cs プロジェクト: BEXIS2/Core
        //
        // GET: /DIM/Import/
        public ActionResult Index()
        {
            //xml metadata for import
            string metadataForImportPath = Path.Combine(AppConfiguration.GetModuleWorkspacePath("DIM"), "MetadataIDIV_EXAMPLE.xml");

            XmlDocument metadataForImport = new XmlDocument();
            metadataForImport.Load(metadataForImportPath);

            // metadataStructure DI
            long metadataStructureId = 3;

            MetadataStructureManager metadataStructureManager = new MetadataStructureManager();
            string metadataStructrueName = metadataStructureManager.Repo.Get(metadataStructureId).Name;

            // loadMapping file
            string path_mappingFile = Path.Combine(AppConfiguration.GetModuleWorkspacePath("DIM"), XmlMetadataImportHelper.GetMappingFileName(metadataStructureId, TransmissionType.mappingFileImport, metadataStructrueName));

            // XML mapper + mapping file
            XmlMapperManager xmlMapperManager = new XmlMapperManager(TransactionDirection.InternToExtern);
            xmlMapperManager.Load(path_mappingFile, "IDIV");

            // generate intern metadata
            XmlDocument metadataResult = xmlMapperManager.Generate(metadataForImport,1);

            // generate intern template
            XmlMetadataWriter xmlMetadatWriter = new XmlMetadataWriter(BExIS.Xml.Helpers.XmlNodeMode.xPath);
            XDocument metadataXml = xmlMetadatWriter.CreateMetadataXml(metadataStructureId);
            XmlDocument metadataXmlTemplate = XmlMetadataWriter.ToXmlDocument(metadataXml);

            XmlDocument completeMetadata = XmlMetadataImportHelper.FillInXmlAttributes(metadataResult, metadataXmlTemplate);

            // create Dataset

            //load datastructure
            DataStructureManager dsm = new DataStructureManager();
            ResearchPlanManager rpm = new ResearchPlanManager();
            MetadataStructureManager msm = new MetadataStructureManager();

            DatasetManager dm = new DatasetManager();
            Dataset dataset = dm.CreateEmptyDataset(dsm.UnStructuredDataStructureRepo.Get(1), rpm.Repo.Get(1), msm.Repo.Get(3));

            if (dm.IsDatasetCheckedOutFor(dataset.Id, GetUsernameOrDefault()) || dm.CheckOutDataset(dataset.Id, GetUsernameOrDefault()))
            {
                DatasetVersion workingCopy = dm.GetDatasetWorkingCopy(dataset.Id);
                workingCopy.Metadata = completeMetadata;

                string title = XmlDatasetHelper.GetInformation(workingCopy, NameAttributeValues.title);
                if (String.IsNullOrEmpty(title)) title = "No Title available.";

                dm.EditDatasetVersion(workingCopy, null, null, null);
                dm.CheckInDataset(dataset.Id, "Metadata was submited.", GetUsernameOrDefault());

                // add security
                if (GetUsernameOrDefault() != "DEFAULT")
                {
                    PermissionManager pm = new PermissionManager();
                    SubjectManager sm = new SubjectManager();

                    BExIS.Security.Entities.Subjects.User user = sm.GetUserByName(GetUsernameOrDefault());

                    foreach (RightType rightType in Enum.GetValues(typeof(RightType)).Cast<RightType>())
                    {
                        pm.CreateDataPermission(user.Id, 1, dataset.Id, rightType);
                    }
                }
            }

            return View();
        }
コード例 #2
0
ファイル: DatasetCreator.cs プロジェクト: BEXIS2/Core
        public long createDataset(string dataSetID, XmlDocument metadataXml, long metadataStructureId, DataStructure dataStructure, string researchPlanName)
        {
            Dataset dataset = new Dataset();

            DatasetManager datasetManager = new DatasetManager();
            DataStructureManager dataStructureManager = new DataStructureManager();
            ResearchPlanManager researchPlanManager = new ResearchPlanManager();
            MetadataStructureManager metadataStructureManager = new MetadataStructureManager();
            PermissionManager permissionManager = new PermissionManager();
            SubjectManager subjectManager = new SubjectManager();

            // get existing researchPlan
            ResearchPlan researchPlan = researchPlanManager.Repo.Get(r => researchPlanName.Equals(r.Title)).FirstOrDefault();

            // get existing metadataStructure (created manualy by using edited Bexis1_XSD)
            MetadataStructure metadataStructure = metadataStructureManager.Repo.Get(metadataStructureId);

            // update verwendet, da bei unstructured structures im dataset constructor dataset(dataStructure) nullexception
            dataset = datasetManager.CreateEmptyDataset(dataStructure, researchPlan, metadataStructure);
            long datasetId = dataset.Id;

            // dataPermission
            List<string> usersWithDataPerm = new List<string>();

            // create dataPermission for originalDatasetManager
            string originalDatasetManager = metadataXml.SelectSingleNode("Metadata/general/general/originalDatasetManager/originalDatasetManager").InnerText;
            User userODM = subjectManager.UsersRepo.Get(u => originalDatasetManager.Equals(u.FullName)).FirstOrDefault();
            permissionManager.CreateDataPermission(userODM.Id, 1, dataset.Id, RightType.Create);
            permissionManager.CreateDataPermission(userODM.Id, 1, dataset.Id, RightType.View);
            permissionManager.CreateDataPermission(userODM.Id, 1, dataset.Id, RightType.Update);
            permissionManager.CreateDataPermission(userODM.Id, 1, dataset.Id, RightType.Download);
            usersWithDataPerm.Add(originalDatasetManager);

            // create dataPermissions for metadataAuthor
            string metadataAuthor = metadataXml.SelectSingleNode("Metadata/general/general/metadataCreator/metadataCreator").InnerText;
            if (!usersWithDataPerm.Contains(metadataAuthor))
            {
                User userMA = subjectManager.UsersRepo.Get(u => metadataAuthor.Equals(u.FullName)).FirstOrDefault();
                permissionManager.CreateDataPermission(userMA.Id, 1, dataset.Id, RightType.Create);
                permissionManager.CreateDataPermission(userMA.Id, 1, dataset.Id, RightType.View);
                permissionManager.CreateDataPermission(userMA.Id, 1, dataset.Id, RightType.Update);
                permissionManager.CreateDataPermission(userMA.Id, 1, dataset.Id, RightType.Download);
                usersWithDataPerm.Add(metadataAuthor);
            }

            // create dataPermissions for designatedDatasetManager
            string designatedDatasetManager = metadataXml.SelectSingleNode("Metadata/general/general/designatedDatasetManager/contactType/designatedDatasetManagerName/designatedDatasetManagerName").InnerText;
            if (!usersWithDataPerm.Contains(designatedDatasetManager))
            {
                User userDDM = subjectManager.UsersRepo.Get(u => designatedDatasetManager.Equals(u.FullName)).FirstOrDefault();
                permissionManager.CreateDataPermission(userDDM.Id, 1, dataset.Id, RightType.Create);
                permissionManager.CreateDataPermission(userDDM.Id, 1, dataset.Id, RightType.View);
                permissionManager.CreateDataPermission(userDDM.Id, 1, dataset.Id, RightType.Update);
                permissionManager.CreateDataPermission(userDDM.Id, 1, dataset.Id, RightType.Download);
                usersWithDataPerm.Add(designatedDatasetManager);
            }

            // create dataPermissions for owners
            XmlNodeList ownerNodes = metadataXml.SelectNodes("Metadata/general/general/owners/ownerType/owner/owner");
            foreach (XmlNode ownerNode in ownerNodes)
            {
                string owner = ownerNode.InnerText;
                if (!usersWithDataPerm.Contains(owner))
                {
                    User userO = subjectManager.UsersRepo.Get(u => owner.Equals(u.FullName)).FirstOrDefault();
                    if (userO != null)
                    {
                        permissionManager.CreateDataPermission(userO.Id, 1, dataset.Id, RightType.Create);
                        permissionManager.CreateDataPermission(userO.Id, 1, dataset.Id, RightType.View);
                        permissionManager.CreateDataPermission(userO.Id, 1, dataset.Id, RightType.Update);
                        permissionManager.CreateDataPermission(userO.Id, 1, dataset.Id, RightType.Download);
                        usersWithDataPerm.Add(owner);
                    }
                }
            }

            // integrate metadataXml to dataset
            // checkOut
            if (datasetManager.IsDatasetCheckedOutFor(datasetId, userODM.Name) || datasetManager.CheckOutDataset(datasetId, userODM.Name))
            {
                DatasetVersion workingCopy = datasetManager.GetDatasetWorkingCopy(datasetId); // get dataset
                workingCopy.Metadata = metadataXml; // set metadata to dataset
                datasetManager.EditDatasetVersion(workingCopy, null, null, null); // edit dataset
                datasetManager.CheckInDataset(datasetId, "Metadata was submited.", userODM.Name); // check in
            }

            return dataset.Id;
        }
コード例 #3
0
        public void PublishDataset(long entityId, long datasetId)
        {
            PermissionManager permissionManager = new PermissionManager();
            SubjectManager subjectManager = new SubjectManager();

            Group group = subjectManager.GetGroupByName("everyone");

            permissionManager.CreateDataPermission(group.Id, entityId, datasetId, RightType.View);
        }
コード例 #4
0
        public DataPermission CreateDataPermission(long subjectId, long entityId, long dataId, int rightType)
        {
            PermissionManager permissionManager = new PermissionManager();

            return permissionManager.CreateDataPermission(subjectId, entityId, dataId, (RightType)rightType);
        }
コード例 #5
0
        /// <summary>
        /// Submit a Dataset based on the imformations
        /// in the CreateTaskManager
        /// </summary>
        public long SubmitDataset()
        {
            #region create dataset

            TaskManager = (CreateTaskmanager)Session["CreateDatasetTaskmanager"];

            if (TaskManager.Bus.ContainsKey(CreateTaskmanager.DATASTRUCTURE_ID)
                && TaskManager.Bus.ContainsKey(CreateTaskmanager.RESEARCHPLAN_ID)
                && TaskManager.Bus.ContainsKey(CreateTaskmanager.METADATASTRUCTURE_ID))
            {
                DatasetManager dm = new DatasetManager();
                long datasetId = 0;
                // for e new dataset
                if (!TaskManager.Bus.ContainsKey(CreateTaskmanager.ENTITY_ID))
                {
                    long datastructureId = Convert.ToInt64(TaskManager.Bus[CreateTaskmanager.DATASTRUCTURE_ID]);
                    long researchPlanId = Convert.ToInt64(TaskManager.Bus[CreateTaskmanager.RESEARCHPLAN_ID]);
                    long metadataStructureId = Convert.ToInt64(TaskManager.Bus[CreateTaskmanager.METADATASTRUCTURE_ID]);

                    DataStructureManager dsm = new DataStructureManager();

                    DataStructure dataStructure = dsm.StructuredDataStructureRepo.Get(datastructureId);
                    //if datastructure is not a structured one
                    if (dataStructure == null) dataStructure = dsm.UnStructuredDataStructureRepo.Get(datastructureId);

                    ResearchPlanManager rpm = new ResearchPlanManager();
                    ResearchPlan rp = rpm.Repo.Get(researchPlanId);

                    MetadataStructureManager msm = new MetadataStructureManager();
                    MetadataStructure metadataStructure = msm.Repo.Get(metadataStructureId);

                    var ds = dm.CreateEmptyDataset(dataStructure, rp, metadataStructure);
                    datasetId = ds.Id;

                    // add security
                    if (GetUsernameOrDefault() != "DEFAULT")
                    {
                        PermissionManager pm = new PermissionManager();
                        SubjectManager sm = new SubjectManager();

                        BExIS.Security.Entities.Subjects.User user = sm.GetUserByName(GetUsernameOrDefault());

                        foreach (RightType rightType in Enum.GetValues(typeof(RightType)).Cast<RightType>())
                        {
                            pm.CreateDataPermission(user.Id, 1, ds.Id, rightType);
                        }
                    }

                }
                else
                {
                    datasetId = Convert.ToInt64(TaskManager.Bus[CreateTaskmanager.ENTITY_ID]);
                }

                TaskManager = (CreateTaskmanager)Session["CreateDatasetTaskmanager"];

                if (dm.IsDatasetCheckedOutFor(datasetId, GetUsernameOrDefault()) || dm.CheckOutDataset(datasetId, GetUsernameOrDefault()))
                {
                    DatasetVersion workingCopy = dm.GetDatasetWorkingCopy(datasetId);

                    if (TaskManager.Bus.ContainsKey(CreateTaskmanager.METADATA_XML))
                    {
                        XDocument xMetadata = (XDocument)TaskManager.Bus[CreateTaskmanager.METADATA_XML];
                        workingCopy.Metadata = XmlMetadataWriter.ToXmlDocument(xMetadata);
                    }

                    string title = XmlDatasetHelper.GetInformation(workingCopy, NameAttributeValues.title);
                    if(String.IsNullOrEmpty(title)) title = "No Title available.";

                    TaskManager.AddToBus(CreateTaskmanager.ENTITY_TITLE, title );//workingCopy.Metadata.SelectNodes("Metadata/Description/Description/Title/Title")[0].InnerText);
                    TaskManager.AddToBus(CreateTaskmanager.ENTITY_ID, datasetId);

                    dm.EditDatasetVersion(workingCopy, null, null, null);
                    dm.CheckInDataset(datasetId, "Metadata was submited.", GetUsernameOrDefault());

                    //add to index
                    // ToDo check which SearchProvider it is, default luceneprovider
                    ISearchProvider provider = IoCFactory.Container.ResolveForSession<ISearchProvider>() as ISearchProvider;
                    provider?.UpdateSingleDatasetIndex(datasetId, IndexingAction.CREATE);

                    LoggerFactory.LogData(datasetId.ToString(), typeof(Dataset).Name, Vaiona.Entities.Logging.CrudState.Created);

                }

                return datasetId;
            }

            #endregion

            return -1;
        }
コード例 #6
0
ファイル: Migration.cs プロジェクト: BEXIS2/Core
        public string TransferDataPermission()
        {
            SubjectManager subjectManager = new SubjectManager();
            var securityMigration = new SecurityMigration();
            Dictionary<int, int> DataSetIDs = new Dictionary<int, int>();
            var groups = subjectManager.GetAllGroups();
            string DatasetMappingPath = Path.Combine(AppConfiguration.DataPath, "DatasetMapping.txt");
            //Key is last datasetId and value is the new one
            Dictionary<int, int> DatasetsMapping = File.ReadAllLines(DatasetMappingPath).AsEnumerable().Select(item => new { oldId = int.Parse(item.Split('\t')[0]), newId = int.Parse(item.Split('\t')[1]) }).ToDictionary(c => c.oldId, c => c.newId);
            DatasetManager dm = new DatasetManager();

            PermissionManager permissionManager = new PermissionManager();
            List<SecurityMigration.Right> rights = securityMigration.GetBexisRights(DataBase, DatasetsMapping);
            foreach (var group in groups)
            {
                var groupRights = rights.Where(item => item.RoleName == group.Name || item.RoleName == "_" + group.Name);

                foreach (var right in groupRights)
                {
                    int newDataSetId = DatasetsMapping.FirstOrDefault(item => item.Key == right.DataSetId).Value;

                    //each entity wich exists in this list has view and download feature
                    permissionManager.CreateDataPermission(group.Id, 1, newDataSetId, RightType.View);
                    permissionManager.CreateDataPermission(group.Id, 1, newDataSetId, RightType.Download);

                    if (right.CanEdit)
                        permissionManager.CreateDataPermission(group.Id, 1, newDataSetId, RightType.Update);

                }
            }
            foreach (var DatasetMapping in DatasetsMapping)
            {
                //extract grant user from the last version and add it to new ver
                if (dm.GetDataset(DatasetMapping.Value) == null)
                    continue;
                DatasetVersion dsv = dm.GetDatasetLatestVersion(DatasetMapping.Value);
                string grantUserEmailAddress = dsv.Metadata.SelectSingleNode("Metadata/general/general/designatedDatasetManager/contactType/email/email").InnerText;
                if (!string.IsNullOrEmpty(grantUserEmailAddress))
                {
                    var grantUser = subjectManager.GetUserByEmail(grantUserEmailAddress);
                    permissionManager.CreateDataPermission(grantUser.Id, 1, DatasetMapping.Value, RightType.Grant);
                }
            }
            return "All of permissions transfered successfully.";
        }