Ejemplo n.º 1
0
        protected override void CoreSetup(Setup setup)
        {
            var merge = this.Cache.Merger().Action();

            var guest = merge(GuestId, v => v.UserName = "******");

            merge(SystemId, v => v.UserName = "******");

            var userGroups = new UserGroups(this.Session);

            userGroups.Guests.AddMember(guest);
        }
        public void GivenOrderItem_WhenObjectStateIsPartiallyReceived_ThenItemMayNotBeCancelledOrRejectedOrDeleted()
        {
            var administrator  = new PersonBuilder(this.Session).WithFirstName("Koen").WithUserName("admin").Build();
            var administrators = new UserGroups(this.Session).Administrators;

            administrators.AddMember(administrator);

            this.Session.Derive();
            this.Session.Commit();

            this.InstantiateObjects(this.Session);

            User user = this.Administrator;

            this.Session.SetUser(user);

            var item = new PurchaseOrderItemBuilder(this.Session)
                       .WithPart(this.finishedGood)
                       .WithQuantityOrdered(20)
                       .WithAssignedUnitPrice(5)
                       .Build();

            this.order.AddPurchaseOrderItem(item);

            this.order.SetReadyForProcessing();

            this.Session.Derive();

            var shipment = new PurchaseShipmentBuilder(this.Session).WithShipmentMethod(new ShipmentMethods(this.Session).Ground).WithShipFromParty(this.order.TakenViaSupplier).Build();

            this.Session.Derive();

            var shipmentItem = new ShipmentItemBuilder(this.Session).WithPart(this.finishedGood).WithQuantity(10).WithUnitPurchasePrice(1).Build();

            shipment.AddShipmentItem(shipmentItem);
            this.Session.Derive();

            new ShipmentReceiptBuilder(this.Session)
            .WithQuantityAccepted(3)
            .WithShipmentItem(shipmentItem)
            .WithOrderItem(item)
            .WithFacility(shipmentItem.StoredInFacility)
            .Build();

            this.Session.Derive();

            var acl = new AccessControlLists(this.Session.GetUser())[item];

            Assert.Equal(new PurchaseOrderItemShipmentStates(this.Session).PartiallyReceived, item.PurchaseOrderItemShipmentState);
            Assert.False(acl.CanExecute(M.PurchaseOrderItem.Cancel));
            Assert.False(acl.CanExecute(M.PurchaseOrderItem.Reject));
            Assert.False(acl.CanExecute(M.PurchaseOrderItem.Delete));
        }
Ejemplo n.º 3
0
        public void UserGroup()
        {
            var userGroup = new UserGroups(this.Session).Administrators;

            var employee = new Employments(this.Session).Extent().Select(v => v.Employee).First();

            this.Session.SetUser(employee);

            var acl = new AccessControlLists(employee)[userGroup];

            Assert.True(acl.CanRead(M.UserGroup.Members));
            Assert.False(acl.CanWrite(M.UserGroup.Members));
        }
Ejemplo n.º 4
0
        public void GivenOrderItem_WhenObjectStateIsCompleted_ThenItemMayNotBeCancelledOrRejectedOrDeleted()
        {
            var administrator  = new PersonBuilder(this.Session).WithFirstName("Koen").WithUserName("admin").Build();
            var administrators = new UserGroups(this.Session).Administrators;

            administrators.AddMember(administrator);

            this.Session.Derive();
            this.Session.Commit();

            this.InstantiateObjects(this.Session);

            this.SetIdentity("admin");

            var item = new PurchaseOrderItemBuilder(this.Session)
                       .WithPart(this.finishedGood)
                       .WithQuantityOrdered(3)
                       .WithActualUnitPrice(5)
                       .Build();

            this.order.AddPurchaseOrderItem(item);

            this.order.Confirm();

            this.Session.Derive();

            var shipment     = new PurchaseShipmentBuilder(this.Session).WithShipFromParty(this.supplier).WithShipmentMethod(new ShipmentMethods(this.Session).Ground).Build();
            var shipmentItem = new ShipmentItemBuilder(this.Session).WithPart(this.finishedGood).Build();

            shipment.AddShipmentItem(shipmentItem);

            new ShipmentReceiptBuilder(this.Session)
            .WithQuantityAccepted(3)
            .WithShipmentItem(shipmentItem)
            .WithOrderItem(item)
            .Build();

            this.Session.Derive();

            shipment.AppsComplete();

            this.Session.Derive();

            Assert.Equal(new PurchaseOrderItemStates(this.Session).Completed, item.PurchaseOrderItemState);
            var acl = new AccessControlList(item, this.Session.GetUser());

            Assert.False(acl.CanExecute(M.PurchaseOrderItem.Cancel));
            Assert.False(acl.CanExecute(M.PurchaseOrderItem.Reject));
            Assert.False(acl.CanExecute(M.PurchaseOrderItem.Delete));
        }
Ejemplo n.º 5
0
        protected override void BaseSetup(Setup config)
        {
            base.BaseSetup(config);

            var guest         = new PersonBuilder(this.Session).WithUserName(Users.GuestUserName).Build();
            var administrator = new PersonBuilder(this.Session).WithUserName(Users.AdministratorUserName).Build();

            var singleton = Singleton.Instance(this.Session);

            singleton.Guest = guest;

            var userGroups = new UserGroups(this.Session);

            userGroups.Guests.AddMember(guest);
            userGroups.Administrators.AddMember(administrator);
        }
Ejemplo n.º 6
0
        protected override void BaseSetup(Setup setup)
        {
            if (setup.Config.SetupSecurity)
            {
                var merge = this.Cache.Merger().Action();

                var roles      = new Roles(this.Session);
                var userGroups = new UserGroups(this.Session);

                merge(EmployeesId, v =>
                {
                    v.Role = roles.Employee;
                    v.AddSubjectGroup(userGroups.Employees);
                });
            }
        }
Ejemplo n.º 7
0
        public void SetUp()
        {
            var configuration = new Databases.Memory.IntegerId.Configuration { ObjectFactory = Config.ObjectFactory, WorkspaceFactory = new WorkspaceFactory() };
            Config.Default = new Databases.Memory.IntegerId.Database(configuration);

            Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("nl-BE");

            var database = Config.Default;
            database.Init();

            using (var session = database.CreateSession())
            {
                new Setup(session).Apply();

                session.Commit();

                using (var stringWriter = new StringWriter())
                {
                    using (var writer = new XmlTextWriter(stringWriter))
                    {
                        database.Save(writer);
                        MinimalXml = stringWriter.ToString();
                    }
                }

                var singleton = Singleton.Instance(session);
                singleton.Guest = new PersonBuilder(session).WithUserName("guest").WithLastName("guest").Build();

                var administrator = new PersonBuilder(session).WithUserName("administrator").WithLastName("Administrator").Build();
                var administrators = new UserGroups(session).Administrators;
                administrators.AddMember(administrator);

                session.Derive(true);
                session.Commit();

                using (var stringWriter = new StringWriter())
                {
                    using (var writer = new XmlTextWriter(stringWriter))
                    {
                        database.Save(writer);
                        DefaultXml = stringWriter.ToString();
                    }
                }
            }
        }
Ejemplo n.º 8
0
        protected override void BaseSetup(Setup config)
        {
            base.BaseSetup(config);

            var userGroups = new UserGroups(this.Session);

            var administrator = new PersonBuilder(this.Session).WithUniqueId(People.AdministratorId).WithUserName(Users.AdministratorUserName).Build();

            userGroups.Administrators.AddMember(administrator);
            userGroups.Creators.AddMember(administrator);

            var guest = new PersonBuilder(this.Session).WithUniqueId(People.GuestId).WithUserName(Users.GuestUserName).Build();

            userGroups.Guests.AddMember(guest);

            var singleton = this.Session.GetSingleton();

            singleton.Guest = guest;
        }
        public void GivenOrderItem_WhenObjectShipmentStateIsReceived_ThenReceiveIsNotAllowed()
        {
            var administrator  = new PersonBuilder(this.Session).WithFirstName("Koen").WithUserName("admin").Build();
            var administrators = new UserGroups(this.Session).Administrators;

            administrators.AddMember(administrator);

            this.Session.Derive();
            this.Session.Commit();

            this.InstantiateObjects(this.Session);

            User user = this.Administrator;

            this.Session.SetUser(user);

            var item = new PurchaseOrderItemBuilder(this.Session)
                       .WithPart(this.finishedGood)
                       .WithQuantityOrdered(3)
                       .WithAssignedUnitPrice(5)
                       .Build();

            this.order.AddPurchaseOrderItem(item);

            this.order.SetReadyForProcessing();
            this.Session.Derive();

            this.order.QuickReceive();
            this.Session.Derive();

            var shipment = (PurchaseShipment)item.OrderShipmentsWhereOrderItem.First.ShipmentItem.ShipmentWhereShipmentItem;

            shipment.Receive();
            this.Session.Derive();

            Assert.True(item.PurchaseOrderItemShipmentState.IsReceived);
            var acl = new AccessControlLists(this.Session.GetUser())[item];

            Assert.False(acl.CanExecute(M.PurchaseOrderItem.QuickReceive));
            Assert.False(acl.CanExecute(M.PurchaseOrderItem.Cancel));
            Assert.False(acl.CanExecute(M.PurchaseOrderItem.Reject));
            Assert.False(acl.CanExecute(M.PurchaseOrderItem.Delete));
        }
Ejemplo n.º 10
0
        public void GivenOrderItem_WhenObjectStateIsFinished_ThenItemMayNotBeCancelledOrRejectedOrDeleted()
        {
            var administrator  = new PersonBuilder(this.Session).WithFirstName("Koen").WithUserName("admin").Build();
            var administrators = new UserGroups(this.Session).Administrators;

            administrators.AddMember(administrator);

            this.Session.Derive();
            this.Session.Commit();

            this.InstantiateObjects(this.Session);

            User user = this.Administrator;

            this.Session.SetUser(user);

            var item = new PurchaseOrderItemBuilder(this.Session)
                       .WithPart(this.finishedGood)
                       .WithQuantityOrdered(3)
                       .WithAssignedUnitPrice(5)
                       .Build();

            this.order.AddPurchaseOrderItem(item);

            this.Session.Derive();

            this.order.PurchaseOrderState = new PurchaseOrderStates(this.Session).Finished;

            this.Session.Derive();

            Assert.Equal(new PurchaseOrderItemStates(this.Session).Finished, item.PurchaseOrderItemState);
            var acl = new AccessControlLists(this.Session.GetUser())[item];

            Assert.False(acl.CanExecute(M.PurchaseOrderItem.Cancel));
            Assert.False(acl.CanExecute(M.PurchaseOrderItem.Reject));
            Assert.False(acl.CanExecute(M.PurchaseOrderItem.Delete));
        }
Ejemplo n.º 11
0
        public void GivenLoggedUserIsAdministrator_WhenAccessingSingleton_ThenLoggedInUserIsGrantedAccess()
        {
            var existingAdministrator = this.Administrator;
            var secondAdministrator   = new PersonBuilder(this.Session).WithLastName("second admin").Build();

            Assert.False(secondAdministrator.IsAdministrator());

            var internalOrganisation = this.InternalOrganisation;

            this.Session.Derive();

            User user = this.Administrator;

            this.Session.SetUser(user);

            var acl = new AccessControlLists(existingAdministrator)[internalOrganisation];

            Assert.True(acl.CanRead(M.Organisation.Name));

            acl = new AccessControlLists(existingAdministrator)[internalOrganisation];
            Assert.True(acl.CanWrite(M.Organisation.Name));

            var administrators = new UserGroups(this.Session).Administrators;

            administrators.AddMember(secondAdministrator);

            this.Session.Derive();

            Assert.True(secondAdministrator.IsAdministrator());

            acl = new AccessControlLists(existingAdministrator)[internalOrganisation];
            Assert.True(acl.CanRead(M.Organisation.Name));

            acl = new AccessControlLists(existingAdministrator)[internalOrganisation];
            Assert.True(acl.CanWrite(M.Organisation.Name));
        }
Ejemplo n.º 12
0
        public void GivenOrderItem_WhenObjectStateIsRejected_ThenItemMayNotBeCancelledOrRejectedOrDeleted()
        {
            var administrator = new PersonBuilder(this.DatabaseSession).WithFirstName("Koen").WithUserName("admin").Build();
            var administrators = new UserGroups(this.DatabaseSession).Administrators;
            administrators.AddMember(administrator);

            this.DatabaseSession.Derive(true);
            this.DatabaseSession.Commit();

            this.InstantiateObjects(this.DatabaseSession);

            Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity("admin", "Forms"), new string[0]);

            var item = new SalesOrderItemBuilder(this.DatabaseSession)
                .WithProduct(this.good)
                .WithQuantityOrdered(3)
                .WithActualUnitPrice(5)
                .Build();

            this.order.AddSalesOrderItem(item);

            this.DatabaseSession.Derive(true);

            item.Reject();

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(new SalesOrderItemObjectStates(this.DatabaseSession).Rejected, item.CurrentObjectState);
            var acl = new AccessControlList(item, new Users(this.DatabaseSession).GetCurrentUser());
            Assert.IsFalse(acl.CanExecute(SalesOrderItems.Meta.Cancel));
            Assert.IsFalse(acl.CanExecute(SalesOrderItems.Meta.Reject));
        }
Ejemplo n.º 13
0
        public void GivenInternalOrganisation_WhenOperationsRoleIsUsed_ThenOperationsUserGroupIsDerived()
        {
            this.InstantiateObjects(this.DatabaseSession);

            var internalOrganisation = new InternalOrganisationBuilder(this.DatabaseSession)
                .WithName("Internal")
                .WithLocale(new Locales(this.DatabaseSession).EnglishGreatBritain)
                .WithPreferredCurrency(this.euro)
                .WithEmployeeRole(new Roles(this.DatabaseSession).Administrator)
                .WithDefaultPaymentMethod(this.ownBankAccount)
                .WithPartyContactMechanism(this.billingAddress)
                .Build();

            this.DatabaseSession.Derive(true);

            var name = string.Format("{0} for {1})", new Roles(this.DatabaseSession).Administrator.Name, internalOrganisation.Name);
            var userGroup = new UserGroups(this.DatabaseSession).FindBy(UserGroups.Meta.Name, name);
            Assert.IsNotNull(userGroup);
        }
Ejemplo n.º 14
0
        public void GivenOrderItem_WhenObjectStateIsPartiallyShipped_ThenProductChangeIsNotAllowed()
        {
            var administrator = new PersonBuilder(this.DatabaseSession).WithFirstName("Koen").WithUserName("admin").Build();
            var administrators = new UserGroups(this.DatabaseSession).Administrators;
            administrators.AddMember(administrator);

            this.DatabaseSession.Derive(true);
            this.DatabaseSession.Commit();

            this.InstantiateObjects(this.DatabaseSession);

            Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity("admin", "Forms"), new string[0]);

            var inventoryItem = (NonSerializedInventoryItem)this.part.InventoryItemsWherePart[0];
            inventoryItem.AddInventoryItemVariance(new InventoryItemVarianceBuilder(this.DatabaseSession).WithQuantity(1).WithReason(new VarianceReasons(this.DatabaseSession).Unknown).Build());

            this.DatabaseSession.Derive(true);

            var item = new SalesOrderItemBuilder(this.DatabaseSession)
                .WithProduct(this.good)
                .WithQuantityOrdered(3)
                .WithActualUnitPrice(5)
                .Build();

            this.order.AddSalesOrderItem(item);

            this.DatabaseSession.Derive(true);

            this.order.Confirm();

            this.DatabaseSession.Derive(true);

            var shipment = (CustomerShipment)this.order.ShipToAddress.ShipmentsWhereShipToAddress[0];

            var pickList = shipment.ShipmentItems[0].ItemIssuancesWhereShipmentItem[0].PickListItem.PickListWherePickListItem;
            pickList.Picker = new Persons(this.DatabaseSession).FindBy(Persons.Meta.LastName, "orderProcessor");
            pickList.SetPicked();

            this.DatabaseSession.Derive(true);

            var package = new ShipmentPackageBuilder(this.DatabaseSession).Build();
            shipment.AddShipmentPackage(package);

            foreach (ShipmentItem shipmentItem in shipment.ShipmentItems)
            {
                package.AddPackagingContent(new PackagingContentBuilder(this.DatabaseSession).WithShipmentItem(shipmentItem).WithQuantity(shipmentItem.Quantity).Build());
            }

            this.DatabaseSession.Derive(true);

            shipment.Ship();

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(new SalesOrderItemObjectStates(this.DatabaseSession).PartiallyShipped, item.CurrentObjectState);
            var acl = new AccessControlList(item, new Users(this.DatabaseSession).GetCurrentUser());
            Assert.IsFalse(acl.CanWrite(SalesOrderItems.Meta.Product));
        }
Ejemplo n.º 15
0
        public void GivenOrderItem_WhenObjectStateIsPartiallyReceived_ThenProductChangeIsNotAllowed()
        {
            var administrator = new PersonBuilder(this.DatabaseSession).WithFirstName("Koen").WithUserName("admin").Build();
            var administrators = new UserGroups(this.DatabaseSession).Administrators;
            administrators.AddMember(administrator);

            this.DatabaseSession.Derive(true);
            this.DatabaseSession.Commit();

            this.InstantiateObjects(this.DatabaseSession);

            var good = new GoodBuilder(this.DatabaseSession)
                .WithSku("10101")
                .WithName("good")
                .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece)
                .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized)
                .WithVatRate(new VatRates(this.DatabaseSession).FindBy(VatRates.Meta.Rate,21))
                .Build();

            Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity("admin", "Forms"), new string[0]);

            var item = new PurchaseOrderItemBuilder(this.DatabaseSession)
                .WithProduct(good)
                .WithQuantityOrdered(3)
                .WithActualUnitPrice(5)
                .Build();

            this.order.AddPurchaseOrderItem(item);

            this.order.Confirm();

            this.DatabaseSession.Derive(true);

            var shipment = new PurchaseShipmentBuilder(this.DatabaseSession).WithShipFromParty(this.supplier).Build();
            var shipmentItem = new ShipmentItemBuilder(this.DatabaseSession).WithGood(good).Build();
            shipment.AddShipmentItem(shipmentItem);

            new ShipmentReceiptBuilder(this.DatabaseSession)
                .WithQuantityAccepted(1)
                .WithShipmentItem(shipmentItem)
                .WithOrderItem(item)
                .Build();

            shipment.AppsComplete();

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(new PurchaseOrderItemObjectStates(this.DatabaseSession).PartiallyReceived, item.CurrentObjectState);
            var acl = new AccessControlList(item, new Users(this.DatabaseSession).GetCurrentUser());
            Assert.IsFalse(acl.CanWrite(PurchaseOrderItems.Meta.Product));
        }
Ejemplo n.º 16
0
        public void GivenOrderItem_WhenObjectStateIsRejected_ThenItemMayNotBeCancelledOrRejectedOrDeleted()
        {
            var administrator = new PersonBuilder(this.DatabaseSession).WithFirstName("Koen").WithUserName("admin").Build();
            var administrators = new UserGroups(this.DatabaseSession).Administrators;
            administrators.AddMember(administrator);

            this.DatabaseSession.Derive(true);
            this.DatabaseSession.Commit();

            this.InstantiateObjects(this.DatabaseSession);

            var good = new GoodBuilder(this.DatabaseSession)
                .WithSku("10101")
                .WithName("good")
                .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece)
                .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized)
                .WithVatRate(new VatRates(this.DatabaseSession).FindBy(VatRates.Meta.Rate,21))
                .Build();

            Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity("admin", "Forms"), new string[0]);

            var item = new PurchaseOrderItemBuilder(this.DatabaseSession)
                .WithProduct(good)
                .WithQuantityOrdered(3)
                .WithActualUnitPrice(5)
                .Build();

            this.order.AddPurchaseOrderItem(item);

            this.DatabaseSession.Derive(true);

            item.Reject();

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(new PurchaseOrderItemObjectStates(this.DatabaseSession).Rejected, item.CurrentObjectState);
            var acl = new AccessControlList(item, new Users(this.DatabaseSession).GetCurrentUser());
            Assert.IsFalse(acl.CanExecute(PurchaseOrderItems.Meta.Cancel));
            Assert.IsFalse(acl.CanExecute(PurchaseOrderItems.Meta.Reject));
            Assert.IsFalse(acl.CanExecute(PurchaseOrderItems.Meta.Delete));
        }
Ejemplo n.º 17
0
        public void GivenSalesInvoice_WhenObjectStateIsWrittenOff_ThenCheckTransitions()
        {
            var customer = new OrganisationBuilder(this.DatabaseSession).WithName("customer").Build();
            var contactMechanism = new PostalAddressBuilder(this.DatabaseSession)
                .WithAddress1("Haverwerf 15")
                .WithPostalBoundary(new PostalBoundaryBuilder(this.DatabaseSession)
                                        .WithLocality("Mechelen")
                                        .WithCountry(new Countries(this.DatabaseSession).FindBy(Countries.Meta.IsoCode, "BE"))
                                        .Build())

                .Build();

            var administrator = new PersonBuilder(this.DatabaseSession).WithFirstName("Koen").WithUserName("administrator").Build();
            var administrators = new UserGroups(this.DatabaseSession).Administrators;
            administrators.AddMember(administrator);

            this.DatabaseSession.Derive(true);
            this.DatabaseSession.Commit();

            Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity("administrator", "Forms"), new string[0]);

            var invoice = new SalesInvoiceBuilder(this.DatabaseSession)
                .WithInvoiceNumber("1")
                .WithBillToCustomer(customer)
                .WithBillToContactMechanism(contactMechanism)
                .WithSalesInvoiceType(new SalesInvoiceTypes(this.DatabaseSession).SalesInvoice)
                .WithBilledFromInternalOrganisation(new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation"))
                .Build();

            new CustomerRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(customer).WithInternalOrganisation(Singleton.Instance(this.DatabaseSession).DefaultInternalOrganisation).Build();

            invoice.Send();
            invoice.WriteOff();

            this.DatabaseSession.Derive(true);

            var acl = new AccessControlList(invoice, new Users(this.DatabaseSession).GetCurrentUser());
            Assert.IsFalse(acl.CanExecute(SalesInvoices.Meta.Send));
            Assert.IsFalse(acl.CanExecute(SalesInvoices.Meta.WriteOff));
            Assert.IsFalse(acl.CanExecute(SalesInvoices.Meta.CancelInvoice));
        }
Ejemplo n.º 18
0
        public void GivenSalesInvoice_WhenObjectStateIsPartiallyPaid_ThenCheckTransitions()
        {
            var customer = new OrganisationBuilder(this.DatabaseSession).WithName("customer").Build();
            var contactMechanism = new PostalAddressBuilder(this.DatabaseSession)
                .WithAddress1("Haverwerf 15")
                .WithPostalBoundary(new PostalBoundaryBuilder(this.DatabaseSession)
                                        .WithLocality("Mechelen")
                                        .WithCountry(new Countries(this.DatabaseSession).FindBy(Countries.Meta.IsoCode, "BE"))
                                        .Build())

                .Build();

            var administrator = new PersonBuilder(this.DatabaseSession).WithFirstName("Koen").WithUserName("administrator").Build();
            var administrators = new UserGroups(this.DatabaseSession).Administrators;
            administrators.AddMember(administrator);

            var good = new GoodBuilder(this.DatabaseSession)
                .WithSku("10101")
                .WithVatRate(new VatRateBuilder(this.DatabaseSession).WithRate(0).Build())
                .WithName("good")
                .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized)
                .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece)
                .Build();

            this.DatabaseSession.Derive(true);
            this.DatabaseSession.Commit();

            Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity("administrator", "Forms"), new string[0]);

            var invoice = new SalesInvoiceBuilder(this.DatabaseSession)
                .WithInvoiceNumber("1")
                .WithBillToCustomer(customer)
                .WithBillToContactMechanism(contactMechanism)
                .WithSalesInvoiceType(new SalesInvoiceTypes(this.DatabaseSession).SalesInvoice)
                .WithBilledFromInternalOrganisation(new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation"))
                .WithSalesInvoiceItem(new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(good).WithQuantity(1).WithActualUnitPrice(100M).WithSalesInvoiceItemType(new SalesInvoiceItemTypes(this.DatabaseSession).ProductItem).Build())
                .Build();

            new CustomerRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(customer).WithInternalOrganisation(Singleton.Instance(this.DatabaseSession).DefaultInternalOrganisation).Build();

            this.DatabaseSession.Derive(true);

            new ReceiptBuilder(this.DatabaseSession)
                .WithAmount(90)
                .WithPaymentApplication(new PaymentApplicationBuilder(this.DatabaseSession).WithInvoiceItem(invoice.SalesInvoiceItems[0]).WithAmountApplied(90).Build())
                .Build();

            this.DatabaseSession.Derive(true);

            var acl = new AccessControlList(invoice, new Users(this.DatabaseSession).GetCurrentUser());
            Assert.IsFalse(acl.CanExecute(SalesInvoices.Meta.Send));
            Assert.IsTrue(acl.CanExecute(SalesInvoices.Meta.WriteOff));
            Assert.IsFalse(acl.CanExecute(SalesInvoices.Meta.CancelInvoice));
        }
Ejemplo n.º 19
0
        public void SetUp()
        {
            var configuration = new Configuration { ObjectFactory = Config.ObjectFactory, WorkspaceFactory = new WorkspaceFactory() };
            Config.Default = new Database(configuration);

            Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-US");

            var database = Config.Default;
            database.Init();

            using (var session = database.CreateSession())
            {
                try
                {
                    new Setup(session).Apply();

                    session.Commit();

                    using (var stringWriter = new StringWriter())
                    {
                        using (var writer = new XmlTextWriter(stringWriter))
                        {
                            database.Save(writer);
                            MinimalXml = stringWriter.ToString();
                        }
                    }

                    var singleton = Singleton.Instance(session);
                    singleton.Guest = new PersonBuilder(session)
                        .WithUserName(Users.GuestUserName)
                        .WithLastName("Guest")
                        .WithCreationDate(DateTime.MinValue)
                        .WithLastModifiedDate(DateTime.UtcNow)
                        .Build();

                    singleton.DefaultLocale = new Locales(session).FindBy(Locales.Meta.Name, "nl-NL");

                    var administrator = new PersonBuilder(session)
                        .WithUserName(Users.AdministratorUserName)
                        .WithLastName("Administrator")
                        .WithCreationDate(DateTime.MinValue)
                        .WithLastModifiedDate(DateTime.UtcNow)
                        .Build();

                    session.Derive(true);

                    var administrators = new UserGroups(session).Administrators;
                    administrators.AddMember(administrator);

                    session.Derive(true);
                    session.Commit();

                    using (var stringWriter = new StringWriter())
                    {
                        using (var writer = new XmlTextWriter(stringWriter))
                        {
                            database.Save(writer);
                            DefaultXml = stringWriter.ToString();
                        }
                    }
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e.StackTrace);
                    throw;
                }
            }
        }
Ejemplo n.º 20
0
        public void GivenSalesInvoiceCreatedBySalesRep_WhenCurrentUserInAdministratorRole_ThenAccessIsGranted()
        {
            var customer = new Organisations(this.DatabaseSession).FindBy(Organisations.Meta.Name, "customer");
            var contactMechanism = new PostalAddressBuilder(this.DatabaseSession)
                .WithAddress1("Haverwerf 15")
                .WithPostalBoundary(new PostalBoundaryBuilder(this.DatabaseSession)
                                        .WithLocality("Mechelen")
                                        .WithCountry(new Countries(this.DatabaseSession).FindBy(Countries.Meta.IsoCode, "BE"))
                                        .Build())

                .Build();

            var administrator = new PersonBuilder(this.DatabaseSession).WithFirstName("Koen").WithUserName("admin").Build();
            var administrators = new UserGroups(this.DatabaseSession).Administrators;
            administrators.AddMember(administrator);

            this.DatabaseSession.Derive(true);

            var supplierContact = new PersonBuilder(this.DatabaseSession).WithUserName("suppliercontact").WithLastName("suppliercontact").Build();
            var supplier = new OrganisationBuilder(this.DatabaseSession).WithName("supplier").Build();

            new SupplierRelationshipBuilder(this.DatabaseSession)
                .WithSupplier(supplier)
                .WithInternalOrganisation(new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation"))
                .WithFromDate(DateTime.UtcNow)
                .Build();

            new OrganisationContactRelationshipBuilder(this.DatabaseSession).WithContact(supplierContact).WithOrganisation(supplier).WithFromDate(DateTime.UtcNow).Build();

            this.DatabaseSession.Derive(true);
            this.DatabaseSession.Commit();

            Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity("salesRep", "Forms"), new string[0]);

            var invoice = new SalesInvoiceBuilder(this.DatabaseSession)
                .WithInvoiceNumber("1")
                .WithBillToCustomer(customer)
                .WithBillToContactMechanism(contactMechanism)
                .WithSalesInvoiceType(new SalesInvoiceTypes(this.DatabaseSession).SalesInvoice)
                .WithBilledFromInternalOrganisation(new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation"))
                .Build();

            new CustomerRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(customer).WithInternalOrganisation(Singleton.Instance(this.DatabaseSession).DefaultInternalOrganisation).Build();

            this.DatabaseSession.Derive(true);

            Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity("admin", "Forms"), new string[0]);
            var acl = new AccessControlList(invoice, new Users(this.DatabaseSession).GetCurrentUser());

            Assert.IsTrue(acl.CanWrite(SalesInvoices.Meta.Comment));
            Assert.IsTrue(acl.CanRead(SalesInvoices.Meta.Comment));
            Assert.IsTrue(acl.CanExecute(SalesInvoices.Meta.Send));
        }
Ejemplo n.º 21
0
        private static void SetupFull()
        {
            var configuration = new Adapters.Memory.IntegerId.Configuration { ObjectFactory = Config.ObjectFactory };
            Config.Default = new Adapters.Memory.IntegerId.Database(configuration);

            Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-GB");
            Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("en-GB");

            var database = Config.Default;
            database.Init();

            using (var session = database.CreateSession())
            {
                new Setup(session, null).Apply();
                new Security(session).Apply();

                session.Derive(true);
                session.Commit();

                using (var stringWriter = new StringWriter())
                {
                    using (var writer = new XmlTextWriter(stringWriter))
                    {
                        database.Save(writer);
                        basicXml = stringWriter.ToString();
                    }
                }

                var singleton = Singleton.Instance(session);
                singleton.Guest = new PersonBuilder(session).WithUserName("guest").WithLastName("guest").Build();

                var administrator = new PersonBuilder(session).WithUserName("administrator").WithLastName("Administrator").Build();

                var belgium = new Countries(session).CountryByIsoCode["BE"];
                var euro = belgium.Currency;

                var bank = new BankBuilder(session).WithCountry(belgium).WithName("ING België").WithBic("BBRUBEBB").Build();

                var ownBankAccount = new OwnBankAccountBuilder(session)
                    .WithBankAccount(new BankAccountBuilder(session).WithBank(bank)
                                        .WithCurrency(euro)
                                        .WithIban("BE68539007547034")
                                        .WithNameOnAccount("Koen")
                                        .Build())
                    .WithDescription("Main bank account")
                    .Build();

                var postalBoundary = new PostalBoundaryBuilder(session).WithLocality("Mechelen").WithCountry(belgium).Build();
                var postalAddress = new PostalAddressBuilder(session).WithAddress1("Kleine Nieuwedijkstraat 2").WithPostalBoundary(postalBoundary).Build();

                var billingAddress =
                    new PartyContactMechanismBuilder(session).WithContactMechanism(postalAddress).WithContactPurpose(
                        new ContactMechanismPurposes(session).BillingAddress).WithUseAsDefault(true).Build();

                var shippingAddress =
                    new PartyContactMechanismBuilder(session).WithContactMechanism(postalAddress).WithContactPurpose(
                        new ContactMechanismPurposes(session).ShippingAddress).WithUseAsDefault(true).Build();

                var internalOrganisation = new InternalOrganisationBuilder(session)
                    .WithLocale(new Locales(session).EnglishGreatBritain)
                    .WithName("internalOrganisation")
                    .WithPreferredCurrency(euro)
                    .WithIncomingShipmentNumberPrefix("incoming shipmentno: ")
                    .WithPurchaseInvoiceNumberPrefix("incoming invoiceno: ")
                    .WithPurchaseOrderNumberPrefix("purchase orderno: ")
                    .WithPartyContactMechanism(billingAddress)
                    .WithPartyContactMechanism(shippingAddress)
                    .WithEmployeeRole(new Roles(session).Administrator)
                    .WithEmployeeRole(new Roles(session).Procurement)
                    .WithEmployeeRole(new Roles(session).Sales)
                    .WithEmployeeRole(new Roles(session).Operations)
                    .WithEmployeeRole(new Roles(session).Administrator)
                    .WithDefaultPaymentMethod(ownBankAccount)
                    .Build();

                Singleton.Instance(session).DefaultInternalOrganisation = internalOrganisation;

                var facility = new WarehouseBuilder(session).WithName("facility").WithOwner(internalOrganisation).Build();
                internalOrganisation.DefaultFacility = facility;

                new StoreBuilder(session)
                    .WithName("store")
                    .WithDefaultFacility(facility)
                    .WithOwner(internalOrganisation)
                    .WithOutgoingShipmentNumberPrefix("shipmentno: ")
                    .WithSalesInvoiceNumberPrefix("invoiceno: ")
                    .WithSalesOrderNumberPrefix("orderno: ")
                    .WithDefaultShipmentMethod(new ShipmentMethods(session).Ground)
                    .WithDefaultCarrier(new Carriers(session).Fedex)
                    .WithCreditLimit(500)
                    .WithPaymentGracePeriod(10)
                    .Build();

                var customer = new OrganisationBuilder(session).WithName("customer").WithLocale(singleton.DefaultLocale).Build();
                var supplier = new OrganisationBuilder(session).WithName("supplier").WithLocale(singleton.DefaultLocale).Build();
                var purchaser = new PersonBuilder(session).WithLastName("purchaser").WithUserName("purchaser").Build();
                var salesrep = new PersonBuilder(session).WithLastName("salesRep").WithUserName("salesRep").Build();
                var orderProcessor =
                    new PersonBuilder(session).WithLastName("orderProcessor").WithUserName("orderProcessor").Build();

                new CustomerRelationshipBuilder(session).WithCustomer(customer).WithInternalOrganisation(internalOrganisation).WithFromDate(DateTime.UtcNow).Build();

                new SupplierRelationshipBuilder(session).WithSupplier(supplier).WithInternalOrganisation(internalOrganisation).WithFromDate(DateTime.UtcNow).Build();

                new EmploymentBuilder(session).WithFromDate(DateTime.UtcNow).WithEmployee(purchaser).WithEmployer(internalOrganisation).Build();

                new EmploymentBuilder(session).WithFromDate(DateTime.UtcNow).WithEmployee(salesrep).WithEmployer(internalOrganisation).Build();

                new EmploymentBuilder(session).WithFromDate(DateTime.UtcNow).WithEmployee(orderProcessor).WithEmployer(internalOrganisation).Build();

                new SalesRepRelationshipBuilder(session).WithFromDate(DateTime.UtcNow).WithCustomer(customer).WithSalesRepresentative(salesrep).Build();

                session.Derive(true);

                var administrators = new UserGroups(session).Administrators;
                administrators.AddMember(administrator);

                var usergroups = internalOrganisation.UserGroupsWhereParty;
                usergroups = internalOrganisation.UserGroupsWhereParty;
                usergroups.Filter.AddEquals(UserGroups.Meta.Parent, new Roles(session).Operations.UserGroupWhereRole);
                var userGroup = usergroups.First;

                userGroup.AddMember(orderProcessor);

                usergroups = internalOrganisation.UserGroupsWhereParty;
                usergroups.Filter.AddEquals(UserGroups.Meta.Parent, new Roles(session).Procurement.UserGroupWhereRole);
                userGroup = usergroups.First;

                userGroup.AddMember(purchaser);

                session.Derive(true);
                session.Commit();

                using (var stringWriter = new StringWriter())
                {
                    using (var writer = new XmlTextWriter(stringWriter))
                    {
                        database.Save(writer);
                        fullXml = stringWriter.ToString();
                    }
                }
            }
        }
Ejemplo n.º 22
0
        public ActionResult Setup()
        {
            if (this.IsProduction)
            {
                throw new Exception("Setup is not supported in production, use Console.");
            }

            var database = Config.Default;
            database.Init();

            var dataPath = ConfigurationManager.AppSettings["dataPath"];
            if (!Path.IsPathRooted(dataPath))
            {
                dataPath = HttpRuntime.AppDomainAppPath + dataPath;
            }

            using (var session = database.CreateSession())
            {
                new Setup(session, new DirectoryInfo(dataPath)).Apply();

                var administrators = new UserGroups(session).Administrators;

                var koen = new PersonBuilder(session)
                    .WithFirstName("John")
                    .WithLastName("Doe")
                    .WithUserName("*****@*****.**")
                    .WithUserPasswordHash("AE9dXDanpvHfD2+eaJi0KSyQ+Awb3m1ixg9ujfK5YJSzZlblxz8+ihVE4aN3QeaIsQ==")  // abc123
                    .Build();

                administrators.AddMember(koen);

                var acme = new OrganisationBuilder(session)
                    .WithName("Acme")
                    .WithOwner(koen)
                    .WithEmployee(koen)
                    .Build();

                session.Derive(true);
                session.Commit();
            }

            return this.View("Index");
        }
Ejemplo n.º 23
0
        public override string[] GetUsersInRole(string roleName)
        {
            var database = Config.Default;

            var userIds = new ArrayList();
            using (ISession session = database.CreateSession())
            {
                var userGroup = new UserGroups(session).FindBy(UserGroups.Meta.Name, roleName);
                if (userGroup != null)
                {
                    foreach (User user in userGroup.Members)
                    {
                        userIds.Add(user.UserName);
                    }
                }
            }

            return (string[])userIds.ToArray(typeof(string));
        }
Ejemplo n.º 24
0
        public static bool IsAdministrator(this User @this)
        {
            var administrators = new UserGroups(@this.Session()).Administrators;

            return(administrators.Members.Contains(@this));
        }
Ejemplo n.º 25
0
        public void GivenSalesOrderCreatedByCustomer_WhenCurrentUserInAdministratorRole_ThenAccessIsGranted()
        {
            var mechelen = new CityBuilder(this.DatabaseSession).WithName("Mechelen").Build();
            var customer = new PersonBuilder(this.DatabaseSession).WithLastName("customer").WithUserName("customer").Build();
            var internalOrganisation = Singleton.Instance(this.DatabaseSession).DefaultInternalOrganisation;

            new CustomerRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(customer).WithInternalOrganisation(internalOrganisation).Build();

            var administrator = new PersonBuilder(this.DatabaseSession).WithFirstName("Koen").WithUserName("admin").Build();
            var administrators = new UserGroups(this.DatabaseSession).Administrators;
            administrators.AddMember(administrator);
            this.DatabaseSession.Derive(true);

            Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity("customer", "Forms"), new string[0]);

            var order = new SalesOrderBuilder(this.DatabaseSession)
                .WithBillToCustomer(customer)
                .WithShipToCustomer(customer)
                .WithShipToAddress(new PostalAddressBuilder(this.DatabaseSession).WithGeographicBoundary(mechelen).WithAddress1("Haverwerf 15").Build())
                .Build();

            this.DatabaseSession.Derive(true);

            Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity("admin", "Forms"), new string[0]);
            var acl = new AccessControlList(order, new Users(this.DatabaseSession).GetCurrentUser());

            Assert.IsTrue(acl.CanWrite(SalesOrders.Meta.Comment));
            Assert.IsTrue(acl.CanRead(SalesOrders.Meta.Comment));
            Assert.IsTrue(acl.CanExecute(SalesOrders.Meta.Confirm));
        }