public void Settings(uint id)
        {
            var user = DbSession.Load <User>(id);

            PropertyBag["user"]      = user;
            PropertyBag["maxRegion"] = UInt64.MaxValue;
            if (user.Client == null)
            {
                var supplier = DbSession.Load <Supplier>(user.RootService.Id);
                if (supplier != null)
                {
                    PropertyBag["AllowWorkRegions"] = Region.GetRegionsByMask(DbSession, supplier.RegionMask);
                }
                PropertyBag["permissions"] = UserPermission.FindPermissionsByType(DbSession, UserPermissionTypes.SupplierInterface);
                RenderView("SupplierSettings");
            }
            else
            {
                var setting = user.Client.Settings;
                PropertyBag["AllowOrderRegions"] = Region.GetRegionsByMask(DbSession, setting.OrderRegionMask);
                PropertyBag["AllowWorkRegions"]  = Region.GetRegionsByMask(DbSession, user.Client.MaskRegion);
                PropertyBag["permissions"]       = UserPermission.FindPermissionsForDrugstore(DbSession);
                PropertyBag["ExcelPermissions"]  = UserPermission.FindPermissionsByType(DbSession, UserPermissionTypes.AnalitFExcel);
                PropertyBag["AccessPermissions"] = UserPermission.FindPermissionsByType(DbSession, UserPermissionTypes.AnalitFPrint)
                                                   .Where(r => r.Shortcut == "ORDR" || r.Shortcut == "CASH" || r.Shortcut == "STCK").ToArray();
                PropertyBag["PrintPermissions"] = UserPermission.FindPermissionsByType(DbSession, UserPermissionTypes.AnalitFPrint)
                                                  .Where(r => r.Shortcut != "ORDR" && r.Shortcut != "CASH" && r.Shortcut != "STCK").ToArray();
                if (user.AFNetConfig != null)
                {
                    user.AFNetConfig.Channels = BinChannel.Load(DbSession, user);
                }
                RenderView("DrugstoreSettings");
            }
        }
Beispiel #2
0
        public void ClientAssignedPermissionTest()
        {
            var permissions = UserPermission.FindPermissionsForDrugstore(session).Where(i => i.Id == 69 || i.Id == 81);

            if (user != null && permissions != null)
            {
                permissions = permissions.Select(i => session.Load <UserPermission>(i.Id)).ToArray();
                user.AssignPermission(session, permissions);
            }
            foreach (var permission in permissions)
            {
                Assert.That(user.AssignedPermissions.ToList(), Contains.Item(permission));
            }
        }
        public void RegisterClient()
        {
            var regions = Region.All(DbSession).ToArray();
            var client  = new Client(new Payer(""), regions.First());
            var user    = new User(client);

            PropertyBag["defaultSettings"] = Defaults;
            PropertyBag["client"]          = client;
            PropertyBag["user"]            = user;
            PropertyBag["address"]         = client.AddAddress("");
            PropertyBag["account"]         = user.Accounting;
            PropertyBag["permissions"]     = UserPermission.FindPermissionsForDrugstore(DbSession);
            PropertyBag["regions"]         = regions;
            PropertyBag["clientContacts"]  = new[] { new Contact(ContactType.Phone, string.Empty), new Contact(ContactType.Email, string.Empty) };
            PropertyBag["options"]         = new AdditionalSettings();
        }
Beispiel #4
0
        public virtual void AssignPermission(ISession session, IEnumerable <UserPermission> permissions)
        {
            var availability = UserPermissionAvailability.Supplier;

            if (Client != null)
            {
                availability = UserPermissionAvailability.Drugstore;
            }

            var defaultPermissions     = UserPermission.DefaultPermissions(session, availability);
            var permissionForDrugstore = UserPermission.FindPermissionsForDrugstore(session);

            permissions = permissions.Concat(defaultPermissions.Except(permissionForDrugstore))
                          .Distinct()
                          .Except(AssignedPermissions)
                          .ToArray();
            foreach (var permission in permissions)
            {
                AssignedPermissions.Add(permission);
            }
        }
        public void Add(uint clientId, User client = null)
        {
            /*Грязный ХАК, почему-то если принудительно не загрузить так, не делается Service.FindAndCheck<Service>(clientId)*/
            DbSession.Get <Client>(clientId);
            DbSession.Get <Supplier>(clientId);

            var service = client == null?Service.FindAndCheck <Service>(clientId) : client.RootService;

            var user = client ?? new User(service);

            PropertyBag["UserMessage"]     = "Текст сообщения";
            PropertyBag["deliveryAddress"] = "";
            PropertyBag["account"]         = user.Accounting;

            if (client == null)
            {
                PropertyBag["UseDefPermession"] = true;
                PropertyBag["SendToEmail"]      = true;
                //Для вьюшки - по умолчанию должен быть True.
                //Но в модели мы это не можем разместить, так как по здравому смыслу он по-умолчанию false.
                //Так мы избежим лишних действий по созданию прав на директории
                user.FtpAccess = true;
                var rejectWaibillParams = new RejectWaibillParams().Get(clientId, DbSession);
                user.SendWaybills = rejectWaibillParams.SendWaybills;
                user.SendRejects  = rejectWaibillParams.SendRejects;
            }

            PropertyBag["phonesForSendToUserList"]  = user.GetPhonesForSendingSms();            //"9031848398";
            PropertyBag["phonesForSendToAdminList"] = GetAdminByRegionForSms(user.RootService.HomeRegion.Id);

            PropertyBag["client"] = service;
            if (service.IsClient())
            {
                PropertyBag["drugstore"] = ((Client)service).Settings;
                var organizations = ((Client)service).Orgs().ToArray();
                if (organizations.Length == 1)
                {
                    PropertyBag["address"] = new Address {
                        LegalEntity = organizations.First()
                    };
                }
                PropertyBag["Organizations"] = organizations;
                PropertyBag["permissions"]   = UserPermission.FindPermissionsForDrugstore(DbSession);
            }
            else
            {
                PropertyBag["singleRegions"]        = true;
                PropertyBag["registerSupplierUser"] = true;
                PropertyBag["availibleRegions"]     = ((Supplier)service).RegionMask;
                PropertyBag["permissions"]          = UserPermission.FindPermissionsByType(DbSession, UserPermissionTypes.SupplierInterface);
            }
            PropertyBag["user"]              = user;
            PropertyBag["ExcelPermissions"]  = UserPermission.FindPermissionsByType(DbSession, UserPermissionTypes.AnalitFExcel);
            PropertyBag["AccessPermissions"] = UserPermission.FindPermissionsByType(DbSession, UserPermissionTypes.AnalitFPrint)
                                               .Where(r => r.Shortcut == "ORDR" || r.Shortcut == "CASH" || r.Shortcut == "STCK").ToArray();
            PropertyBag["PrintPermissions"] = UserPermission.FindPermissionsByType(DbSession, UserPermissionTypes.AnalitFPrint)
                                              .Where(r => r.Shortcut != "ORDR" && r.Shortcut != "CASH" && r.Shortcut != "STCK").ToArray();
            PropertyBag["emailForSend"]     = user.GetAddressForSendingClientCard();
            PropertyBag["EmailContactType"] = ContactType.Email;
            PropertyBag["PhoneContactType"] = ContactType.Phone;
            PropertyBag["regions"]          = Region.All(DbSession).ToArray();
            IList <Payer> payers = new List <Payer>();

            if (service.IsClient())
            {
                payers = ((Client)service).Payers;
            }
            else
            {
                payers = new List <Payer> {
                    DbSession.Load <Supplier>(service.Id).Payer
                }
            };

            if (payers.Count == 1)
            {
                user.Payer = payers.First();
                PropertyBag["onePayer"] = true;
            }
            else
            {
                PropertyBag["onePayer"] = false;
            }
            PropertyBag["Payers"]           = payers;
            PropertyBag["maxRegion"]        = UInt64.MaxValue;
            PropertyBag["UserRegistration"] = true;
            PropertyBag["defaultSettings"]  = Defaults;
        }