Skip to content

Commit

Permalink
Follow-up refactoring commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
impworks committed May 25, 2024
1 parent e4bcadb commit ae85e91
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 33 deletions.
12 changes: 6 additions & 6 deletions src/Bonsai/Areas/Admin/Controllers/ChangesetsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Bonsai.Areas.Admin.Controllers;
/// Controller for managing changesets.
/// </summary>
[Route("admin/changes")]
public class ChangesetsController(ChangesetsManagerService changes, AppDbContext db) : AdminControllerBase
public class ChangesetsController(ChangesetsManagerService changesSvc, AppDbContext db) : AdminControllerBase
{
protected override Type ListStateType => typeof(ChangesetsListRequestVM);

Expand All @@ -26,7 +26,7 @@ public class ChangesetsController(ChangesetsManagerService changes, AppDbContext
public async Task<ActionResult> Index(ChangesetsListRequestVM request)
{
PersistListState(request);
var vm = await changes.GetChangesetsAsync(request);
var vm = await changesSvc.GetChangesetsAsync(request);
return View(vm);
}

Expand All @@ -37,7 +37,7 @@ public async Task<ActionResult> Index(ChangesetsListRequestVM request)
[Route("details")]
public async Task<ActionResult> Details(Guid id)
{
var vm = await changes.GetChangesetDetailsAsync(id);
var vm = await changesSvc.GetChangesetDetailsAsync(id);
return View(vm);
}

Expand All @@ -48,7 +48,7 @@ public async Task<ActionResult> Details(Guid id)
[Route("revert")]
public async Task<ActionResult> Revert(Guid id)
{
var vm = await changes.GetChangesetDetailsAsync(id);
var vm = await changesSvc.GetChangesetDetailsAsync(id);
if (!vm.CanRevert)
throw new OperationException(Texts.Admin_Changesets_CannotRevertMessage);

Expand All @@ -62,11 +62,11 @@ public async Task<ActionResult> Revert(Guid id)
[Route("revert")]
public async Task<ActionResult> Revert(Guid id, bool confirm)
{
var editVm = await changes.GetChangesetDetailsAsync(id);
var editVm = await changesSvc.GetChangesetDetailsAsync(id);
if (!editVm.CanRevert)
throw new OperationException(Texts.Admin_Changesets_CannotRevertMessage);

await changes.RevertChangeAsync(id, User);
await changesSvc.RevertChangeAsync(id, User);
await db.SaveChangesAsync();

return RedirectToSuccess(Texts.Admin_Changesets_RevertedMessage);
Expand Down
20 changes: 10 additions & 10 deletions src/Bonsai/Areas/Admin/Controllers/PagesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace Bonsai.Areas.Admin.Controllers;
/// Controller for handling pages.
/// </summary>
[Route("admin/pages")]
public class PagesController(PagesManagerService pages, ISearchEngine search, AppDbContext db, IBackgroundJobService jobs)
public class PagesController(PagesManagerService pagesSvc, ISearchEngine search, AppDbContext db, IBackgroundJobService jobs)
: AdminControllerBase
{
protected override Type ListStateType => typeof(PagesListRequestVM);
Expand All @@ -53,7 +53,7 @@ public class PagesController(PagesManagerService pages, ISearchEngine search, Ap
public async Task<ActionResult> Index(PagesListRequestVM request)
{
PersistListState(request);
var vm = await pages.GetPagesAsync(request);
var vm = await pagesSvc.GetPagesAsync(request);
return View(vm);
}

Expand All @@ -64,7 +64,7 @@ public async Task<ActionResult> Index(PagesListRequestVM request)
[Route("create")]
public async Task<ActionResult> Create([FromQuery]PageType type = PageType.Person)
{
var vm = await pages.RequestCreateAsync(type, User);
var vm = await pagesSvc.RequestCreateAsync(type, User);
if (vm.Type != type)
{
TempData[NotificationsService.NOTE_PAGETYPE_RESET_FROM_DRAFT] = type;
Expand All @@ -86,7 +86,7 @@ public async Task<ActionResult> Create(PageEditorVM vm)

try
{
var page = await pages.CreateAsync(vm, User);
var page = await pagesSvc.CreateAsync(vm, User);
await db.SaveChangesAsync();
await search.AddPageAsync(page);
await jobs.RunAsync(JobBuilder.For<TreeLayoutJob>().SupersedeAll());
Expand All @@ -107,7 +107,7 @@ public async Task<ActionResult> Create(PageEditorVM vm)
[Route("update")]
public async Task<ActionResult> Update(Guid id)
{
var vm = await pages.RequestUpdateAsync(id, User);
var vm = await pagesSvc.RequestUpdateAsync(id, User);
return await ViewEditorFormAsync(vm, displayDraft: true);
}

Expand All @@ -123,7 +123,7 @@ public async Task<ActionResult> Update(PageEditorVM vm, string tab)

try
{
var page = await pages.UpdateAsync(vm, User);
var page = await pagesSvc.UpdateAsync(vm, User);
await db.SaveChangesAsync();
await search.AddPageAsync(page);
await jobs.RunAsync(JobBuilder.For<TreeLayoutJob>().SupersedeAll());
Expand All @@ -145,7 +145,7 @@ public async Task<ActionResult> Update(PageEditorVM vm, string tab)
[Route("remove")]
public async Task<ActionResult> Remove(Guid id)
{
ViewBag.Info = await pages.RequestRemoveAsync(id, User);
ViewBag.Info = await pagesSvc.RequestRemoveAsync(id, User);
return View(new RemoveEntryRequestVM { Id = id });
}

Expand All @@ -157,9 +157,9 @@ public async Task<ActionResult> Remove(Guid id)
public async Task<ActionResult> Remove(RemoveEntryRequestVM vm)
{
if (vm.RemoveCompletely)
await pages.RemoveCompletelyAsync(vm.Id, User);
await pagesSvc.RemoveCompletelyAsync(vm.Id, User);
else
await pages.RemoveAsync(vm.Id, User);
await pagesSvc.RemoveAsync(vm.Id, User);

await db.SaveChangesAsync();
await search.RemovePageAsync(vm.Id);
Expand Down Expand Up @@ -187,7 +187,7 @@ private async Task<ActionResult> ViewEditorFormAsync(PageEditorVM vm, string tab
.JoinString(", ");

var photoThumbUrl = await GetMainPhotoThumbnailUrlAsync(vm.MainPhotoKey);
var draft = await pages.GetPageDraftAsync(vm.Id, User);
var draft = await pagesSvc.GetPageDraftAsync(vm.Id, User);

ViewBag.Data = new PageEditorDataVM
{
Expand Down
34 changes: 17 additions & 17 deletions src/Bonsai/Areas/Admin/Controllers/UsersController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace Bonsai.Areas.Admin.Controllers;
/// Controller for managing users.
/// </summary>
[Route("admin/users")]
public class UsersController(UsersManagerService users, PagesManagerService pages, BonsaiConfigService config, ISearchEngine search, AppDbContext db)
public class UsersController(UsersManagerService usersSvc, PagesManagerService pagesSvc, BonsaiConfigService configSvc, ISearchEngine search, AppDbContext db)
: AdminControllerBase
{
protected override Type ListStateType => typeof(UsersListRequestVM);
Expand All @@ -35,9 +35,9 @@ public class UsersController(UsersManagerService users, PagesManagerService page
public async Task<ActionResult> Index([FromQuery] UsersListRequestVM request)
{
PersistListState(request);
var users1 = await users.GetUsersAsync(request);
ViewBag.AllowPasswordAuth = config.GetStaticConfig().Auth.AllowPasswordAuth;
return View(users1);
var users = await usersSvc.GetUsersAsync(request);
ViewBag.AllowPasswordAuth = configSvc.GetStaticConfig().Auth.AllowPasswordAuth;
return View(users);
}

/// <summary>
Expand All @@ -47,7 +47,7 @@ public async Task<ActionResult> Index([FromQuery] UsersListRequestVM request)
[Route("remove")]
public async Task<ActionResult> Remove(string id)
{
var vm = await users.RequestRemoveAsync(id, User);
var vm = await usersSvc.RequestRemoveAsync(id, User);
return View(vm);
}

Expand All @@ -58,7 +58,7 @@ public async Task<ActionResult> Remove(string id)
[Route("remove")]
public async Task<ActionResult> Remove(string id, bool confirm)
{
await users.RemoveAsync(id, User);
await usersSvc.RemoveAsync(id, User);
return RedirectToSuccess(Texts.Admin_Users_RemovedMessage);
}

Expand All @@ -69,7 +69,7 @@ public async Task<ActionResult> Remove(string id, bool confirm)
[Route("update")]
public async Task<ActionResult> Update(string id)
{
var vm = await users.RequestUpdateAsync(id);
var vm = await usersSvc.RequestUpdateAsync(id);
return await ViewUpdateFormAsync(vm);
}

Expand All @@ -85,16 +85,16 @@ public async Task<ActionResult> Update(UserEditorVM vm)

try
{
if (vm.CreatePersonalPage && await users.CanCreatePersonalPageAsync(vm))
if (vm.CreatePersonalPage && await usersSvc.CanCreatePersonalPageAsync(vm))
{
var page = await pages.CreateDefaultUserPageAsync(vm, User);
var page = await pagesSvc.CreateDefaultUserPageAsync(vm, User);
vm.PersonalPageId = page.Id;
vm.CreatePersonalPage = false;

await search.AddPageAsync(page);
}

await users.UpdateAsync(vm, User);
await usersSvc.UpdateAsync(vm, User);

await db.SaveChangesAsync();

Expand Down Expand Up @@ -135,14 +135,14 @@ public async Task<ActionResult> Create(UserCreatorVM vm)
{
if (vm.CreatePersonalPage)
{
var page = await pages.CreateDefaultUserPageAsync(vm, User);
var page = await pagesSvc.CreateDefaultUserPageAsync(vm, User);
vm.PersonalPageId = page.Id;
vm.CreatePersonalPage = false;

await search.AddPageAsync(page);
}

await users.CreateAsync(vm);
await usersSvc.CreateAsync(vm);
await db.SaveChangesAsync();

return RedirectToSuccess(Texts.Admin_Users_CreatedMessage);
Expand Down Expand Up @@ -177,7 +177,7 @@ public async Task<ActionResult> ResetPassword(UserPasswordEditorVM vm)

try
{
await users.ResetPasswordAsync(vm);
await usersSvc.ResetPasswordAsync(vm);
return RedirectToSuccess(Texts.Admin_Users_PasswordResetMessage);
}
catch (ValidationException ex)
Expand Down Expand Up @@ -211,7 +211,7 @@ private async Task<ActionResult> ViewCreateFormAsync(UserCreatorVM vm)
/// </summary>
private async Task<ActionResult> ViewResetPasswordFormAsync(string id)
{
ViewBag.Data = await users.GetAsync(id);
ViewBag.Data = await usersSvc.GetAsync(id);
return View("ResetPassword", new UserPasswordEditorVM { Id = id });
}

Expand All @@ -220,12 +220,12 @@ private async Task<ActionResult> ViewResetPasswordFormAsync(string id)
/// </summary>
private async Task<ActionResult> ViewUpdateFormAsync(UserEditorVM vm)
{
var canCreate = await users.CanCreatePersonalPageAsync(vm);
var canCreate = await usersSvc.CanCreatePersonalPageAsync(vm);
var pageItems = await GetPageItemsAsync(vm.PersonalPageId);

ViewBag.Data = new UserEditorDataVM
{
IsSelf = users.IsSelf(vm.Id, User),
IsSelf = usersSvc.IsSelf(vm.Id, User),
UserRoleItems = ViewHelper.GetEnumSelectList(vm.Role),
CanCreatePersonalPage = canCreate,
PageItems = pageItems
Expand Down Expand Up @@ -258,7 +258,7 @@ private async Task<IReadOnlyList<SelectListItem>> GetPageItemsAsync(Guid? pageId
/// </summary>
private void CheckPasswordAuth()
{
if (!config.GetStaticConfig().Auth.AllowPasswordAuth)
if (!configSvc.GetStaticConfig().Auth.AllowPasswordAuth)
throw new OperationException(Texts.Admin_Users_PasswordAuthRestrictedMessage);
}

Expand Down

0 comments on commit ae85e91

Please sign in to comment.