Skip to content

Commit 14bf5a2

Browse files
authored
Merge pull request #1 from WindowsAppCommunity/role-data-on-publisher-graph
Add role data to Publisher.ParentPublishers and Publisher.ChildPublishers commands
2 parents a3f009c + 420840d commit 14bf5a2

File tree

8 files changed

+47
-19
lines changed

8 files changed

+47
-19
lines changed

src/Commands/Publisher/ChildPublishers/AddChildPublisherCommand.cs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,23 @@ public class AddChildPublisherCommand : Command
1515
/// <summary>
1616
/// Initializes a new instance of the <see cref="AddChildPublisherCommand"/> class.
1717
/// </summary>
18-
public AddChildPublisherCommand(WacsdkCommandConfig config, Option<string> repoOption, Option<string> idOption, Option<string> publisherIdOption)
18+
public AddChildPublisherCommand(WacsdkCommandConfig config, Option<string> repoOption, Option<string> idOption, Option<string> publisherIdOption, Option<string> roleIdOption, Option<string> roleNameOption, Option<string> roleDescriptionOption)
1919
: base("add", "Adds a child publisher to the Publisher.")
2020
{
2121
AddOption(repoOption);
2222
AddOption(idOption);
2323
AddOption(publisherIdOption);
24+
AddOption(roleIdOption);
25+
AddOption(roleNameOption);
26+
AddOption(roleDescriptionOption);
2427

25-
this.SetHandler(InvokeAsync, repoOption, idOption, publisherIdOption);
28+
this.SetHandler(InvokeAsync, repoOption, idOption, publisherIdOption, roleIdOption, roleNameOption, roleDescriptionOption);
2629
this.Config = config;
2730
}
2831

2932
protected WacsdkCommandConfig Config { get; init; }
3033

31-
public async Task InvokeAsync(string repo, string id, string publisherId)
34+
public async Task InvokeAsync(string repo, string id, string publisherId, string roleId, string roleName, string roleDescription)
3235
{
3336
Guard.IsNotNullOrWhiteSpace(publisherId);
3437

@@ -43,8 +46,19 @@ public async Task InvokeAsync(string repo, string id, string publisherId)
4346
var childPublisher = await GetPublisherByIdAsync(repo, publisherId, cancellationToken);
4447
Logger.LogInformation($"Got {nameof(childPublisher.Id)}: {childPublisher.Id}");
4548

49+
var role = new Role
50+
{
51+
Id = roleId,
52+
Name = roleName,
53+
Description = roleDescription
54+
};
55+
56+
var readOnlyPublisher = childPublisher is ModifiablePublisher modifiablePublisher ? modifiablePublisher.InnerPublisher : (ReadOnlyPublisher)childPublisher;
57+
58+
var publisherRole = new ReadOnlyPublisherRole { Role = role, InnerPublisher = readOnlyPublisher };
59+
4660
Logger.LogInformation($"Adding child publisher to collection");
47-
await publisher.ChildPublishers.AddPublisherAsync(childPublisher, cancellationToken);
61+
await publisher.ChildPublishers.AddPublisherAsync(publisherRole, cancellationToken);
4862

4963
Logger.LogInformation($"Publishing changes");
5064
await PublishAsync(publisher, cancellationToken);

src/Commands/Publisher/ChildPublishers/ChildPublishersCommand.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ public class ChildPublishersCommand : Command
1010
/// <summary>
1111
/// Initializes a new instance of the <see cref="ChildPublishersCommand"/> class.
1212
/// </summary>
13-
public ChildPublishersCommand(WacsdkCommandConfig config, Option<string> repoOption, Option<string> idOption, Option<string> publisherIdOption)
13+
public ChildPublishersCommand(WacsdkCommandConfig config, Option<string> repoOption, Option<string> idOption, Option<string> publisherIdOption, Option<string> roleIdOption, Option<string> roleNameOption, Option<string> roleDescriptionOption)
1414
: base("child-publishers", "Manages the child publishers of the Publisher.")
1515
{
1616
AddCommand(new GetChildPublishersCommand(config, repoOption, idOption));
17-
AddCommand(new AddChildPublisherCommand(config, repoOption, idOption, publisherIdOption));
17+
AddCommand(new AddChildPublisherCommand(config, repoOption, idOption, publisherIdOption, roleIdOption, roleNameOption, roleDescriptionOption));
1818
AddCommand(new RemoveChildPublisherCommand(config, repoOption, idOption, publisherIdOption));
1919
}
2020
}

src/Commands/Publisher/ChildPublishers/RemoveChildPublisherCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public async Task InvokeAsync(string repo, string id, string publisherId)
4040
Logger.LogInformation($"Got {nameof(publisher.Id)}: {publisher.Id}");
4141

4242
Logger.LogInformation($"Getting child publisher to remove");
43-
var childPublisher = await GetPublisherByIdAsync(repo, publisherId, cancellationToken);
43+
var childPublisher = await publisher.ChildPublishers.GetPublishersAsync(cancellationToken).FirstAsync(p => p.Id == publisherId, cancellationToken);
4444
Logger.LogInformation($"Got {nameof(childPublisher.Id)}: {childPublisher.Id}");
4545

4646
Logger.LogInformation($"Removing child publisher from collection");

src/Commands/Publisher/ParentPublishers/AddParentPublisherCommand.cs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,23 @@ public class AddParentPublisherCommand : Command
1515
/// <summary>
1616
/// Initializes a new instance of the <see cref="AddParentPublisherCommand"/> class.
1717
/// </summary>
18-
public AddParentPublisherCommand(WacsdkCommandConfig config, Option<string> repoOption, Option<string> idOption, Option<string> publisherIdOption)
18+
public AddParentPublisherCommand(WacsdkCommandConfig config, Option<string> repoOption, Option<string> idOption, Option<string> publisherIdOption, Option<string> roleIdOption, Option<string> roleNameOption, Option<string> roleDescriptionOption)
1919
: base("add", "Adds a parent publisher to the Publisher.")
2020
{
2121
AddOption(repoOption);
2222
AddOption(idOption);
2323
AddOption(publisherIdOption);
24+
AddOption(roleIdOption);
25+
AddOption(roleNameOption);
26+
AddOption(roleDescriptionOption);
2427

25-
this.SetHandler(InvokeAsync, repoOption, idOption, publisherIdOption);
28+
this.SetHandler(InvokeAsync, repoOption, idOption, publisherIdOption, roleIdOption, roleNameOption, roleDescriptionOption);
2629
this.Config = config;
2730
}
2831

2932
protected WacsdkCommandConfig Config { get; init; }
3033

31-
public async Task InvokeAsync(string repo, string id, string publisherId)
34+
public async Task InvokeAsync(string repo, string id, string publisherId, string roleId, string roleName, string roleDescription)
3235
{
3336
Guard.IsNotNullOrWhiteSpace(publisherId);
3437

@@ -40,11 +43,22 @@ public async Task InvokeAsync(string repo, string id, string publisherId)
4043
Logger.LogInformation($"Got {nameof(publisher.Id)}: {publisher.Id}");
4144

4245
Logger.LogInformation($"Getting parent publisher");
43-
var parentPublisher = await GetPublisherByIdAsync(repo, publisherId, cancellationToken);
44-
Logger.LogInformation($"Got {nameof(parentPublisher.Id)}: {parentPublisher.Id}");
46+
var childPublisher = await GetPublisherByIdAsync(repo, publisherId, cancellationToken);
47+
Logger.LogInformation($"Got {nameof(childPublisher.Id)}: {childPublisher.Id}");
48+
49+
var role = new Role
50+
{
51+
Id = roleId,
52+
Name = roleName,
53+
Description = roleDescription
54+
};
55+
56+
var readOnlyPublisher = childPublisher is ModifiablePublisher modifiablePublisher ? modifiablePublisher.InnerPublisher : (ReadOnlyPublisher)childPublisher;
57+
58+
var publisherRole = new ReadOnlyPublisherRole { Role = role, InnerPublisher = readOnlyPublisher };
4559

4660
Logger.LogInformation($"Adding parent publisher to collection");
47-
await publisher.ParentPublishers.AddPublisherAsync(parentPublisher, cancellationToken);
61+
await publisher.ParentPublishers.AddPublisherAsync(publisherRole, cancellationToken);
4862

4963
Logger.LogInformation($"Publishing changes");
5064
await PublishAsync(publisher, cancellationToken);

src/Commands/Publisher/ParentPublishers/ParentPublishersCommand.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ public class ParentPublishersCommand : Command
1010
/// <summary>
1111
/// Initializes a new instance of the <see cref="ParentPublishersCommand"/> class.
1212
/// </summary>
13-
public ParentPublishersCommand(WacsdkCommandConfig config, Option<string> repoOption, Option<string> idOption, Option<string> publisherIdOption)
13+
public ParentPublishersCommand(WacsdkCommandConfig config, Option<string> repoOption, Option<string> idOption, Option<string> publisherIdOption, Option<string> roleIdOption, Option<string> roleNameOption, Option<string> roleDescriptionOption)
1414
: base("parent-publishers", "Manages the parent publishers of the Publisher.")
1515
{
1616
AddCommand(new GetParentPublishersCommand(config, repoOption, idOption));
17-
AddCommand(new AddParentPublisherCommand(config, repoOption, idOption, publisherIdOption));
17+
AddCommand(new AddParentPublisherCommand(config, repoOption, idOption, publisherIdOption, roleIdOption, roleNameOption, roleDescriptionOption));
1818
AddCommand(new RemoveParentPublisherCommand(config, repoOption, idOption, publisherIdOption));
1919
}
2020
}

src/Commands/Publisher/ParentPublishers/RemoveParentPublisherCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public async Task InvokeAsync(string repo, string id, string publisherId)
4040
Logger.LogInformation($"Got {nameof(publisher.Id)}: {publisher.Id}");
4141

4242
Logger.LogInformation($"Getting parent publisher to remove");
43-
var parentPublisher = await GetPublisherByIdAsync(repo, publisherId, cancellationToken);
43+
var parentPublisher = await publisher.ParentPublishers.GetPublishersAsync(cancellationToken).FirstAsync(p => p.Id == publisherId, cancellationToken);
4444
Logger.LogInformation($"Got {nameof(parentPublisher.Id)}: {parentPublisher.Id}");
4545

4646
Logger.LogInformation($"Removing parent publisher from collection");

src/Commands/Publisher/WacsdkPublisherCommands.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ public WacsdkPublisherCommands(WacsdkCommandConfig config, Option<string> repoOp
7474

7575
// Add publisher-specific collection commands
7676
AddCommand(new ProjectsCommand(config, repoOption, publisherIdOption, projectIdOption));
77-
AddCommand(new ChildPublishersCommand(config, repoOption, parentPublisherIdOption, childPublisherIdOption));
78-
AddCommand(new ParentPublishersCommand(config, repoOption, childPublisherIdOption, parentPublisherIdOption));
77+
AddCommand(new ChildPublishersCommand(config, repoOption, parentPublisherIdOption, childPublisherIdOption, roleIdOption, roleNameOption, roleDescriptionOption));
78+
AddCommand(new ParentPublishersCommand(config, repoOption, childPublisherIdOption, parentPublisherIdOption, roleIdOption, roleNameOption, roleDescriptionOption));
7979
}
8080
}
8181
}

0 commit comments

Comments
 (0)