mirror of
https://github.com/bitwarden/server.git
synced 2025-01-22 21:51:22 +01:00
tool to promote admin user to org owner
This commit is contained in:
parent
57b246df20
commit
e69fc3620e
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Bit.Admin.Models;
|
||||
using Bit.Core;
|
||||
@ -16,13 +17,16 @@ namespace Bit.Admin.Controllers
|
||||
{
|
||||
private readonly GlobalSettings _globalSettings;
|
||||
private readonly ITransactionRepository _transactionRepository;
|
||||
private readonly IOrganizationUserRepository _organizationUserRepository;
|
||||
|
||||
public ToolsController(
|
||||
GlobalSettings globalSettings,
|
||||
ITransactionRepository transactionRepository)
|
||||
ITransactionRepository transactionRepository,
|
||||
IOrganizationUserRepository organizationUserRepository)
|
||||
{
|
||||
_globalSettings = globalSettings;
|
||||
_transactionRepository = transactionRepository;
|
||||
_organizationUserRepository = organizationUserRepository;
|
||||
}
|
||||
|
||||
public IActionResult ChargeBraintree()
|
||||
@ -137,5 +141,40 @@ namespace Bit.Admin.Controllers
|
||||
return RedirectToAction("Edit", "Organizations", new { id = model.OrganizationId });
|
||||
}
|
||||
}
|
||||
|
||||
public IActionResult PromoteAdmin()
|
||||
{
|
||||
return View("PromoteAdmin");
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> PromoteAdmin(PromoteAdminModel model)
|
||||
{
|
||||
if(!ModelState.IsValid)
|
||||
{
|
||||
return View("PromoteAdmin", model);
|
||||
}
|
||||
|
||||
var orgUsers = await _organizationUserRepository.GetManyByOrganizationAsync(
|
||||
model.OrganizationId.Value, null);
|
||||
var user = orgUsers.FirstOrDefault(u => u.UserId == model.UserId.Value);
|
||||
if(user == null)
|
||||
{
|
||||
ModelState.AddModelError(nameof(model.UserId), "User Id not found in this organization.");
|
||||
}
|
||||
else if(user.Type != Core.Enums.OrganizationUserType.Admin)
|
||||
{
|
||||
ModelState.AddModelError(nameof(model.UserId), "User is not an admin of this organization.");
|
||||
}
|
||||
|
||||
if(!ModelState.IsValid)
|
||||
{
|
||||
return View("PromoteAdmin", model);
|
||||
}
|
||||
|
||||
user.Type = Core.Enums.OrganizationUserType.Owner;
|
||||
await _organizationUserRepository.ReplaceAsync(user);
|
||||
return RedirectToAction("Edit", "Organizations", new { id = model.OrganizationId.Value });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
15
src/Admin/Models/PromoteAdminModel.cs
Normal file
15
src/Admin/Models/PromoteAdminModel.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Bit.Admin.Models
|
||||
{
|
||||
public class PromoteAdminModel
|
||||
{
|
||||
[Required]
|
||||
[Display(Name = "Admin User Id")]
|
||||
public Guid? UserId { get; set; }
|
||||
[Required]
|
||||
[Display(Name = "Organization Id")]
|
||||
public Guid? OrganizationId { get; set; }
|
||||
}
|
||||
}
|
@ -52,6 +52,9 @@
|
||||
<a class="dropdown-item" asp-controller="Tools" asp-action="CreateTransaction">
|
||||
Create Transaction
|
||||
</a>
|
||||
<a class="dropdown-item" asp-controller="Tools" asp-action="PromoteAdmin">
|
||||
Promote Admin
|
||||
</a>
|
||||
</div>
|
||||
</li>
|
||||
<li class="nav-item" active-controller="Logs">
|
||||
|
25
src/Admin/Views/Tools/PromoteAdmin.cshtml
Normal file
25
src/Admin/Views/Tools/PromoteAdmin.cshtml
Normal file
@ -0,0 +1,25 @@
|
||||
@model PromoteAdminModel
|
||||
@{
|
||||
ViewData["Title"] = "Promote Organization Admin";
|
||||
}
|
||||
|
||||
<h1>Promote Organization Admin</h1>
|
||||
|
||||
<form method="post">
|
||||
<div asp-validation-summary="All" class="alert alert-danger"></div>
|
||||
<div class="row">
|
||||
<div class="col-md">
|
||||
<div class="form-group">
|
||||
<label asp-for="UserId"></label>
|
||||
<input type="text" class="form-control" asp-for="UserId">
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md">
|
||||
<div class="form-group">
|
||||
<label asp-for="OrganizationId"></label>
|
||||
<input type="text" class="form-control" asp-for="OrganizationId">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary mb-2">Promote Admin</button>
|
||||
</form>
|
Loading…
Reference in New Issue
Block a user