예제 #1
0
        /// <summary>
        /// Adds the default option types which are used for testing.
        /// </summary>
        /// <param name="dbContext"></param>
        /// <returns></returns>
        public override bool Execute(KitosContext dbContext)
        {
            var globalAdmin = dbContext.GetGlobalAdmin();
            var ownerId     = globalAdmin.Id;

            //Oversight options
            dbContext.DataProcessingOversightOptions.Add(BuildOption(new DataProcessingOversightOption(), "Egen kontrol", 0, ownerId));
            dbContext.DataProcessingOversightOptions.Add(BuildOption(new DataProcessingOversightOption(), "Ledelseserklæring", 1, ownerId));
            dbContext.DataProcessingOversightOptions.Add(BuildOption(new DataProcessingOversightOption(), "ISAE 3000", 2, ownerId));
            dbContext.DataProcessingOversightOptions.Add(BuildOption(new DataProcessingOversightOption(), "ISAE 3402 type 1", 3, ownerId));
            dbContext.DataProcessingOversightOptions.Add(BuildOption(new DataProcessingOversightOption(), "ISAE 3402 type 2", 4, ownerId));
            dbContext.DataProcessingOversightOptions.Add(BuildOption(new DataProcessingOversightOption(), "Skriftlig kontrol", 5, ownerId));
            dbContext.DataProcessingOversightOptions.Add(BuildOption(new DataProcessingOversightOption(), "Fysisk tilsyn", 6, ownerId));

            //Oversight options
            dbContext.DataProcessingDataResponsibleOptions.Add(BuildOption(new DataProcessingDataResponsibleOption(), "Leverandøren er databehandler", 0, ownerId, "(Det er vurderet at leverandøren behandler persondata på instruks fra kommunen og der skal indgås en databehandleraftale)"));
            dbContext.DataProcessingDataResponsibleOptions.Add(BuildOption(new DataProcessingDataResponsibleOption(), "Leverandøren behandler ikke personoplysninger", 1, ownerId, "(Og derfor skal der ikke indgås en databehandleraftale)"));
            dbContext.DataProcessingDataResponsibleOptions.Add(BuildOption(new DataProcessingDataResponsibleOption(), "Leverandøren er selvstændig dataansvarlig", 2, ownerId, "(Deres anvendelse af data er ikke noget vi har indflydelse på)"));
            dbContext.DataProcessingDataResponsibleOptions.Add(BuildOption(new DataProcessingDataResponsibleOption(), "Fællesdataansvar ", 3, ownerId, "(Der skal typisk indgås en anden type aftale – fortrolighedserklæring eller…)"));
            dbContext.DataProcessingDataResponsibleOptions.Add(BuildOption(new DataProcessingDataResponsibleOption(), "Kommunen er selv dataansvarlig", 4, ownerId));

            //data transfer options
            dbContext.DataProcessingBasisForTransferOptions.Add(BuildOption(new DataProcessingBasisForTransferOption(), "EU og EØS", 0, ownerId));
            dbContext.DataProcessingBasisForTransferOptions.Add(BuildOption(new DataProcessingBasisForTransferOption(), "EU's standard kontrakt /standard contract clauses", 1, ownerId));
            dbContext.DataProcessingBasisForTransferOptions.Add(BuildOption(new DataProcessingBasisForTransferOption(), "Binding corporate rules / BCR", 2, ownerId));
            dbContext.DataProcessingBasisForTransferOptions.Add(BuildOption(new DataProcessingBasisForTransferOption(), "Intet", 3, ownerId));
            dbContext.DataProcessingBasisForTransferOptions.Add(BuildOption(new DataProcessingBasisForTransferOption(), "Andet", 4, ownerId));

            //cointries
            dbContext.DataProcessingCountryOptions.Add(BuildOption(new DataProcessingCountryOption(), "Danmark", 0, ownerId));
            dbContext.DataProcessingCountryOptions.Add(BuildOption(new DataProcessingCountryOption(), "EU", 1, ownerId));

            dbContext.SaveChanges();
            return(true);
        }
예제 #2
0
        public override bool Execute(KitosContext context)
        {
            var commonOrg   = context.GetOrganization(TestOrganizations.CommonOrg);
            var globalAdmin = context.GetGlobalAdmin();

            var existing = context.Reports.AsNoTracking().FirstOrDefault(x => x.Name == _name);

            if (existing != null)
            {
                Console.Out.WriteLine($"Existing Report with name {_name} already exists in the database.");
                return(false);
            }

            var entity = new Report()
            {
                Name                = _name,
                ObjectOwnerId       = globalAdmin.Id,
                OrganizationId      = commonOrg.Id,
                LastChangedByUserId = globalAdmin.Id,
                Description         = "Test rapport oprettet til accessibility tests"
            };

            context.Reports.Add(entity);
            context.SaveChanges();

            return(true);
        }
예제 #3
0
        static int Main(string[] args)
        {
            var task           = GetArgument(args, 0);
            var additionalArgs = args.Skip(1).ToArray();

            var databaseTask = CreateTask(task, additionalArgs);
            var taskName     = $"{task}(implemented in {databaseTask.GetType().Name})";

            try
            {
                Console.WriteLine($"Executing {taskName}");
                var connectionString = GetArgument(additionalArgs, 0);
                FailOnConnectionToProd(connectionString);
                using (var context = new KitosContext(connectionString))
                {
                    var success = databaseTask.Execute(context);
                    if (success == false)
                    {
                        Console.WriteLine($"Failed to execute {taskName}");
                        return(-1);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }

            Console.WriteLine($"Executed {taskName} with success");
            return(0);
        }
예제 #4
0
        public override bool Execute(KitosContext context)
        {
            //Create a new connection string without initial catalog so that db can be dropped
            var connectionStringBuilder = new SqlConnectionStringBuilder(_connectionString);
            var dbName = connectionStringBuilder.InitialCatalog;

            connectionStringBuilder.Remove("Initial Catalog");

            using var connection = new SqlConnection(connectionStringBuilder.ConnectionString);
            try
            {
                connection.Open();
                using var sqlCommand = connection.CreateCommand();
                var sqlToDropDb =
                    $"if DB_ID('{dbName}') IS NOT NULL " +
                    "BEGIN " +
                    $"alter database [{dbName}] set single_user with rollback immediate " +
                    $"drop database [{dbName}] " +
                    "END ";

                sqlCommand.CommandText = sqlToDropDb;
                sqlCommand.ExecuteNonQuery();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
            finally
            {
                connection.Close();
            }

            return(true);
        }
예제 #5
0
        public override bool Execute(KitosContext context)
        {
            var globalAdmin = context.GetGlobalAdmin();

            var organization = new Organization
            {
                Name                = _orgName,
                AccessModifier      = AccessModifier.Public,
                TypeId              = _organizationType,
                ObjectOwnerId       = globalAdmin.Id,
                LastChangedByUserId = globalAdmin.Id,
                Config              = Config.Default(globalAdmin)
            };

            organization.OrgUnits.Add(new OrganizationUnit()
            {
                Name                = organization.Name,
                ObjectOwnerId       = globalAdmin.Id,
                LastChangedByUserId = globalAdmin.Id
            });

            context.Organizations.Add(organization);
            context.SaveChanges();

            return(true);
        }
예제 #6
0
        public override bool Execute(KitosContext context)
        {
            var commonOrg   = context.GetOrganization(TestOrganizations.CommonOrg);
            var globalAdmin = context.GetGlobalAdmin();

            var projectWithName = context.ItProjects.AsNoTracking().FirstOrDefault(x => x.Name == _name);

            if (projectWithName != null)
            {
                Console.Out.WriteLine($"Existing ItProject with name {_name} already exists in the database.");
                return(false);
            }

            var project = ItProjectFactory.Create(_name, commonOrg.Id);

            var entities = new List <IEntity>();

            entities.Add(project);
            entities.Add(project.GoalStatus);
            entities.Add(project.Handover);
            entities.AddRange(project.EconomyYears);
            entities.ForEach(entity =>
            {
                entity.ObjectOwner       = globalAdmin;
                entity.LastChangedByUser = globalAdmin;
                entity.LastChanged       = DateTime.Now;
            });

            context.ItProjects.Add(project);
            context.SaveChanges();

            return(true);
        }
예제 #7
0
        public override bool Execute(KitosContext context)
        {
            var commonOrg   = context.GetOrganization(TestOrganizations.CommonOrg);
            var globalAdmin = context.GetGlobalAdmin();

            var systemWithSameName = context.ItContracts.AsNoTracking().FirstOrDefault(x => x.Name == _name);

            if (systemWithSameName != null)
            {
                Console.Out.WriteLine($"Existing ItContract with name {_name} already exists in the database.");
                return(false);
            }

            var itContract = new ItContract
            {
                Name                = _name,
                ObjectOwnerId       = globalAdmin.Id,
                OrganizationId      = commonOrg.Id,
                LastChangedByUserId = globalAdmin.Id,
            };

            context.ItContracts.Add(itContract);
            context.SaveChanges();

            return(true);
        }
예제 #8
0
 public static User GetGlobalAdmin(this KitosContext context)
 {
     return(context
            .Users
            .AsQueryable()
            .Where(x => x.IsGlobalAdmin)
            .OrderByDescending(x => x.Id)
            .First());
 }
예제 #9
0
        public override bool Execute(KitosContext dbContext)
        {
            foreach (var databaseTask in _tasks)
            {
                Console.WriteLine($"Executing: {databaseTask}");
                databaseTask.Execute(dbContext);
                Console.WriteLine($"FINISHED: {databaseTask}");
            }

            return(true);
        }
예제 #10
0
        public override bool Execute(KitosContext context)
        {
            var organization = context.GetOrganization(_organizationName);
            var globalAdmin  = context.GetGlobalAdmin();

            //Create the new it system
            var systemWithSameName = GetItSystemnByName(context);

            if (systemWithSameName != null)
            {
                Console.Out.WriteLine($"Existing ITSystem with name {_name} already exists in the database.");
                return(false);
            }

            var itSystem = new ItSystem
            {
                Name                = _name,
                ObjectOwnerId       = globalAdmin.Id,
                OrganizationId      = organization.Id,
                LastChangedByUserId = globalAdmin.Id,
                Uuid                = Guid.NewGuid(),
                ParentId            = _parentId
            };

            context.ItSystems.Add(itSystem);
            context.SaveChanges();

            //Enable usage of the system
            var itSystemUsage = new ItSystemUsage
            {
                ItSystemId          = itSystem.Id,
                OrganizationId      = organization.Id,
                ObjectOwnerId       = globalAdmin.Id,
                LastChangedByUserId = globalAdmin.Id
            };

            itSystemUsage.ResponsibleUsage = new ItSystemUsageOrgUnitUsage
            {
                ItSystemUsage      = itSystemUsage,
                ItSystemUsageId    = itSystemUsage.Id,
                OrganizationUnit   = organization.OrgUnits.First(),
                OrganizationUnitId = organization.Id
            };

            context.ItSystemUsages.Add(itSystemUsage);
            context.SaveChanges();

            var pendingReadModelUpdate = PendingReadModelUpdate.Create(itSystemUsage, PendingReadModelUpdateSourceCategory.ItSystemUsage);

            context.PendingReadModelUpdates.Add(pendingReadModelUpdate);
            context.SaveChanges();

            return(true);
        }
예제 #11
0
        /// <summary>
        /// Replicates the actions carried out by both org-user-create.controller.ts, UsersController::Post and UserService
        /// </summary>
        /// <returns></returns>
        public override bool Execute(KitosContext context)
        {
            var newUser = CreateUser(context);

            foreach (var orgName in _organizationNames)
            {
                AssignOrganizationRole(context, newUser, orgName);
            }

            context.SaveChanges();

            return(true);
        }
예제 #12
0
        public override bool Execute(KitosContext context)
        {
            var optionTypes = LoadAllOptionTypes();

            foreach (var optionType in optionTypes)
            {
                Console.Out.WriteLine("Enabling all options of type:" + optionType.Name);
                var dbSet = context.Set(optionType).ToListAsync().GetAwaiter().GetResult();
                EnableAllLocalOptions(dbSet);
                context.SaveChanges();
            }

            return(true);
        }
예제 #13
0
        private void AssignOrganizationRole(KitosContext context, User newUser, string orgName)
        {
            var globalAdmin = context.GetGlobalAdmin();
            var org         = context.GetOrganization(orgName);
            var newRight    = new OrganizationRight
            {
                UserId              = newUser.Id,
                Role                = _role,
                OrganizationId      = org.Id,
                ObjectOwnerId       = globalAdmin.Id,
                LastChangedByUserId = globalAdmin.Id
            };

            context.OrganizationRights.Add(newRight);
            context.SaveChanges();
        }
        public override bool Execute(KitosContext context)
        {
            var globalAdmin = context.GetGlobalAdmin();

            var sensitiveDataType = new SensitivePersonalDataType()
            {
                Name = _name,
                IsLocallyAvailable  = true,
                IsObligatory        = true,
                IsEnabled           = true,
                LastChanged         = DateTime.Now,
                LastChangedByUserId = globalAdmin.Id
            };

            context.SensitivePersonalDataTypes.Add(sensitiveDataType);

            context.SaveChanges();
            return(true);
        }
        public override bool Execute(KitosContext dbContext)
        {
            var commonOrg   = dbContext.GetOrganization(TestOrganizations.CommonOrg);
            var globalAdmin = dbContext.GetGlobalAdmin();

            var agreement = new DataProcessingRegistration()
            {
                Name                = _name,
                ObjectOwnerId       = globalAdmin.Id,
                OrganizationId      = commonOrg.Id,
                LastChangedByUserId = globalAdmin.Id
            };

            agreement = dbContext.DataProcessingRegistrations.Add(agreement);
            dbContext.SaveChanges();

            var readModel = new DataProcessingRegistrationReadModel();
            var update    = new DataProcessingRegistrationReadModelUpdate(
                new GenericRepository <DataProcessingRegistrationRoleAssignmentReadModel>(dbContext),
                new OptionsService <DataProcessingRegistration, DataProcessingBasisForTransferOption, LocalDataProcessingBasisForTransferOption>
                (
                    new GenericRepository <LocalDataProcessingBasisForTransferOption>(dbContext),
                    new GenericRepository <DataProcessingBasisForTransferOption>(dbContext)
                ),
                new OptionsService <DataProcessingRegistration, DataProcessingDataResponsibleOption, LocalDataProcessingDataResponsibleOption>
                (
                    new GenericRepository <LocalDataProcessingDataResponsibleOption>(dbContext),
                    new GenericRepository <DataProcessingDataResponsibleOption>(dbContext)
                ),
                new OptionsService <DataProcessingRegistration, DataProcessingOversightOption, LocalDataProcessingOversightOption>
                (
                    new GenericRepository <LocalDataProcessingOversightOption>(dbContext),
                    new GenericRepository <DataProcessingOversightOption>(dbContext)
                )
                );

            update.Apply(agreement, readModel);

            dbContext.DataProcessingRegistrationReadModels.Add(readModel);
            dbContext.SaveChanges();

            return(true);
        }
예제 #16
0
        public override bool Execute(KitosContext context)
        {
            var organization = context.GetOrganization(_organizationName);
            var globalAdmin  = context.GetGlobalAdmin();

            var taskRef = new TaskRef()
            {
                Uuid        = new Guid(),
                Type        = "TestKLEType",
                TaskKey     = "TestKLEKey",
                Description = "Test task ref",
                OwnedByOrganizationUnitId = organization.Id,
                ObjectOwnerId             = globalAdmin.Id,
                LastChanged         = DateTime.Now,
                LastChangedByUserId = globalAdmin.Id
            };

            context.TaskRefs.Add(taskRef);
            context.SaveChanges();

            return(true);
        }
예제 #17
0
        private User CreateUser(KitosContext context)
        {
            var globalAdmin = context.GetGlobalAdmin();
            var apiUser     = "******";
            var newUser     = new User
            {
                Name                = "Automatisk oprettet testbruger",
                LastName            = $"({((_apiAccess) ? apiUser : "")}{_role:G})",
                Salt                = _salt,
                Email               = _email,
                ObjectOwnerId       = globalAdmin.Id,
                LastChangedByUserId = globalAdmin.Id,
                IsGlobalAdmin       = _role == OrganizationRole.GlobalAdmin,
                HasApiAccess        = _apiAccess
            };

            newUser.SetPassword(_password);

            context.Users.AddOrUpdate(x => x.Email, newUser);
            context.SaveChanges();
            return(newUser);
        }
예제 #18
0
 public abstract bool Execute(KitosContext dbContext);
예제 #19
0
 public TransactionManager(KitosContext context)
 {
     _context = context;
 }
예제 #20
0
 public static Organization GetOrganization(this KitosContext context, string name)
 {
     return(context
            .Organizations
            .First(x => x.Name == name));
 }
예제 #21
0
 private ItSystem GetItSystemnByName(KitosContext context)
 {
     return(context.ItSystems.AsNoTracking().FirstOrDefault(x => x.Name == _name));
 }
 public EntityFrameworkContextDatabaseControl(KitosContext kitosContext)
 {
     _kitosContext = kitosContext;
 }