예제 #1
0
        public async Task <ApplicationLocalRole> SaveRoleTranslate(JObject data)
        {
            dynamic localRoleDto = data;
            int?    roleId       = localRoleDto.Id;
            var     localRole    = new ApplicationLocalRole()
            {
                Id = roleId ?? 0
            };

            var currentLocalRole =
                await
                _securityContext.ApplicationLocalRoles.AsNoTracking().Include(md => md.Role)
                .SingleOrDefaultAsync(md => md.Id == localRole.Id);

            if (localRole.Id > 0)
            {
                if (currentLocalRole == null)
                {
                    throw new KhodkarInvalidException(LanguageManager.ToAsErrorMessage(ExceptionKey.RoleNotFound));
                }

                localRole            = currentLocalRole;
                localRole.RowVersion = localRoleDto.RowVersion;

                _securityContext.ApplicationLocalRoles.Attach(localRole);
            }
            else
            {
                _securityContext.ApplicationLocalRoles.Add(localRole);
            }

            localRole.RoleId      = localRoleDto.ItemId;
            localRole.Name        = localRoleDto.Name;
            localRole.Description = localRoleDto.Description;
            localRole.Language    = localRoleDto.Language;

            var currentRole = await _securityContext.Roles
                              .AsNoTracking().SingleOrDefaultAsync(md => md.Id == localRole.RoleId);

            if (currentRole == null)
            {
                throw new KhodkarInvalidException(LanguageManager.ToAsErrorMessage(ExceptionKey.RoleNotFound));
            }


            AuthorizeManager.SetAndCheckModifyAndAccessRole(currentRole, localRoleDto, false);


            localRole.Status = localRoleDto.Status;
            await _securityContext.SaveChangesAsync();

            return(localRole);
        }
예제 #2
0
        public async Task Execute(string odsInstanceName, CloudOdsClaimSet claimSet, ApiMode apiMode)
        {
            var odsSqlConfiguration = await _odsSecretConfigurationProvider.GetSqlConfiguration();

            var cloudOdsInstance = await _getCloudOdsInstanceQuery.Execute(odsInstanceName);

            var firstTimeSetupConfiguration = await GetFirstTimeSetupConfiguration(cloudOdsInstance, claimSet, odsSqlConfiguration);

            SetupAndRuntimeConfigurations(firstTimeSetupConfiguration);

            if (apiMode.SupportsSingleInstance)
            {
                var defaultOdsInstance = new OdsInstanceRegistration
                {
                    Name        = odsInstanceName,
                    Description = "Default single ods instance"
                };
                await _odsInstanceFirstTimeSetupService.CompleteSetup(defaultOdsInstance, claimSet, apiMode);
            }

            CreateClaimSetForAdminApp(firstTimeSetupConfiguration.ClaimSet);

            ApplyAdditionalClaimSetModifications();

            await _usersContext.SaveChangesAsync();

            await _securityContext.SaveChangesAsync();

            await _restartAppServicesCommand.Execute(new CloudOdsApiOperationContext(cloudOdsInstance));
        }
예제 #3
0
        public async Task <bool> Execute(string odsInstanceName, CloudOdsClaimSet claimSet, ApiMode apiMode)
        {
            ExtraDatabaseInitializationAction?.Invoke();
            var restartRequired = false;

            if (apiMode.SupportsSingleInstance)
            {
                var defaultOdsInstance = new OdsInstanceRegistration
                {
                    Name         = odsInstanceName,
                    DatabaseName = _instanceService.DatabaseName(0, apiMode),
                    Description  = "Default single ods instance"
                };
                await _firstTimeSetupService.CompleteSetup(defaultOdsInstance, claimSet, apiMode);
            }

            if (!_claimSetCheckService.RequiredClaimSetsExist())
            {
                CreateClaimSetForAdminApp(claimSet);

                ApplyAdditionalClaimSetModifications();

                restartRequired = true;
            }

            await _usersContext.SaveChangesAsync();

            await _securityContext.SaveChangesAsync();

            return(restartRequired);
        }
예제 #4
0
        public async Task Execute(string odsInstanceName, CloudOdsClaimSet claimSet, ApiMode apiMode)
        {
            ExtraDatabaseInitializationAction?.Invoke();

            if (apiMode.SupportsSingleInstance)
            {
                var defaultOdsInstance = new OdsInstanceRegistration
                {
                    Name        = odsInstanceName,
                    Description = "Default single ods instance"
                };
                await _firstTimeSetupService.CompleteSetup(defaultOdsInstance, claimSet, apiMode);
            }

            CreateClaimSetForAdminApp(claimSet);

            ApplyAdditionalClaimSetModifications();

            await _usersContext.SaveChangesAsync();

            await _securityContext.SaveChangesAsync();
        }
        /// <summary>
        /// Sets the User-Widgets for the given user
        /// </summary>
        /// <param name="userWidgets">the target widgets to add</param>
        /// <param name="userName">the user for which to register these widgets</param>
        /// <returns>an empty task</returns>
        public async Task <DashboardWidgetDefinition[]> SetUserWidgets(DashboardWidgetDefinition[] widgets, string userName)
        {
            var tmp = dbContext.ShowAllTenants;

            try
            {
                dbContext.ShowAllTenants = false;
                if (dbContext.CurrentTenantId != null)
                {
                    var tenantId  = dbContext.CurrentTenantId.Value;
                    var dbwidgets = dbContext.UserWidgets.OrderBy(n => n.SortOrder).ToArray();
                    var allIds    = dbwidgets.Select(n => n.UserWidgetId)
                                    .Union(widgets.Select(n => n.UserWidgetId)).Distinct().ToArray();
                    var selection = (from i in allIds
                                     join d in dbwidgets on i equals d.UserWidgetId into j1
                                     from lj1 in j1.DefaultIfEmpty()
                                     join p in widgets on i equals p.UserWidgetId into j2
                                     from lj2 in j2.DefaultIfEmpty()
                                     select new { Id = i, Db = lj1, Posted = lj2 }).ToArray();
                    foreach (var item in selection)
                    {
                        if (item.Db == null)
                        {
                            var w = dbContext.Widgets.First(n => n.DashboardWidgetId == item.Posted.DashboardWidgetId);
                            dbContext.UserWidgets.Add(new TUserWidget()
                            {
                                DashboardWidgetId = item.Posted.DashboardWidgetId,
                                SortOrder         = dbContext.UserWidgets.Count(),
                                TenantId          = tenantId,
                                UserName          = userName,
                                CustomQueryString = w.Params.Any() ? item.Posted.CustomQueryString : null,
                                DisplayName       = !string.IsNullOrEmpty(w.TitleTemplate) ? item.Posted.DisplayName : null
                            });
                        }
                        else if (item.Posted == null)
                        {
                            dbContext.UserWidgets.Remove(item.Db);
                        }
                        else
                        {
                            item.Db.SortOrder = item.Posted.SortOrder;
                            if (item.Db.Widget.Params.Any())
                            {
                                item.Db.CustomQueryString
                                    = item.Posted.CustomQueryString;
                            }
                        }
                    }

                    await dbContext.SaveChangesAsync().ConfigureAwait(false);

                    var ret = dbContext.UserWidgets.OrderBy(n => n.SortOrder).ToArray()
                              .Select(n => new DashboardWidgetDefinition
                    {
                        UserWidgetId      = n.UserWidgetId,
                        CustomQueryString = n.Widget.Params.Any()
                                ? n.CustomQueryString
                                : n.Widget.CustomQueryString,
                        SortOrder         = n.SortOrder,
                        DashboardWidgetId = n.DashboardWidgetId,
                        DisplayName       = n.DisplayName ?? n.Widget.DisplayName,
                        TitleTemplate     = n.Widget.TitleTemplate,
                        DiagnosticsQuery  = GetQuery(n.Widget.DiagnosticsQuery.DiagnosticsQueryName),
                        SystemName        = n.Widget.SystemName,
                        Template          = n.Widget.Template,
                        Area = n.Widget.Area
                    }).ToArray();
                    return(ret);
                }
            }
            finally
            {
                dbContext.ShowAllTenants = tmp;
            }

            return(null);
        }