remove generics for API + controller and use base interfaces
This commit is contained in:
@@ -8,18 +8,16 @@ using zero.Web.Models;
|
||||
namespace zero.Web.Controllers
|
||||
{
|
||||
[ZeroAuthorize(Permissions.Settings.Users, PermissionsValue.Read)]
|
||||
public class UsersController<T, TLanguage> : BackofficeController
|
||||
where T : class, IUser
|
||||
where TLanguage : ILanguage
|
||||
public class UsersController : BackofficeController
|
||||
{
|
||||
IUserApi<T> Api;
|
||||
IUserApi Api;
|
||||
IAuthenticationApi AuthenticationApi;
|
||||
IUserRolesApi RolesApi;
|
||||
ILanguagesApi<TLanguage> LanguagesApi;
|
||||
ILanguagesApi LanguagesApi;
|
||||
IPermissionsApi PermissionsApi;
|
||||
|
||||
|
||||
public UsersController(IUserApi<T> api, IAuthenticationApi authenticationApi, IUserRolesApi rolesApi, ILanguagesApi<TLanguage> languagesApi, IPermissionsApi permissionsApi)
|
||||
public UsersController(IUserApi api, IAuthenticationApi authenticationApi, IUserRolesApi rolesApi, ILanguagesApi languagesApi, IPermissionsApi permissionsApi)
|
||||
{
|
||||
Api = api;
|
||||
AuthenticationApi = authenticationApi;
|
||||
@@ -35,7 +33,7 @@ namespace zero.Web.Controllers
|
||||
public IActionResult GetSupportedCultures() => Json(LanguagesApi.GetAllCultures(Options.SupportedLanguages));
|
||||
|
||||
|
||||
public async Task<IActionResult> GetAll([FromQuery] ListQuery<T> query) => Json(await Api.GetByQuery(query));
|
||||
public async Task<IActionResult> GetAll([FromQuery] ListQuery<IUser> query) => Json(await Api.GetByQuery(query));
|
||||
|
||||
|
||||
public IActionResult GetAllPermissions() => Json(PermissionsApi.GetAll());
|
||||
@@ -44,16 +42,16 @@ namespace zero.Web.Controllers
|
||||
[ZeroAuthorize]
|
||||
public async Task<IActionResult> UpdatePassword([FromBody] UserPasswordEditModel model)
|
||||
{
|
||||
EntityResult<T> result;
|
||||
EntityResult<IUser> result;
|
||||
|
||||
if (model.NewPassword != model.ConfirmNewPassword)
|
||||
{
|
||||
result = EntityResult<T>.Fail(nameof(model.NewPassword), "@errors.changepassword.newpasswordsnotmatching");
|
||||
result = EntityResult<IUser>.Fail(nameof(model.NewPassword), "@errors.changepassword.newpasswordsnotmatching");
|
||||
}
|
||||
else
|
||||
{
|
||||
User user = await AuthenticationApi.GetUser();
|
||||
result = await Api.UpdatePassword(user as T, model.CurrentPassword, model.NewPassword);
|
||||
result = await Api.UpdatePassword(user as IUser, model.CurrentPassword, model.NewPassword);
|
||||
|
||||
if (result.IsSuccess)
|
||||
{
|
||||
@@ -66,28 +64,28 @@ namespace zero.Web.Controllers
|
||||
|
||||
|
||||
[ZeroAuthorize(Permissions.Settings.Users, PermissionsValue.Update)]
|
||||
public async Task<IActionResult> Disable([FromBody] T model)
|
||||
public async Task<IActionResult> Disable([FromBody] IUser model)
|
||||
{
|
||||
T entity = await Api.GetUserById(model.Id);
|
||||
IUser entity = await Api.GetUserById(model.Id);
|
||||
return Json(await Api.Disable(entity));
|
||||
}
|
||||
|
||||
|
||||
[ZeroAuthorize(Permissions.Settings.Users, PermissionsValue.Update)]
|
||||
public async Task<IActionResult> Enable([FromBody] T model)
|
||||
public async Task<IActionResult> Enable([FromBody] IUser model)
|
||||
{
|
||||
T entity = await Api.GetUserById(model.Id);
|
||||
IUser entity = await Api.GetUserById(model.Id);
|
||||
return Json(await Api.Enable(entity));
|
||||
}
|
||||
|
||||
|
||||
[ZeroAuthorize(Permissions.Settings.Users, PermissionsValue.Update)]
|
||||
public async Task<IActionResult> Save([FromBody] T model) => Json(await Api.Save(model));
|
||||
public async Task<IActionResult> Save([FromBody] IUser model) => Json(await Api.Save(model));
|
||||
|
||||
|
||||
[ZeroAuthorize(Permissions.Settings.Users, PermissionsValue.Update)]
|
||||
// TODO do not need settings.users authorization for editing current user profiles
|
||||
public async Task<IActionResult> SaveCurrent([FromBody] T model) => Json(await Api.Save(model));
|
||||
public async Task<IActionResult> SaveCurrent([FromBody] IUser model) => Json(await Api.Save(model));
|
||||
|
||||
|
||||
[ZeroAuthorize(Permissions.Settings.Users, PermissionsValue.Update)]
|
||||
|
||||
Reference in New Issue
Block a user