Skip to content

Commit

Permalink
Migrate User API (#1427)
Browse files Browse the repository at this point in the history
  • Loading branch information
tschumpr authored Aug 6, 2024
2 parents 3629711 + 3dea24c commit cc249e6
Show file tree
Hide file tree
Showing 24 changed files with 423 additions and 380 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
- Upgraded to PostgreSQL 15 and PostGIS 3.4.
- Removed unused `IsViewer` flag from user.
- Removed unused `UserEvent` from user.
- Migrated `User` API endpoints to .NET API.

### Fixed

Expand Down
1 change: 0 additions & 1 deletion src/api-legacy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@

# User actions
from bms.v1.user.handler import UserHandler
from bms.v1.user.admin import AdminHandler

# Workgroup actions
from bms.v1.user.workgrpup.admin import WorkgroupAdminHandler
Expand Down
2 changes: 0 additions & 2 deletions src/api-legacy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ async def close(application):
# user handlers
SettingHandler,
UserHandler,
AdminHandler,
WorkgroupAdminHandler,

# Borehole handlers
Expand Down Expand Up @@ -132,7 +131,6 @@ async def close(application):

# User handlers
(r'/api/v1/user', UserHandler),
(r'/api/v1/user/edit', AdminHandler),

(r'/api/v1/user/workgroup/edit', WorkgroupAdminHandler),

Expand Down
6 changes: 0 additions & 6 deletions src/api-legacy/v1/user/__init__.py

This file was deleted.

74 changes: 0 additions & 74 deletions src/api-legacy/v1/user/admin.py

This file was deleted.

115 changes: 0 additions & 115 deletions src/api-legacy/v1/user/delete.py

This file was deleted.

23 changes: 0 additions & 23 deletions src/api-legacy/v1/user/disable.py

This file was deleted.

23 changes: 0 additions & 23 deletions src/api-legacy/v1/user/enable.py

This file was deleted.

2 changes: 1 addition & 1 deletion src/api-legacy/v1/user/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ async def execute(self, request):
action = request.pop('action', None)

if action in [
'GET', 'RELOAD'
'GET'
]:

workgroups = []
Expand Down
28 changes: 0 additions & 28 deletions src/api-legacy/v1/user/update.py

This file was deleted.

6 changes: 6 additions & 0 deletions src/api/BdmsContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ public class BdmsContext : DbContext
public DbSet<Stratigraphy> Stratigraphies { get; set; }
public DbSet<Term> Terms { get; set; }
public DbSet<User> Users { get; set; }
public IQueryable<User> UsersWithIncludes => Users
.Include(u => u.WorkgroupRoles)
.ThenInclude(wr => wr.Workgroup)
.Include(u => u.TermsAccepted)
.ThenInclude(ta => ta.Term);
public DbSet<UserWorkgroupRole> UserWorkgroupRoles { get; set; }
public DbSet<Workflow> Workflows { get; set; }
public DbSet<Workgroup> Workgroups { get; set; }
Expand Down Expand Up @@ -88,6 +93,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.HasDefaultSchema("bdms");
modelBuilder.Entity<UserWorkgroupRole>().HasKey(k => new { k.UserId, k.WorkgroupId, k.Role });
modelBuilder.Entity<TermsAccepted>().HasKey(k => new { k.UserId, k.TermId });

modelBuilder.Entity<Borehole>()
.HasMany(b => b.Files)
Expand Down
2 changes: 1 addition & 1 deletion src/api/BoreholeLockService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public async Task<bool> IsBoreholeLockedAsync(int? boreholeId, string? subjectId
.Select(w => w.Role)
.ToHashSet();

if (!user.WorkgroupRoles.Any(x => x.WorkgroupId == borehole.WorkgroupId && boreholeWorkflowRoles.Contains(x.Role)))
if (user.WorkgroupRoles == null || !user.WorkgroupRoles.Any(x => x.WorkgroupId == borehole.WorkgroupId && boreholeWorkflowRoles.Contains(x.Role)))
{
logger.LogWarning("Current user with subject_id <{SubjectId}> does not have the required role to edit the borehole with id <{BoreholeId}>.", subjectId, boreholeId);
return true;
Expand Down
2 changes: 1 addition & 1 deletion src/api/Controllers/BoreholeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public async Task<ActionResult<int>> CopyAsync([Required] int id, [Required] int
.SingleOrDefaultAsync(u => u.SubjectId == HttpContext.GetUserSubjectId())
.ConfigureAwait(false);

if (user == null || !user.WorkgroupRoles.Any(w => w.WorkgroupId == workgroupId && w.Role == Role.Editor))
if (user == null || user.WorkgroupRoles == null || !user.WorkgroupRoles.Any(w => w.WorkgroupId == workgroupId && w.Role == Role.Editor))
{
return Unauthorized();
}
Expand Down
Loading

0 comments on commit cc249e6

Please sign in to comment.