-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create permission relationships page
- Loading branch information
Showing
8 changed files
with
220 additions
and
53 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
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
60 changes: 60 additions & 0 deletions
60
OryAdmin/Components/Pages/Permissions/Relationships/Create.razor
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,60 @@ | ||
@page "/permissions/relationships/{NamespaceName}/create" | ||
@attribute [StreamRendering] | ||
@attribute [RenderModeInteractiveServer] | ||
@inject ICustomTranslator Translator | ||
@inject ILogger<Home> Logger | ||
@inject NavigationManager Navigation | ||
|
||
<PageTitle>Create Relationship</PageTitle> | ||
|
||
<h1 class="title">Create Relationship</h1> | ||
<form @onsubmit="SubmitForm"> | ||
<div class="columns"> | ||
<div class="column field"> | ||
<label class="label"> | ||
Subject | ||
<div class="control"> | ||
<input type="text" class="input" id="subject" value="" | ||
@onchange="args => _subjectId = args.Value?.ToString()"/> | ||
</div> | ||
</label> | ||
</div> | ||
<div class="column is-narrow"> | ||
<p class="is-large">is</p> | ||
</div> | ||
<div class="column field"> | ||
<label class="label"> | ||
Relation | ||
<div class="control"> | ||
<input type="text" class="input" id="relation" value="" | ||
@onchange="args => _relation = args.Value?.ToString()"/> | ||
</div> | ||
</label> | ||
</div> | ||
<div class="column is-narrow"> | ||
<p class="is-large">of</p> | ||
</div> | ||
<div class="column field"> | ||
<label class="label"> | ||
Object | ||
<div class="control"> | ||
<input type="text" class="input" id="object" value="" | ||
@onchange="args => _object = args.Value?.ToString()"/> | ||
</div> | ||
</label> | ||
</div> | ||
</div> | ||
<div class="message is-warning p-2 @(string.IsNullOrWhiteSpace(_errorMessage) ? "is-hidden" : "")"> | ||
@_errorMessage | ||
</div> | ||
<div class="mt-5"> | ||
<div class="buttons"> | ||
<a class="button" href="permissions/relationships/@NamespaceName"> | ||
Cancel | ||
</a> | ||
<button type="submit" class="button is-success"> | ||
Save | ||
</button> | ||
</div> | ||
</div> | ||
</form> |
33 changes: 33 additions & 0 deletions
33
OryAdmin/Components/Pages/Permissions/Relationships/Create.razor.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,33 @@ | ||
using Microsoft.AspNetCore.Components; | ||
using Ory.Keto.Client.Model; | ||
using OryAdmin.Services; | ||
|
||
namespace OryAdmin.Components.Pages.Permissions.Relationships; | ||
|
||
public partial class Create | ||
{ | ||
private string? _errorMessage; | ||
private string? _object; | ||
private string? _relation; | ||
private string? _subjectId; | ||
|
||
[Inject] private ApiService ApiService { get; set; } = default!; | ||
[Parameter] public required string NamespaceName { get; set; } | ||
|
||
private async Task SubmitForm() | ||
{ | ||
Console.WriteLine("Submit Form"); | ||
var body = new KetoCreateRelationshipBody(subjectId: _subjectId, relation: _relation, _object: _object, | ||
_namespace: NamespaceName); | ||
try | ||
{ | ||
_ = await ApiService.KetoRelationshipWrite.CreateRelationshipAsync(body); | ||
} | ||
catch (Exception exception) | ||
{ | ||
_errorMessage = exception.Message; | ||
return; | ||
} | ||
Navigation.NavigateTo($"permissions/relationships/{NamespaceName}"); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
OryAdmin/Components/Pages/Permissions/Relationships/Index.razor
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,63 @@ | ||
@page "/permissions/relationships/{NamespaceName}" | ||
@attribute [StreamRendering] | ||
@attribute [RenderModeInteractiveServer] | ||
@inject ICustomTranslator Translator | ||
@inject ILogger<Home> Logger | ||
@inject NavigationManager Navigation | ||
|
||
<PageTitle>Relationships</PageTitle> | ||
|
||
<h1 class="title">Relationships for @NamespaceName</h1> | ||
<div class="buttons"> | ||
<a class="button is-dark" href="permissions">Back</a> | ||
<a class="button is-success" href="permissions/relationships/@NamespaceName/create">Create Relationship</a> | ||
</div> | ||
@if (_isLoading) | ||
{ | ||
// is loading | ||
<p>Loading data...</p> | ||
} | ||
else | ||
{ | ||
@if (_relationships == null) | ||
{ | ||
<div class="message is-danger p-2"> | ||
<p>List of relationships could not be loaded.</p> | ||
</div> | ||
} | ||
else | ||
{ | ||
if (_relationships.RelationTuples.Count == 0) | ||
{ | ||
<p>There are no relationships.</p> | ||
} | ||
else | ||
{ | ||
<table class="table is-fullwidth"> | ||
<thead> | ||
<th>Subject</th> | ||
<th></th> | ||
<th>Relation</th> | ||
<th></th> | ||
<th>Object</th> | ||
</thead> | ||
<tbody> | ||
@foreach (var relationship in _relationships.RelationTuples) | ||
{ | ||
<tr> | ||
<td>@(relationship.SubjectId ?? relationship.SubjectSet.ToJson())</td> | ||
<td> | ||
<p class="is-bold">is</p> | ||
</td> | ||
<td>@relationship.Relation</td> | ||
<td> | ||
<p class="is-bold">of</p> | ||
</td> | ||
<td>@relationship.Object</td> | ||
</tr> | ||
} | ||
</tbody> | ||
</table> | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
OryAdmin/Components/Pages/Permissions/Relationships/Index.razor.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 Microsoft.AspNetCore.Components; | ||
using Ory.Keto.Client.Model; | ||
using OryAdmin.Services; | ||
|
||
namespace OryAdmin.Components.Pages.Permissions.Relationships; | ||
|
||
public partial class Index | ||
{ | ||
private bool _isLoading = true; | ||
private KetoRelationships? _relationships; | ||
[Parameter] public required string NamespaceName { get; set; } | ||
|
||
[Inject] private ApiService ApiService { get; set; } = default!; | ||
|
||
protected override async Task OnInitializedAsync() | ||
{ | ||
try | ||
{ | ||
_relationships = await ApiService.KetoRelationshipRead.GetRelationshipsAsync(_namespace: NamespaceName); | ||
} | ||
catch (Exception) | ||
{ | ||
// ignored | ||
} | ||
|
||
_isLoading = false; | ||
} | ||
} |
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