示例#1
0
        protected void InitializePermissionValidator()
        {
            var user = UserRepository.GetCurrentUser(UoW);

            permissionResult = ServicesConfig.CommonServices.PermissionService.ValidateUserPermission(objectType, user.Id);

            if (!permissionResult.CanRead)
            {
                var message = PermissionsSettings.GetEntityReadValidateResult(objectType);
                MessageDialogHelper.RunErrorDialog(message);
                FailInitialize = true;
            }
        }
        public PermissionControlledRepresentationJournal(IRepresentationModel representationModel, Buttons buttons = Buttons.All) : base(representationModel)
        {
            if (RepresentationModel.EntityType != null)
            {
                UpdateUserEntityPermission();
                if (!permissionResult.CanRead)
                {
                    var message = PermissionsSettings.GetEntityReadValidateResult(RepresentationModel.EntityType);
                    MessageDialogHelper.RunErrorDialog(message);
                    FailInitialize = true;
                }
            }

            this.buttons = buttons;
            ConfigureActionButtons();
        }
        public static void CreateVodovozDefaultServices()
        {
            ServicesConfig.InteractiveService = new GtkInteractiveService();
            ServicesConfig.ValidationService  = new ObjectValidator(new GtkValidationViewFactory());
            EmployeeService = new EmployeeService();

            IRepresentationJournalFactory journalFactory = new PermissionControlledRepresentationJournalFactory();

            RepresentationEntityPicker = new RepresentationEntityPickerGtk(journalFactory);

            PermissionsSettings.ConfigureEntityPermissionFinder(new Vodovoz.Domain.Permissions.EntitiesWithPermissionFinder());

            //пространство имен специально прописано чтобы при изменениях не было случайного совпадения с валидатором из QS
            var entityPermissionValidator = new Vodovoz.Domain.Permissions.EntityPermissionValidator(EmployeeSingletonRepository.GetInstance(), new PermissionRepository());
            var presetPermissionValidator = new Vodovoz.Domain.Permissions.HierarchicalPresetPermissionValidator(EmployeeSingletonRepository.GetInstance(), new PermissionRepository());
            var permissionService         = new PermissionService(entityPermissionValidator, presetPermissionValidator);

            PermissionsSettings.PermissionService        = permissionService;
            PermissionsSettings.CurrentPermissionService = new CurrentPermissionServiceAdapter(permissionService, ServicesConfig.UserService);
        }
示例#4
0
        protected void InitializePermissionValidator()
        {
            permissionResult = new PermissionResult(EntityPermission.AllAllowed);

            Type entityType = typeof(TEntity);
            int? currUserId;

            using (IUnitOfWork uow = UnitOfWorkFactory.CreateWithoutRoot()) {
                currUserId = UserRepository.GetCurrentUser(uow)?.Id;
            }
            if (!currUserId.HasValue)
            {
                return;
            }
            permissionResult = ServicesConfig.CommonServices.PermissionService.ValidateUserPermission(entityType, currUserId.Value);

            if (!permissionResult.CanRead)
            {
                var message = PermissionsSettings.GetEntityReadValidateResult(entityType);
                MessageDialogHelper.RunErrorDialog(message);
                FailInitialize = true;
            }
        }
示例#5
0
        public EmployeeViewModel(
            IAuthorizationService authorizationService,
            IEmployeeWageParametersFactory employeeWageParametersFactory,
            IEmployeeJournalFactory employeeJournalFactory,
            ISubdivisionJournalFactory subdivisionJournalFactory,
            IEmployeePostsJournalFactory employeePostsJournalFactory,
            ICashDistributionCommonOrganisationProvider commonOrganisationProvider,
            ISubdivisionService subdivisionService,
            IEmailServiceSettingAdapter emailServiceSettingAdapter,
            IWageCalculationRepository wageCalculationRepository,
            IEmployeeRepository employeeRepository,
            IUnitOfWorkGeneric <Employee> uowGeneric,
            ICommonServices commonServices,
            IValidationContextFactory validationContextFactory,
            IPhonesViewModelFactory phonesViewModelFactory,
            IWarehouseRepository warehouseRepository,
            IRouteListRepository routeListRepository,
            DriverApiUserRegisterEndpoint driverApiUserRegisterEndpoint,
            UserSettings userSettings,
            IUserRepository userRepository,
            BaseParametersProvider baseParametersProvider,
            bool traineeToEmployee = false,
            INavigationManager navigationManager = null
            ) : base(commonServices?.InteractiveService, navigationManager)
        {
            _authorizationService         = authorizationService ?? throw new ArgumentNullException(nameof(authorizationService));
            EmployeeWageParametersFactory =
                employeeWageParametersFactory ?? throw new ArgumentNullException(nameof(employeeWageParametersFactory));
            EmployeeJournalFactory      = employeeJournalFactory ?? throw new ArgumentNullException(nameof(employeeJournalFactory));
            EmployeePostsJournalFactory = employeePostsJournalFactory ?? throw new ArgumentNullException(nameof(employeePostsJournalFactory));
            SubdivisionJournalFactory   = subdivisionJournalFactory ?? throw new ArgumentNullException(nameof(subdivisionJournalFactory));

            if (commonOrganisationProvider == null)
            {
                throw new ArgumentNullException(nameof(commonOrganisationProvider));
            }

            _subdivisionService            = subdivisionService ?? throw new ArgumentNullException(nameof(subdivisionService));
            _emailServiceSettingAdapter    = emailServiceSettingAdapter ?? throw new ArgumentNullException(nameof(emailServiceSettingAdapter));
            _wageCalculationRepository     = wageCalculationRepository ?? throw new ArgumentNullException(nameof(wageCalculationRepository));
            _employeeRepository            = employeeRepository ?? throw new ArgumentNullException(nameof(employeeRepository));
            _warehouseRepository           = warehouseRepository ?? throw new ArgumentNullException(nameof(warehouseRepository));
            _routeListRepository           = routeListRepository ?? throw new ArgumentNullException(nameof(routeListRepository));
            _driverApiUserRegisterEndpoint = driverApiUserRegisterEndpoint ?? throw new ArgumentNullException(nameof(driverApiUserRegisterEndpoint));
            _userSettings           = userSettings ?? throw new ArgumentNullException(nameof(userSettings));
            UoWGeneric              = uowGeneric ?? throw new ArgumentNullException(nameof(uowGeneric));
            _commonServices         = commonServices ?? throw new ArgumentNullException(nameof(commonServices));
            _userRepository         = userRepository ?? throw new ArgumentNullException(nameof(userRepository));
            _baseParametersProvider = baseParametersProvider ?? throw new ArgumentNullException(nameof(baseParametersProvider));

            if (validationContextFactory == null)
            {
                throw new ArgumentNullException(nameof(validationContextFactory));
            }

            ConfigureValidationContext(validationContextFactory);

            if (phonesViewModelFactory == null)
            {
                throw new ArgumentNullException(nameof(phonesViewModelFactory));
            }

            PhonesViewModel = phonesViewModelFactory.CreateNewPhonesViewModel(UoW);

            if (Entity.Id == 0)
            {
                Entity.OrganisationForSalary = commonOrganisationProvider.GetCommonOrganisation(UoW);
                TabName = "Новый сотрудник";
            }
            else
            {
                TabName = Entity.GetPersonNameWithInitials();
            }

            if (Entity.Phones == null)
            {
                Entity.Phones = new List <Phone>();
            }

            SetPermissions();

            Entity.PropertyChanged += OnEntityPropertyChanged;

            organizations = UoW.GetAll <Organization>().ToList();
            FillHiddenCategories(traineeToEmployee);

            CanRegisterMobileUser = string.IsNullOrWhiteSpace(Entity.AndroidLogin) && string.IsNullOrWhiteSpace(Entity.AndroidPassword);

            var permissionResult =
                _commonServices.PermissionService.ValidateUserPermission(typeof(Employee), _commonServices.UserService.CurrentUserId);

            if (!permissionResult.CanRead)
            {
                AbortOpening(PermissionsSettings.GetEntityReadValidateResult(typeof(Employee)));
            }
        }