Beispiel #1
0
        public DetailViewData(FirmaSession currentFirmaSession,
                              Person personToView,
                              Project.UserProjectGridSpec userProjectGridSpec,
                              string basicProjectInfoGridName,
                              string basicProjectInfoGridDataUrl,
                              UserNotificationGridSpec userNotificationGridSpec,
                              string userNotificationGridName,
                              string userNotificationGridDataUrl,
                              string activateInactivateUrl,
                              ActionItemsUserGridSpec actionItemsUserGridSpec,
                              string actionItemsGridName,
                              string actionItemsGridDataUrl)
            : base(currentFirmaSession)
        {
            Person     = personToView;
            PageTitle  = personToView.GetFullNameFirstLast() + (!personToView.IsActive ? " (inactive)" : string.Empty);
            EntityName = "User";

            EditPersonOrganizationPrimaryContactUrl = SitkaRoute <PersonOrganizationController> .BuildUrlFromExpression(c => c.EditPersonOrganizationPrimaryContacts(personToView));

            IndexUrl = SitkaRoute <UserController> .BuildUrlFromExpression(x => x.Index());

            if (FirmaWebConfiguration.AuthenticationType == AuthenticationType.LocalAuth)
            {
                EditDetailBasicsUrl = SitkaRoute <UserController> .BuildUrlFromExpression(x => x.EditUser(personToView.PrimaryKey));

                ChangePasswordUrl = SitkaRoute <UserController> .BuildUrlFromExpression(x => x.ChangePassword(personToView.PrimaryKey));
            }

            // And again, here we should take Current FirmaSession, not the person. -- SLG & SG
            UserHasPersonViewPermissions   = new UserViewFeature().HasPermission(currentFirmaSession, personToView).HasPermission;
            UserHasPersonManagePermissions = new UserEditFeature().HasPermissionByFirmaSession(currentFirmaSession);
            UserHasAdminPermissions        = new FirmaAdminFeature().HasPermissionByFirmaSession(currentFirmaSession);

            CurrentPersonCanBeImpersonatedByCurrentUser = new FirmaImpersonateUserFeature().HasPermission(currentFirmaSession, personToView).HasPermission;

            IsViewingSelf = !currentFirmaSession.IsAnonymousUser() && currentFirmaSession.PersonID == personToView.PersonID;
            EditRolesLink = UserHasAdminPermissions
                ? ModalDialogFormHelper.MakeEditIconLink(SitkaRoute <UserController> .BuildUrlFromExpression(c => c.EditRoles(personToView)),
                                                         $"Edit Roles for User - {personToView.GetFullNameFirstLast()}",
                                                         true)
                : new HtmlString(string.Empty);

            UserProjectGridSpec         = userProjectGridSpec;
            BasicProjectInfoGridName    = basicProjectInfoGridName;
            BasicProjectInfoGridDataUrl = basicProjectInfoGridDataUrl;

            UserNotificationGridSpec    = userNotificationGridSpec;
            UserNotificationGridName    = userNotificationGridName;
            UserNotificationGridDataUrl = userNotificationGridDataUrl;
            ActivateInactivateUrl       = activateInactivateUrl;

            TenantHasStewardshipAreas = MultiTenantHelpers.GetProjectStewardshipAreaType() != null;

            ActionItemsUserGridSpec = actionItemsUserGridSpec;
            ActionItemsGridName     = actionItemsGridName;
            ActionItemsGridDataUrl  = actionItemsGridDataUrl;
        }
        public DetailViewData(Person currentPerson,
                              Person personToView,
                              ProjectInfoForUserDetailGridSpec basicProjectInfoGridSpec,
                              string basicProjectInfoGridName,
                              string basicProjectInfoGridDataUrl,
                              UserNotificationGridSpec userNotificationGridSpec,
                              string userNotificationGridName,
                              string userNotificationGridDataUrl,
                              string activateInactivateUrl,
                              bool atLeastOneAgreementHasFile)
            : base(currentPerson)
        {
            Person = personToView;
            PersonIsMereContact = !personToView.IsFullUser();
            PageTitle           = personToView.FullNameFirstLast + (!personToView.IsActive ? " (inactive)" : string.Empty);
            EntityName          = "User";
            //TODO: This gets pulled up to root
            EditPersonOrganizationPrimaryContactUrl = SitkaRoute <PersonOrganizationController> .BuildUrlFromExpression(c => c.EditPersonOrganizationPrimaryContacts(personToView));

            Index = SitkaRoute <UserController> .BuildUrlFromExpression(x => x.Index());

            UserHasPersonViewPermissions     = new UserViewFeature().HasPermission(currentPerson, personToView).HasPermission;
            UserHasEditBasicsPermission      = new UserEditBasicsFeature().HasPermission(currentPerson, personToView).HasPermission;
            UserCanViewAndCreateNewContacts  = new ContactCreateAndViewFeature().HasPermissionByPerson(currentPerson);
            UserHasViewEverythingPermissions = new FirmaAdminFeature().HasPermissionByPerson(currentPerson);
            IsViewingSelf          = currentPerson != null && currentPerson.PersonID == personToView.PersonID;
            UserHasAdminPermission = new UserEditAsAdminFeature().HasPermissionByPerson(currentPerson);
            EditRolesLink          = UserHasAdminPermission
                ? ModalDialogFormHelper.MakeEditIconLink(SitkaRoute <UserController> .BuildUrlFromExpression(c => c.EditRoles(personToView)),
                                                         $"Edit Roles for User - {personToView.FullNameFirstLast}",
                                                         true)
                : new HtmlString(string.Empty);
            AuthenticatorsDisplayString = string.Join(", ", Person.PersonAllowedAuthenticators.OrderBy(x => x.Authenticator.AuthenticatorFullName).Select(x => $"{x.Authenticator.AuthenticatorFullName} ({x.Authenticator.AuthenticatorName})"));

            BasicProjectInfoGridSpec    = basicProjectInfoGridSpec;
            BasicProjectInfoGridName    = basicProjectInfoGridName;
            BasicProjectInfoGridDataUrl = basicProjectInfoGridDataUrl;

            UserNotificationGridSpec    = userNotificationGridSpec;
            UserNotificationGridName    = userNotificationGridName;
            UserNotificationGridDataUrl = userNotificationGridDataUrl;
            ActivateInactivateUrl       = activateInactivateUrl;

            TenantHasStewardshipAreas = MultiTenantHelpers.GetProjectStewardshipAreaType() != null;
            EditContactUrl            = SitkaRoute <UserController> .BuildUrlFromExpression(x => x.EditContact(personToView));

            ProjectsForWhichUserIsAContactGridTitle = personToView.IsFullUser()
                ? $"{Models.FieldDefinition.Project.GetFieldDefinitionLabelPluralized()} for which {Person.FullNameFirstLast} is an {Models.FieldDefinition.OrganizationPrimaryContact.GetFieldDefinitionLabel()}"
                : $"{Models.FieldDefinition.Project.GetFieldDefinitionLabelPluralized()} for which {Person.FullNameFirstLast} is a {Models.FieldDefinition.Contact.GetFieldDefinitionLabel()}";

            AgreementsForWhichUserIsAContactGridTitle = personToView.IsFullUser()
                ? $"{Models.FieldDefinition.Agreement.GetFieldDefinitionLabelPluralized()} for which {Person.FullNameFirstLast} is an {Models.FieldDefinition.OrganizationPrimaryContact.GetFieldDefinitionLabel()}"
                : $"{Models.FieldDefinition.Agreement.GetFieldDefinitionLabelPluralized()} for which {Person.FullNameFirstLast} is a {Models.FieldDefinition.Contact.GetFieldDefinitionLabel()}";

            UserAgreementsGridSpec = new AgreementGridSpec(CurrentPerson, atLeastOneAgreementHasFile, false, false)
            {
                CustomExcelDownloadUrl = SitkaRoute <UserController> .BuildUrlFromExpression(tc => tc.UserAgreementsExcelDownload(personToView.PrimaryKey))
            };
            UserAgreementsGridName    = "userAgreementsFromUserGrid";
            UserAgreementsGridDataUrl =
                SitkaRoute <UserController> .BuildUrlFromExpression(
                    tc => tc.UserAgreementsGridJsonData(personToView));

            InteractionEventsForWhichUserIsAContactGridTitle = $"{Models.FieldDefinition.InteractionEvent.GetFieldDefinitionLabelPluralized()} for which {Person.FullNameFirstLast} is a {Models.FieldDefinition.Contact.GetFieldDefinitionLabel()}";
            UserInteractionEventsGridSpec    = new InteractionEventGridSpec(CurrentPerson, personToView);
            UserInteractionEventsGridName    = "userInteractionEventsFromUserGrid";
            UserInteractionEventsGridDataUrl =
                SitkaRoute <UserController> .BuildUrlFromExpression(x => x.UserInteractionEventsGridJsonData(personToView));
        }