Skip to content

Commit f934793

Browse files
authored
Remove ASP.NET Authorization usage (#167)
1 parent e707ee1 commit f934793

20 files changed

Lines changed: 42 additions & 294 deletions

StartSch/AuthSchSetup.cs

Lines changed: 0 additions & 12 deletions
This file was deleted.

StartSch/Authorization/Handlers/EventAdminAccessHandler.cs

Lines changed: 0 additions & 32 deletions
This file was deleted.

StartSch/Authorization/Handlers/EventReadAccessHandler.cs

Lines changed: 0 additions & 17 deletions
This file was deleted.

StartSch/Authorization/Handlers/PostAdminAccessHandler.cs

Lines changed: 0 additions & 48 deletions
This file was deleted.

StartSch/Authorization/Handlers/PublishedPostAccessHandler.cs

Lines changed: 0 additions & 19 deletions
This file was deleted.

StartSch/Authorization/Requirements/AdminRequirement.cs

Lines changed: 0 additions & 9 deletions
This file was deleted.

StartSch/Authorization/Requirements/PageAdminRequirement.cs

Lines changed: 0 additions & 10 deletions
This file was deleted.

StartSch/Authorization/Requirements/ResourceAccessRequirement.cs

Lines changed: 0 additions & 15 deletions
This file was deleted.

StartSch/Components/Home.razor

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -100,19 +100,7 @@ else
100100
</a>
101101
</h3>
102102

103-
@if (opening.Id != 0)
104-
{
105-
<AuthorizeView Policy="Write" Resource="@opening">
106-
<div class="icon-buttons">
107-
<a title="Új poszt"
108-
href="/posts/0/edit?categories=@string.Join(',', opening.Categories.Select(g => g.Page.Id))&event=@opening.Id">
109-
<md-icon>
110-
chat_add_on
111-
</md-icon>
112-
</a>
113-
</div>
114-
</AuthorizeView>
115-
}
103+
<AdminButtonsForEvent Event="@opening" />
116104
</div>
117105

118106
<div style="display: flex; align-items: center; flex-wrap: wrap; gap: 8px">
@@ -210,6 +198,7 @@ else
210198
protected override async Task OnInitializedAsync()
211199
{
212200
Instant currentInstant = SystemClock.Instance.GetCurrentInstant();
201+
213202
await InterestService.LoadIndex;
214203

215204
await using var tx = await Db.BeginTransaction(IsolationLevel.Snapshot);
@@ -224,7 +213,7 @@ else
224213
}
225214

226215
IQueryable<Post> postsQuery = Db.Posts
227-
.Where(p => p.Published.HasValue)
216+
.WhereAnyoneCanRead(currentInstant)
228217
.OrderByDescending(p => p.Published)
229218
.ThenByDescending(p => p.Id);
230219
if (After != null)

StartSch/Components/Pages/PagePage.razor

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
@using StartSch.Services
33
@inherits ResourcePage<Page>
44
@inject Db Db
5-
@inject IAuthorizationService Auth
65
@inject InterestService InterestService
76
@inject AuthorizationService AuthorizationService
87

@@ -98,12 +97,11 @@
9897
@code {
9998
private Page? _page;
10099
private readonly List<object> _items = [];
100+
private readonly Instant currentInstant = SystemClock.Instance.GetCurrentInstant();
101101
[Parameter] public int PageId { get; set; }
102102

103103
protected override async Task OnInitializedAsync()
104104
{
105-
var isAdminTask = IsAdmin();
106-
107105
await InterestService.LoadIndex;
108106

109107
_page = await Db.Pages.FirstOrDefaultAsync(g => g.Id == PageId);
@@ -122,13 +120,10 @@
122120
var postIds = postsAndEvents.Where(x => x.PostId != 0).Select(x => x.PostId);
123121
var eventIds = postsAndEvents.Where(x => x.EventId != 0).Select(x => x.EventId);
124122

125-
var postsQuery = Db.Posts
123+
var posts = await Db.Posts
124+
.WhereUserCanRead(currentInstant, AuthorizationService)
126125
.Include(p => p.PostCategories)
127-
.Where(p => postIds.Contains(p.Id));
128-
if (!await isAdminTask)
129-
postsQuery = postsQuery
130-
.Where(p => p.Published.HasValue);
131-
var posts = await postsQuery
126+
.Where(p => postIds.Contains(p.Id))
132127
.Include(p => p.Event)
133128
.OrderBy(p => p.Published.HasValue) // drafts first
134129
.ThenByDescending(p => p.Published)
@@ -147,15 +142,6 @@
147142
_items.Sort((a, b) => GetDate(b).CompareTo(GetDate(a)));
148143
}
149144

150-
private async Task<bool> IsAdmin()
151-
{
152-
var adminAuthorization = await Auth.AuthorizeAsync(
153-
await User,
154-
_page,
155-
PageAdminRequirement.Instance);
156-
return adminAuthorization.Succeeded;
157-
}
158-
159145
private static Instant GetDate(object item) => item switch
160146
{
161147
Post post => post.Published ?? post.Created,

0 commit comments

Comments
 (0)