-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add mutations: lockOrganizationContact, unlockOrganizationConta…
…ct (#28) feat: Add checking of xapi:my_organization:edit permission to the mutation updateOrganization
- Loading branch information
Showing
11 changed files
with
192 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/VirtoCommerce.ProfileExperienceApiModule.Data/Commands/LockOrganizationContactCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Identity; | ||
using VirtoCommerce.ExperienceApiModule.Core.Infrastructure; | ||
using VirtoCommerce.ProfileExperienceApiModule.Data.Aggregates.Contact; | ||
|
||
namespace VirtoCommerce.ProfileExperienceApiModule.Data.Commands | ||
{ | ||
public class LockOrganizationContactCommand : ICommand<ContactAggregate> | ||
{ | ||
public string UserId { get; set; } | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...ommerce.ProfileExperienceApiModule.Data/Commands/LockOrganizationContactCommandHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using MediatR; | ||
using VirtoCommerce.ProfileExperienceApiModule.Data.Aggregates.Contact; | ||
|
||
namespace VirtoCommerce.ProfileExperienceApiModule.Data.Commands | ||
{ | ||
public class LockOrganizationContactCommandHandler : IRequestHandler<LockOrganizationContactCommand, ContactAggregate> | ||
{ | ||
private readonly IContactAggregateRepository _contactAggregateRepository; | ||
|
||
public LockOrganizationContactCommandHandler(IContactAggregateRepository contactAggregateRepository) | ||
{ | ||
_contactAggregateRepository = contactAggregateRepository; | ||
} | ||
|
||
public async Task<ContactAggregate> Handle(LockOrganizationContactCommand request, CancellationToken cancellationToken) | ||
{ | ||
var contactAggregate = await _contactAggregateRepository.GetMemberAggregateRootByIdAsync<ContactAggregate>(request.UserId); | ||
|
||
contactAggregate.Contact.Status = ModuleConstants.ContactStatuses.Locked; | ||
|
||
await _contactAggregateRepository.SaveAsync(contactAggregate); | ||
|
||
return contactAggregate; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
...irtoCommerce.ProfileExperienceApiModule.Data/Commands/UnlockOrganizationContactCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Identity; | ||
using VirtoCommerce.ExperienceApiModule.Core.Infrastructure; | ||
using VirtoCommerce.ProfileExperienceApiModule.Data.Aggregates.Contact; | ||
|
||
namespace VirtoCommerce.ProfileExperienceApiModule.Data.Commands | ||
{ | ||
public class UnlockOrganizationContactCommand : ICommand<ContactAggregate> | ||
{ | ||
public string UserId { get; set; } | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...merce.ProfileExperienceApiModule.Data/Commands/UnlockOrganizationContactCommandHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using MediatR; | ||
using VirtoCommerce.ProfileExperienceApiModule.Data.Aggregates.Contact; | ||
|
||
namespace VirtoCommerce.ProfileExperienceApiModule.Data.Commands | ||
{ | ||
public class UnlockOrganizationContactCommandHandler : IRequestHandler<UnlockOrganizationContactCommand, ContactAggregate> | ||
{ | ||
private readonly IContactAggregateRepository _contactAggregateRepository; | ||
|
||
public UnlockOrganizationContactCommandHandler(IContactAggregateRepository contactAggregateRepository) | ||
{ | ||
_contactAggregateRepository = contactAggregateRepository; | ||
} | ||
|
||
public async Task<ContactAggregate> Handle(UnlockOrganizationContactCommand request, CancellationToken cancellationToken) | ||
{ | ||
var contactAggregate = await _contactAggregateRepository.GetMemberAggregateRootByIdAsync<ContactAggregate>(request.UserId); | ||
|
||
contactAggregate.Contact.Status = ModuleConstants.ContactStatuses.Approved; | ||
|
||
await _contactAggregateRepository.SaveAsync(contactAggregate); | ||
|
||
return contactAggregate; | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/VirtoCommerce.ProfileExperienceApiModule.Data/ModuleConstants.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace VirtoCommerce.ProfileExperienceApiModule.Data | ||
{ | ||
public static class ModuleConstants | ||
{ | ||
public static class Security | ||
{ | ||
public static class Permissions | ||
{ | ||
public const string MyOrganizationEdit = "xapi:my_organization:edit"; | ||
|
||
public static string[] AllPermissions { get; } = { MyOrganizationEdit }; | ||
} | ||
} | ||
|
||
public static class ContactStatuses | ||
{ | ||
public const string Locked = "Locked"; | ||
public const string Approved = "Approved"; | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/VirtoCommerce.ProfileExperienceApiModule.Data/Schemas/InputLockContactType.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using GraphQL.Types; | ||
|
||
namespace VirtoCommerce.ProfileExperienceApiModule.Data.Schemas | ||
{ | ||
public class InputLockUnlockOrganizationContactType : InputObjectGraphType | ||
{ | ||
public InputLockUnlockOrganizationContactType() | ||
{ | ||
Field<StringGraphType>("UserId"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters