diff --git a/.drone.yml b/.drone.yml index 389a52a4a..93bc57bd1 100644 --- a/.drone.yml +++ b/.drone.yml @@ -1,3 +1,8 @@ +clone: + git: + image: plugins/git:next + pull: true + pipeline: test_pull_request: image: docker diff --git a/LICENSE.txt b/LICENSE.txt index 95317685c..306b9eced 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file +SOFTWARE. \ No newline at end of file diff --git a/src/Squidex.Domain.Apps.Entities/Apps/AppGrain.cs b/src/Squidex.Domain.Apps.Entities/Apps/AppGrain.cs index 2f8d229e4..31b58c315 100644 --- a/src/Squidex.Domain.Apps.Entities/Apps/AppGrain.cs +++ b/src/Squidex.Domain.Apps.Entities/Apps/AppGrain.cs @@ -70,11 +70,13 @@ namespace Squidex.Domain.Apps.Entities.Apps }); case AssignContributor assigneContributor: - return UpdateAsync(assigneContributor, async c => + return UpdateReturnAsync(assigneContributor, async c => { await GuardAppContributors.CanAssign(Snapshot.Contributors, c, userResolver, appPlansProvider.GetPlan(Snapshot.Plan?.PlanId)); AssignContributor(c); + + return EntityCreatedResult.Create(c.ContributorId, NewVersion); }); case RemoveContributor removeContributor: diff --git a/src/Squidex.Domain.Apps.Entities/Apps/Guards/GuardAppContributors.cs b/src/Squidex.Domain.Apps.Entities/Apps/Guards/GuardAppContributors.cs index dfaedfc24..000b9dc10 100644 --- a/src/Squidex.Domain.Apps.Entities/Apps/Guards/GuardAppContributors.cs +++ b/src/Squidex.Domain.Apps.Entities/Apps/Guards/GuardAppContributors.cs @@ -34,20 +34,27 @@ namespace Squidex.Domain.Apps.Entities.Apps.Guards } else { - if (await users.FindByIdAsync(command.ContributorId) == null) + var user = await users.FindByIdOrEmailAsync(command.ContributorId); + + if (user == null) { error(new ValidationError("Cannot find contributor id.", nameof(command.ContributorId))); } - else if (contributors.TryGetValue(command.ContributorId, out var existing)) + else { - if (existing == command.Permission) + command.ContributorId = user.Id; + + if (contributors.TryGetValue(command.ContributorId, out var existing)) { - error(new ValidationError("Contributor has already this permission.", nameof(command.Permission))); + if (existing == command.Permission) + { + error(new ValidationError("Contributor has already this permission.", nameof(command.Permission))); + } + } + else if (plan.MaxContributors == contributors.Count) + { + error(new ValidationError("You have reached the maximum number of contributors for your plan.")); } - } - else if (plan.MaxContributors == contributors.Count) - { - error(new ValidationError("You have reached the maximum number of contributors for your plan.")); } } }); diff --git a/src/Squidex.Domain.Apps.Entities/Apps/Services/IAppLimitsPlan.cs b/src/Squidex.Domain.Apps.Entities/Apps/Services/IAppLimitsPlan.cs index 21bbae9bf..59d0feed4 100644 --- a/src/Squidex.Domain.Apps.Entities/Apps/Services/IAppLimitsPlan.cs +++ b/src/Squidex.Domain.Apps.Entities/Apps/Services/IAppLimitsPlan.cs @@ -15,6 +15,10 @@ namespace Squidex.Domain.Apps.Entities.Apps.Services string Costs { get; } + string YearlyCosts { get; } + + string YearlyId { get; } + long MaxApiCalls { get; } long MaxAssetSize { get; } diff --git a/src/Squidex.Domain.Apps.Entities/Apps/Services/Implementations/ConfigAppLimitsPlan.cs b/src/Squidex.Domain.Apps.Entities/Apps/Services/Implementations/ConfigAppLimitsPlan.cs index 5f4892e4b..3d568c928 100644 --- a/src/Squidex.Domain.Apps.Entities/Apps/Services/Implementations/ConfigAppLimitsPlan.cs +++ b/src/Squidex.Domain.Apps.Entities/Apps/Services/Implementations/ConfigAppLimitsPlan.cs @@ -15,6 +15,10 @@ namespace Squidex.Domain.Apps.Entities.Apps.Services.Implementations public string Costs { get; set; } + public string YearlyCosts { get; set; } + + public string YearlyId { get; set; } + public long MaxApiCalls { get; set; } public long MaxAssetSize { get; set; } diff --git a/src/Squidex.Domain.Apps.Entities/Apps/Services/Implementations/ConfigAppPlansProvider.cs b/src/Squidex.Domain.Apps.Entities/Apps/Services/Implementations/ConfigAppPlansProvider.cs index 813914f09..83bd9d196 100644 --- a/src/Squidex.Domain.Apps.Entities/Apps/Services/Implementations/ConfigAppPlansProvider.cs +++ b/src/Squidex.Domain.Apps.Entities/Apps/Services/Implementations/ConfigAppPlansProvider.cs @@ -23,15 +23,23 @@ namespace Squidex.Domain.Apps.Entities.Apps.Services.Implementations MaxContributors = -1 }; - private readonly Dictionary plansById; - private readonly List plansList; + private readonly Dictionary plansById = new Dictionary(StringComparer.OrdinalIgnoreCase); + private readonly List plansList = new List(); public ConfigAppPlansProvider(IEnumerable config) { Guard.NotNull(config, nameof(config)); - plansList = config.Select(c => c.Clone()).OrderBy(x => x.MaxApiCalls).ToList(); - plansById = plansList.ToDictionary(c => c.Id, StringComparer.OrdinalIgnoreCase); + foreach (var plan in config.OrderBy(x => x.MaxApiCalls).Select(x => x.Clone())) + { + plansList.Add(plan); + plansById[plan.Id] = plan; + + if (!string.IsNullOrWhiteSpace(plan.YearlyId) && !string.IsNullOrWhiteSpace(plan.YearlyCosts)) + { + plansById[plan.YearlyId] = plan; + } + } } public IEnumerable GetAvailablePlans() diff --git a/src/Squidex.Domain.Users.MongoDb/MongoUserStore.cs b/src/Squidex.Domain.Users.MongoDb/MongoUserStore.cs index 44cd87f61..89a6d6e55 100644 --- a/src/Squidex.Domain.Users.MongoDb/MongoUserStore.cs +++ b/src/Squidex.Domain.Users.MongoDb/MongoUserStore.cs @@ -12,6 +12,7 @@ using System.Security.Claims; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Identity; +using MongoDB.Bson; using MongoDB.Driver; using Squidex.Infrastructure.MongoDb; using Squidex.Infrastructure.Tasks; @@ -72,9 +73,16 @@ namespace Squidex.Domain.Users.MongoDb return new MongoUser { Email = email, UserName = email }; } - public async Task FindByIdAsync(string id) + public async Task FindByIdOrEmailAsync(string id) { - return await Collection.Find(x => x.Id == id).FirstOrDefaultAsync(); + if (ObjectId.TryParse(id, out var parsed)) + { + return await Collection.Find(x => x.Id == id).FirstOrDefaultAsync(); + } + else + { + return await Collection.Find(x => x.NormalizedEmail == id.ToUpperInvariant()).FirstOrDefaultAsync(); + } } public async Task FindByIdAsync(string userId, CancellationToken cancellationToken) diff --git a/src/Squidex.Domain.Users/UserExtensions.cs b/src/Squidex.Domain.Users/UserExtensions.cs index cc87e88c7..1884648ce 100644 --- a/src/Squidex.Domain.Users/UserExtensions.cs +++ b/src/Squidex.Domain.Users/UserExtensions.cs @@ -35,6 +35,11 @@ namespace Squidex.Domain.Users user.SetClaim(SquidexClaimTypes.SquidexPictureUrl, GravatarHelper.CreatePictureUrl(email)); } + public static void SetHidden(this IUser user, bool value) + { + user.SetClaim(SquidexClaimTypes.SquidexHidden, value.ToString()); + } + public static void SetConsent(this IUser user) { user.SetClaim(SquidexClaimTypes.SquidexConsent, "true"); @@ -45,6 +50,11 @@ namespace Squidex.Domain.Users user.SetClaim(SquidexClaimTypes.SquidexConsentForEmails, value.ToString()); } + public static bool IsHidden(this IUser user) + { + return user.HasClaimValue(SquidexClaimTypes.SquidexHidden, "true"); + } + public static bool HasConsent(this IUser user) { return user.HasClaimValue(SquidexClaimTypes.SquidexConsent, "true"); diff --git a/src/Squidex.Domain.Users/UserManagerExtensions.cs b/src/Squidex.Domain.Users/UserManagerExtensions.cs index 302b025d1..c84c61422 100644 --- a/src/Squidex.Domain.Users/UserManagerExtensions.cs +++ b/src/Squidex.Domain.Users/UserManagerExtensions.cs @@ -71,8 +71,9 @@ namespace Squidex.Domain.Users return user; } - public static Task UpdateAsync(this UserManager userManager, IUser user, string email, string displayName) + public static Task UpdateAsync(this UserManager userManager, IUser user, string email, string displayName, bool hidden) { + user.SetHidden(hidden); user.SetEmail(email); user.SetDisplayName(displayName); diff --git a/src/Squidex.Infrastructure/EventSourcing/Grains/OrleansEventNotifier.cs b/src/Squidex.Infrastructure/EventSourcing/Grains/OrleansEventNotifier.cs index 0e97746e4..17900a901 100644 --- a/src/Squidex.Infrastructure/EventSourcing/Grains/OrleansEventNotifier.cs +++ b/src/Squidex.Infrastructure/EventSourcing/Grains/OrleansEventNotifier.cs @@ -10,26 +10,24 @@ using Orleans; namespace Squidex.Infrastructure.EventSourcing.Grains { - public sealed class OrleansEventNotifier : IEventNotifier, IInitializable + public sealed class OrleansEventNotifier : IEventNotifier { private readonly IGrainFactory factory; - private IEventConsumerManagerGrain eventConsumerManagerGrain; + private readonly Lazy eventConsumerManagerGrain; public OrleansEventNotifier(IGrainFactory factory) { Guard.NotNull(factory, nameof(factory)); - this.factory = factory; - } - - public void Initialize() - { - eventConsumerManagerGrain = factory.GetGrain("Default"); + eventConsumerManagerGrain = new Lazy(() => + { + return factory.GetGrain("Default"); + }); } public void NotifyEventsStored(string streamName) { - eventConsumerManagerGrain?.ActivateAsync(streamName); + eventConsumerManagerGrain.Value.ActivateAsync(streamName); } public IDisposable Subscribe(Action handler) diff --git a/src/Squidex.Infrastructure/Orleans/Bootstrap.cs b/src/Squidex.Infrastructure/Orleans/Bootstrap.cs index 79abd18b9..254d31b49 100644 --- a/src/Squidex.Infrastructure/Orleans/Bootstrap.cs +++ b/src/Squidex.Infrastructure/Orleans/Bootstrap.cs @@ -14,6 +14,7 @@ namespace Squidex.Infrastructure.Orleans { public sealed class Bootstrap : IStartupTask where T : IBackgroundGrain { + private const int NumTries = 10; private readonly IGrainFactory grainFactory; public Bootstrap(IGrainFactory grainFactory) @@ -23,11 +24,26 @@ namespace Squidex.Infrastructure.Orleans this.grainFactory = grainFactory; } - public Task Execute(CancellationToken cancellationToken) + public async Task Execute(CancellationToken cancellationToken) { - var grain = grainFactory.GetGrain("Default"); + for (var i = 1; i <= NumTries; i++) + { + try + { + var grain = grainFactory.GetGrain("Default"); - return grain.ActivateAsync(); + await grain.ActivateAsync(); + + return; + } + catch (OrleansException) + { + if (i == NumTries) + { + throw; + } + } + } } } } diff --git a/src/Squidex.Shared/Identity/SquidexClaimTypes.cs b/src/Squidex.Shared/Identity/SquidexClaimTypes.cs index b456cfd21..79d1bbf2d 100644 --- a/src/Squidex.Shared/Identity/SquidexClaimTypes.cs +++ b/src/Squidex.Shared/Identity/SquidexClaimTypes.cs @@ -17,6 +17,8 @@ namespace Squidex.Shared.Identity public static readonly string SquidexConsentForEmails = "urn:squidex:consent:emails"; + public static readonly string SquidexHidden = "urn:squidex:hidden"; + public static readonly string Prefix = "urn:squidex:"; } } diff --git a/src/Squidex.Shared/Users/IUserResolver.cs b/src/Squidex.Shared/Users/IUserResolver.cs index 6dea877d9..5f2772e23 100644 --- a/src/Squidex.Shared/Users/IUserResolver.cs +++ b/src/Squidex.Shared/Users/IUserResolver.cs @@ -11,6 +11,6 @@ namespace Squidex.Shared.Users { public interface IUserResolver { - Task FindByIdAsync(string id); + Task FindByIdOrEmailAsync(string idOrEmail); } } diff --git a/src/Squidex/Areas/Api/Controllers/Apps/AppContributorsController.cs b/src/Squidex/Areas/Api/Controllers/Apps/AppContributorsController.cs index 4f44f8288..7de8d6932 100644 --- a/src/Squidex/Areas/Api/Controllers/Apps/AppContributorsController.cs +++ b/src/Squidex/Areas/Api/Controllers/Apps/AppContributorsController.cs @@ -65,19 +65,24 @@ namespace Squidex.Areas.Api.Controllers.Apps /// The name of the app. /// Contributor object that needs to be added to the app. /// - /// 204 => User assigned to app. + /// 200 => User assigned to app. /// 400 => User is already assigned to the app or not found. /// 404 => App not found. /// [HttpPost] [Route("apps/{app}/contributors/")] + [ProducesResponseType(typeof(ContributorAssignedDto), 201)] [ProducesResponseType(typeof(ErrorDto), 400)] [ApiCosts(1)] public async Task PostContributor(string app, [FromBody] AssignAppContributorDto request) { - await CommandBus.PublishAsync(SimpleMapper.Map(request, new AssignContributor())); + var command = SimpleMapper.Map(request, new AssignContributor()); + var context = await CommandBus.PublishAsync(command); - return NoContent(); + var result = context.Result>(); + var response = new ContributorAssignedDto { ContributorId = result.IdOrValue }; + + return Ok(response); } /// diff --git a/src/Squidex/Areas/Api/Controllers/Apps/AppsController.cs b/src/Squidex/Areas/Api/Controllers/Apps/AppsController.cs index 66b178361..7304b11e3 100644 --- a/src/Squidex/Areas/Api/Controllers/Apps/AppsController.cs +++ b/src/Squidex/Areas/Api/Controllers/Apps/AppsController.cs @@ -99,7 +99,6 @@ namespace Squidex.Areas.Api.Controllers.Apps public async Task PostApp([FromBody] CreateAppDto request) { var command = SimpleMapper.Map(request, new CreateApp()); - var context = await CommandBus.PublishAsync(command); var result = context.Result>(); diff --git a/src/Squidex/Areas/Api/Controllers/Apps/Models/AssignAppContributorDto.cs b/src/Squidex/Areas/Api/Controllers/Apps/Models/AssignAppContributorDto.cs index ed56a9183..3f0203d30 100644 --- a/src/Squidex/Areas/Api/Controllers/Apps/Models/AssignAppContributorDto.cs +++ b/src/Squidex/Areas/Api/Controllers/Apps/Models/AssignAppContributorDto.cs @@ -15,7 +15,7 @@ namespace Squidex.Areas.Api.Controllers.Apps.Models public sealed class AssignAppContributorDto { /// - /// The id of the user to add to the app. + /// The id or email of the user to add to the app. /// [Required] public string ContributorId { get; set; } diff --git a/src/Squidex/Areas/Api/Controllers/Apps/Models/ContributorAssignedDto.cs b/src/Squidex/Areas/Api/Controllers/Apps/Models/ContributorAssignedDto.cs new file mode 100644 index 000000000..826fd9426 --- /dev/null +++ b/src/Squidex/Areas/Api/Controllers/Apps/Models/ContributorAssignedDto.cs @@ -0,0 +1,20 @@ +// ========================================================================== +// Squidex Headless CMS +// ========================================================================== +// Copyright (c) Squidex UG (haftungsbeschraenkt) +// All rights reserved. Licensed under the MIT license. +// ========================================================================== + +using System.ComponentModel.DataAnnotations; + +namespace Squidex.Areas.Api.Controllers.Apps.Models +{ + public sealed class ContributorAssignedDto + { + /// + /// The id of the user that has been assigned as contributor. + /// + [Required] + public string ContributorId { get; set; } + } +} diff --git a/src/Squidex/Areas/Api/Controllers/Content/ContentsController.cs b/src/Squidex/Areas/Api/Controllers/Content/ContentsController.cs index f5a497941..e747e1b52 100644 --- a/src/Squidex/Areas/Api/Controllers/Content/ContentsController.cs +++ b/src/Squidex/Areas/Api/Controllers/Content/ContentsController.cs @@ -268,7 +268,6 @@ namespace Squidex.Areas.Api.Controllers.Contents await contentQuery.FindSchemaAsync(App, name); var command = new UpdateContent { ContentId = id, Data = request.ToCleaned() }; - var context = await CommandBus.PublishAsync(command); var result = context.Result(); @@ -301,7 +300,6 @@ namespace Squidex.Areas.Api.Controllers.Contents await contentQuery.FindSchemaAsync(App, name); var command = new PatchContent { ContentId = id, Data = request.ToCleaned() }; - var context = await CommandBus.PublishAsync(command); var result = context.Result(); diff --git a/src/Squidex/Areas/Api/Controllers/Plans/AppPlansController.cs b/src/Squidex/Areas/Api/Controllers/Plans/AppPlansController.cs index b0d406c9b..0b93c9043 100644 --- a/src/Squidex/Areas/Api/Controllers/Plans/AppPlansController.cs +++ b/src/Squidex/Areas/Api/Controllers/Plans/AppPlansController.cs @@ -55,11 +55,12 @@ namespace Squidex.Areas.Api.Controllers.Plans public IActionResult GetPlans(string app) { var planId = appPlansProvider.GetPlanForApp(App).Id; + var plans = appPlansProvider.GetAvailablePlans().Select(x => SimpleMapper.Map(x, new PlanDto())).ToList(); var response = new AppPlansDto { CurrentPlanId = planId, - Plans = appPlansProvider.GetAvailablePlans().Select(x => SimpleMapper.Map(x, new PlanDto())).ToList(), + Plans = plans, PlanOwner = App.Plan?.Owner.Identifier, HasPortal = appPlansBillingManager.HasPortal }; diff --git a/src/Squidex/Areas/Api/Controllers/Plans/Models/PlanDto.cs b/src/Squidex/Areas/Api/Controllers/Plans/Models/PlanDto.cs index 59adb8595..7c330ad23 100644 --- a/src/Squidex/Areas/Api/Controllers/Plans/Models/PlanDto.cs +++ b/src/Squidex/Areas/Api/Controllers/Plans/Models/PlanDto.cs @@ -5,6 +5,8 @@ // All rights reserved. Licensed under the MIT license. // ========================================================================== +using System.ComponentModel.DataAnnotations; + namespace Squidex.Areas.Api.Controllers.Plans.Models { public sealed class PlanDto @@ -12,18 +14,31 @@ namespace Squidex.Areas.Api.Controllers.Plans.Models /// /// The id of the plan. /// + [Required] public string Id { get; set; } /// /// The name of the plan. /// + [Required] public string Name { get; set; } /// /// The monthly costs of the plan. /// + [Required] public string Costs { get; set; } + /// + /// The yearly costs of the plan. + /// + public string YearlyCosts { get; set; } + + /// + /// The yearly id of the plan. + /// + public string YearlyId { get; set; } + /// /// The maximum number of API calls. /// diff --git a/src/Squidex/Areas/Api/Controllers/Schemas/SchemaFieldsController.cs b/src/Squidex/Areas/Api/Controllers/Schemas/SchemaFieldsController.cs index 3a12a70d5..a2ebdb98d 100644 --- a/src/Squidex/Areas/Api/Controllers/Schemas/SchemaFieldsController.cs +++ b/src/Squidex/Areas/Api/Controllers/Schemas/SchemaFieldsController.cs @@ -11,6 +11,7 @@ using NSwag.Annotations; using Squidex.Areas.Api.Controllers.Schemas.Models; using Squidex.Domain.Apps.Entities.Schemas.Commands; using Squidex.Infrastructure.Commands; +using Squidex.Infrastructure.Reflection; using Squidex.Pipeline; namespace Squidex.Areas.Api.Controllers.Schemas @@ -50,13 +51,7 @@ namespace Squidex.Areas.Api.Controllers.Schemas [ApiCosts(1)] public async Task PostField(string app, string name, [FromBody] AddFieldDto request) { - var command = new AddField - { - Name = request.Name, - Partitioning = request.Partitioning, - Properties = request.Properties.ToProperties() - }; - + var command = SimpleMapper.Map(request, new AddField { Properties = request.Properties.ToProperties() }); var context = await CommandBus.PublishAsync(command); var result = context.Result>(); diff --git a/src/Squidex/Areas/Api/Controllers/Schemas/SchemasController.cs b/src/Squidex/Areas/Api/Controllers/Schemas/SchemasController.cs index 7118cc2a3..dcc5ffea1 100644 --- a/src/Squidex/Areas/Api/Controllers/Schemas/SchemasController.cs +++ b/src/Squidex/Areas/Api/Controllers/Schemas/SchemasController.cs @@ -120,7 +120,6 @@ namespace Squidex.Areas.Api.Controllers.Schemas public async Task PostSchema(string app, [FromBody] CreateSchemaDto request) { var command = request.ToCommand(); - var context = await CommandBus.PublishAsync(command); var result = context.Result>(); diff --git a/src/Squidex/Areas/Api/Controllers/Users/Models/CreateUserDto.cs b/src/Squidex/Areas/Api/Controllers/Users/Models/CreateUserDto.cs index b67f308ef..3caaa052f 100644 --- a/src/Squidex/Areas/Api/Controllers/Users/Models/CreateUserDto.cs +++ b/src/Squidex/Areas/Api/Controllers/Users/Models/CreateUserDto.cs @@ -11,13 +11,22 @@ namespace Squidex.Areas.Api.Controllers.Users.Models { public sealed class CreateUserDto { + /// + /// The email of the user. Unique value. + /// [Required] [EmailAddress] public string Email { get; set; } + /// + /// The display name (usually first name and last name) of the user. + /// [Required] public string DisplayName { get; set; } + /// + /// The password of the user. + /// [Required] public string Password { get; set; } } diff --git a/src/Squidex/Areas/Api/Controllers/Users/Models/PublicUserDto.cs b/src/Squidex/Areas/Api/Controllers/Users/Models/PublicUserDto.cs new file mode 100644 index 000000000..e398c88be --- /dev/null +++ b/src/Squidex/Areas/Api/Controllers/Users/Models/PublicUserDto.cs @@ -0,0 +1,26 @@ +// ========================================================================== +// Squidex Headless CMS +// ========================================================================== +// Copyright (c) Squidex UG (haftungsbeschränkt) +// All rights reserved. Licensed under the MIT license. +// ========================================================================== + +using System.ComponentModel.DataAnnotations; + +namespace Squidex.Areas.Api.Controllers.Users.Models +{ + public sealed class PublicUserDto + { + /// + /// The id of the user. + /// + [Required] + public string Id { get; set; } + + /// + /// The display name (usually first name and last name) of the user. + /// + [Required] + public string DisplayName { get; set; } + } +} diff --git a/src/Squidex/Areas/Api/Controllers/Users/Models/UpdateUserDto.cs b/src/Squidex/Areas/Api/Controllers/Users/Models/UpdateUserDto.cs index 049d62d47..e9511e2be 100644 --- a/src/Squidex/Areas/Api/Controllers/Users/Models/UpdateUserDto.cs +++ b/src/Squidex/Areas/Api/Controllers/Users/Models/UpdateUserDto.cs @@ -11,13 +11,22 @@ namespace Squidex.Areas.Api.Controllers.Users.Models { public sealed class UpdateUserDto { + /// + /// The email of the user. Unique value. + /// [Required] [EmailAddress] public string Email { get; set; } + /// + /// The display name (usually first name and last name) of the user. + /// [Required] public string DisplayName { get; set; } + /// + /// The password of the user. + /// public string Password { get; set; } } } diff --git a/src/Squidex/Areas/Api/Controllers/Users/Models/UserCreatedDto.cs b/src/Squidex/Areas/Api/Controllers/Users/Models/UserCreatedDto.cs index a4134357f..815c7b533 100644 --- a/src/Squidex/Areas/Api/Controllers/Users/Models/UserCreatedDto.cs +++ b/src/Squidex/Areas/Api/Controllers/Users/Models/UserCreatedDto.cs @@ -11,10 +11,10 @@ namespace Squidex.Areas.Api.Controllers.Users.Models { public sealed class UserCreatedDto { + /// + /// The id of the user. + /// [Required] public string Id { get; set; } - - [Required] - public string PictureUrl { get; set; } } } diff --git a/src/Squidex/Areas/Api/Controllers/Users/Models/UserDto.cs b/src/Squidex/Areas/Api/Controllers/Users/Models/UserDto.cs index c210416ef..42407d14b 100644 --- a/src/Squidex/Areas/Api/Controllers/Users/Models/UserDto.cs +++ b/src/Squidex/Areas/Api/Controllers/Users/Models/UserDto.cs @@ -23,12 +23,6 @@ namespace Squidex.Areas.Api.Controllers.Users.Models [Required] public string Email { get; set; } - /// - /// The url to the profile picture of the user. - /// - [Required] - public string PictureUrl { get; set; } - /// /// The display name (usually first name and last name) of the user. /// diff --git a/src/Squidex/Areas/Api/Controllers/Users/UserManagementController.cs b/src/Squidex/Areas/Api/Controllers/Users/UserManagementController.cs index d77397666..b3d7c33a7 100644 --- a/src/Squidex/Areas/Api/Controllers/Users/UserManagementController.cs +++ b/src/Squidex/Areas/Api/Controllers/Users/UserManagementController.cs @@ -82,7 +82,7 @@ namespace Squidex.Areas.Api.Controllers.Users { var user = await userManager.CreateAsync(userFactory, request.Email, request.DisplayName, request.Password); - var response = new UserCreatedDto { Id = user.Id, PictureUrl = user.PictureUrl() }; + var response = new UserCreatedDto { Id = user.Id }; return Ok(response); } @@ -129,7 +129,7 @@ namespace Squidex.Areas.Api.Controllers.Users private static UserDto Map(IUser user) { - return SimpleMapper.Map(user, new UserDto { DisplayName = user.DisplayName(), PictureUrl = user.PictureUrl() }); + return SimpleMapper.Map(user, new UserDto { DisplayName = user.DisplayName() }); } private bool IsSelf(string id) diff --git a/src/Squidex/Areas/Api/Controllers/Users/UsersController.cs b/src/Squidex/Areas/Api/Controllers/Users/UsersController.cs index a69b126f3..9325f0c1c 100644 --- a/src/Squidex/Areas/Api/Controllers/Users/UsersController.cs +++ b/src/Squidex/Areas/Api/Controllers/Users/UsersController.cs @@ -65,12 +65,12 @@ namespace Squidex.Areas.Api.Controllers.Users [ApiAuthorize] [HttpGet] [Route("users/")] - [ProducesResponseType(typeof(UserDto[]), 200)] + [ProducesResponseType(typeof(PublicUserDto[]), 200)] public async Task GetUsers(string query) { var entities = await userManager.QueryByEmailAsync(query ?? string.Empty); - var models = entities.Select(x => SimpleMapper.Map(x, new UserDto { DisplayName = x.DisplayName(), PictureUrl = x.PictureUrl() })).ToArray(); + var models = entities.Where(x => !x.IsHidden()).Select(x => SimpleMapper.Map(x, new UserDto { DisplayName = x.DisplayName() })).ToArray(); return Ok(models); } @@ -86,7 +86,7 @@ namespace Squidex.Areas.Api.Controllers.Users [ApiAuthorize] [HttpGet] [Route("users/{id}/")] - [ProducesResponseType(typeof(UserDto), 200)] + [ProducesResponseType(typeof(PublicUserDto), 200)] public async Task GetUser(string id) { var entity = await userManager.FindByIdAsync(id); @@ -96,7 +96,7 @@ namespace Squidex.Areas.Api.Controllers.Users return NotFound(); } - var response = SimpleMapper.Map(entity, new UserDto { DisplayName = entity.DisplayName(), PictureUrl = entity.PictureUrl() }); + var response = SimpleMapper.Map(entity, new UserDto { DisplayName = entity.DisplayName() }); return Ok(response); } diff --git a/src/Squidex/Areas/IdentityServer/Controllers/Profile/ChangeProfileModel.cs b/src/Squidex/Areas/IdentityServer/Controllers/Profile/ChangeProfileModel.cs index cb473d902..e1eb3c23e 100644 --- a/src/Squidex/Areas/IdentityServer/Controllers/Profile/ChangeProfileModel.cs +++ b/src/Squidex/Areas/IdentityServer/Controllers/Profile/ChangeProfileModel.cs @@ -17,5 +17,7 @@ namespace Squidex.Areas.IdentityServer.Controllers.Profile [Required(ErrorMessage = "DisplayName is required.")] public string DisplayName { get; set; } + + public bool IsHidden { get; set; } } } diff --git a/src/Squidex/Areas/IdentityServer/Controllers/Profile/ProfileController.cs b/src/Squidex/Areas/IdentityServer/Controllers/Profile/ProfileController.cs index 90ea54e4f..7d242ccbb 100644 --- a/src/Squidex/Areas/IdentityServer/Controllers/Profile/ProfileController.cs +++ b/src/Squidex/Areas/IdentityServer/Controllers/Profile/ProfileController.cs @@ -83,7 +83,7 @@ namespace Squidex.Areas.IdentityServer.Controllers.Profile [Route("/account/profile/update/")] public Task UpdateProfile(ChangeProfileModel model) { - return MakeChangeAsync(user => userManager.UpdateAsync(user, model.Email, model.DisplayName), + return MakeChangeAsync(user => userManager.UpdateAsync(user, model.Email, model.DisplayName, model.IsHidden), "Account updated successfully."); } @@ -195,6 +195,7 @@ namespace Squidex.Areas.IdentityServer.Controllers.Profile ExternalLogins = user.Logins, ExternalProviders = externalProviders, DisplayName = user.DisplayName(), + IsHidden = user.IsHidden(), HasPassword = await userManager.HasPasswordAsync(user), HasPasswordAuth = identityOptions.Value.AllowPasswordAuth, SuccessMessage = successMessage diff --git a/src/Squidex/Areas/IdentityServer/Controllers/Profile/ProfileVM.cs b/src/Squidex/Areas/IdentityServer/Controllers/Profile/ProfileVM.cs index 052cc9bc9..0ac09080c 100644 --- a/src/Squidex/Areas/IdentityServer/Controllers/Profile/ProfileVM.cs +++ b/src/Squidex/Areas/IdentityServer/Controllers/Profile/ProfileVM.cs @@ -22,6 +22,8 @@ namespace Squidex.Areas.IdentityServer.Controllers.Profile public string SuccessMessage { get; set; } + public bool IsHidden { get; set; } + public bool HasPassword { get; set; } public bool HasPasswordAuth { get; set; } diff --git a/src/Squidex/Areas/IdentityServer/Views/Profile/Profile.cshtml b/src/Squidex/Areas/IdentityServer/Views/Profile/Profile.cshtml index 7150c41c7..80574e1e3 100644 --- a/src/Squidex/Areas/IdentityServer/Views/Profile/Profile.cshtml +++ b/src/Squidex/Areas/IdentityServer/Views/Profile/Profile.cshtml @@ -52,7 +52,7 @@ } - +
@@ -65,7 +65,15 @@
} - + + + +
+
+ + + +
diff --git a/src/Squidex/Config/Domain/EventStoreServices.cs b/src/Squidex/Config/Domain/EventStoreServices.cs index baa744514..8f3c76ff3 100644 --- a/src/Squidex/Config/Domain/EventStoreServices.cs +++ b/src/Squidex/Config/Domain/EventStoreServices.cs @@ -53,8 +53,7 @@ namespace Squidex.Config.Domain }); services.AddSingletonAs() - .As() - .As(); + .As(); services.AddSingletonAs() .As(); diff --git a/src/Squidex/app/features/settings/pages/contributors/contributors-page.component.html b/src/Squidex/app/features/settings/pages/contributors/contributors-page.component.html index 0058a53f0..8f38e3f14 100644 --- a/src/Squidex/app/features/settings/pages/contributors/contributors-page.component.html +++ b/src/Squidex/app/features/settings/pages/contributors/contributors-page.component.html @@ -6,55 +6,53 @@ -
- Your plan allows up to {{maxContributors}} contributors. -
- - - - - - - - - - - - - - -
- - - {{contributor.contributorId | sqxUserName}} - - {{contributor.contributorId | sqxUserEmail}} - - - - -
- -