Dynamic User Roles
This commit is contained in:
21
Oqtane.Client/Services/Interfaces/IRoleService.cs
Normal file
21
Oqtane.Client/Services/Interfaces/IRoleService.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using Oqtane.Models;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Oqtane.Services
|
||||
{
|
||||
public interface IRoleService
|
||||
{
|
||||
Task<List<Role>> GetRolesAsync();
|
||||
|
||||
Task<List<Role>> GetRolesAsync(int SiteId);
|
||||
|
||||
Task<Role> GetRoleAsync(int RoleId);
|
||||
|
||||
Task<Role> AddRoleAsync(Role Role);
|
||||
|
||||
Task<Role> UpdateRoleAsync(Role Role);
|
||||
|
||||
Task DeleteRoleAsync(int RoleId);
|
||||
}
|
||||
}
|
16
Oqtane.Client/Services/Interfaces/IUserRoleService.cs
Normal file
16
Oqtane.Client/Services/Interfaces/IUserRoleService.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using Oqtane.Models;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Oqtane.Services
|
||||
{
|
||||
public interface IUserRoleService
|
||||
{
|
||||
Task<List<UserRole>> GetUserRolesAsync();
|
||||
Task<List<UserRole>> GetUserRolesAsync(int UserId);
|
||||
Task<UserRole> GetUserRoleAsync(int UserRoleId);
|
||||
Task<UserRole> AddUserRoleAsync(UserRole UserRole);
|
||||
Task<UserRole> UpdateUserRoleAsync(UserRole UserRole);
|
||||
Task DeleteUserRoleAsync(int UserRoleId);
|
||||
}
|
||||
}
|
@ -6,11 +6,11 @@ namespace Oqtane.Services
|
||||
{
|
||||
public interface IUserService
|
||||
{
|
||||
Task<List<User>> GetUsersAsync();
|
||||
Task<List<User>> GetUsersAsync(int SiteId);
|
||||
|
||||
Task<User> GetUserAsync(int UserId);
|
||||
Task<User> GetUserAsync(int UserId, int SiteId);
|
||||
|
||||
Task<User> GetUserAsync(string Username);
|
||||
Task<User> GetUserAsync(string Username, int SiteId);
|
||||
|
||||
Task<User> AddUserAsync(User User);
|
||||
|
||||
@ -18,8 +18,6 @@ namespace Oqtane.Services
|
||||
|
||||
Task DeleteUserAsync(int UserId);
|
||||
|
||||
Task<User> GetCurrentUserAsync();
|
||||
|
||||
Task<User> LoginUserAsync(User User);
|
||||
|
||||
Task LogoutUserAsync();
|
||||
|
60
Oqtane.Client/Services/RoleService.cs
Normal file
60
Oqtane.Client/Services/RoleService.cs
Normal file
@ -0,0 +1,60 @@
|
||||
using Oqtane.Models;
|
||||
using System.Threading.Tasks;
|
||||
using System.Net.Http;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using System.Collections.Generic;
|
||||
using Oqtane.Shared;
|
||||
|
||||
namespace Oqtane.Services
|
||||
{
|
||||
public class RoleService : ServiceBase, IRoleService
|
||||
{
|
||||
private readonly HttpClient http;
|
||||
private readonly SiteState sitestate;
|
||||
private readonly IUriHelper urihelper;
|
||||
|
||||
public RoleService(HttpClient http, SiteState sitestate, IUriHelper urihelper)
|
||||
{
|
||||
this.http = http;
|
||||
this.sitestate = sitestate;
|
||||
this.urihelper = urihelper;
|
||||
}
|
||||
|
||||
private string apiurl
|
||||
{
|
||||
get { return CreateApiUrl(sitestate.Alias, urihelper.GetAbsoluteUri(), "Role"); }
|
||||
}
|
||||
|
||||
public async Task<List<Role>> GetRolesAsync()
|
||||
{
|
||||
List<Role> Roles = await http.GetJsonAsync<List<Role>>(apiurl);
|
||||
return Roles.OrderBy(item => item.Name).ToList();
|
||||
}
|
||||
|
||||
public async Task<List<Role>> GetRolesAsync(int SiteId)
|
||||
{
|
||||
List<Role> Roles = await http.GetJsonAsync<List<Role>>(apiurl + "?siteid=" + SiteId.ToString());
|
||||
return Roles.OrderBy(item => item.Name).ToList();
|
||||
}
|
||||
|
||||
public async Task<Role> GetRoleAsync(int RoleId)
|
||||
{
|
||||
return await http.GetJsonAsync<Role>(apiurl + "/" + RoleId.ToString());
|
||||
}
|
||||
|
||||
public async Task<Role> AddRoleAsync(Role Role)
|
||||
{
|
||||
return await http.PostJsonAsync<Role>(apiurl, Role);
|
||||
}
|
||||
|
||||
public async Task<Role> UpdateRoleAsync(Role Role)
|
||||
{
|
||||
return await http.PutJsonAsync<Role>(apiurl + "/" + Role.SiteId.ToString(), Role);
|
||||
}
|
||||
public async Task DeleteRoleAsync(int RoleId)
|
||||
{
|
||||
await http.DeleteAsync(apiurl + "/" + RoleId.ToString());
|
||||
}
|
||||
}
|
||||
}
|
59
Oqtane.Client/Services/UserRoleService.cs
Normal file
59
Oqtane.Client/Services/UserRoleService.cs
Normal file
@ -0,0 +1,59 @@
|
||||
using Oqtane.Models;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Oqtane.Shared;
|
||||
|
||||
namespace Oqtane.Services
|
||||
{
|
||||
public class UserRoleService : ServiceBase, IUserRoleService
|
||||
{
|
||||
private readonly HttpClient http;
|
||||
private readonly SiteState sitestate;
|
||||
private readonly IUriHelper urihelper;
|
||||
|
||||
public UserRoleService(HttpClient http, SiteState sitestate, IUriHelper urihelper)
|
||||
{
|
||||
this.http = http;
|
||||
this.sitestate = sitestate;
|
||||
this.urihelper = urihelper;
|
||||
}
|
||||
|
||||
private string apiurl
|
||||
{
|
||||
get { return CreateApiUrl(sitestate.Alias, urihelper.GetAbsoluteUri(), "UserRole"); }
|
||||
}
|
||||
|
||||
public async Task<List<UserRole>> GetUserRolesAsync()
|
||||
{
|
||||
return await http.GetJsonAsync<List<UserRole>>(apiurl);
|
||||
}
|
||||
|
||||
public async Task<List<UserRole>> GetUserRolesAsync(int UserId)
|
||||
{
|
||||
return await http.GetJsonAsync<List<UserRole>>(apiurl + "?userid=" + UserId.ToString());
|
||||
}
|
||||
|
||||
public async Task<UserRole> GetUserRoleAsync(int UserRoleId)
|
||||
{
|
||||
return await http.GetJsonAsync<UserRole>(apiurl + "/" + UserRoleId.ToString());
|
||||
}
|
||||
|
||||
public async Task<UserRole> AddUserRoleAsync(UserRole UserRole)
|
||||
{
|
||||
return await http.PostJsonAsync<UserRole>(apiurl, UserRole);
|
||||
}
|
||||
|
||||
public async Task<UserRole> UpdateUserRoleAsync(UserRole UserRole)
|
||||
{
|
||||
return await http.PutJsonAsync<UserRole>(apiurl + "/" + UserRole.UserRoleId.ToString(), UserRole);
|
||||
}
|
||||
|
||||
public async Task DeleteUserRoleAsync(int UserRoleId)
|
||||
{
|
||||
await http.DeleteAsync(apiurl + "/" + UserRoleId.ToString());
|
||||
}
|
||||
}
|
||||
}
|
@ -27,20 +27,20 @@ namespace Oqtane.Services
|
||||
get { return CreateApiUrl(sitestate.Alias, urihelper.GetAbsoluteUri(), "User"); }
|
||||
}
|
||||
|
||||
public async Task<List<User>> GetUsersAsync()
|
||||
public async Task<List<User>> GetUsersAsync(int SiteId)
|
||||
{
|
||||
List<User> users = await http.GetJsonAsync<List<User>>(apiurl);
|
||||
List<User> users = await http.GetJsonAsync<List<User>>(apiurl + "?siteid=" + SiteId.ToString());
|
||||
return users.OrderBy(item => item.DisplayName).ToList();
|
||||
}
|
||||
|
||||
public async Task<User> GetUserAsync(int UserId)
|
||||
public async Task<User> GetUserAsync(int UserId, int SiteId)
|
||||
{
|
||||
return await http.GetJsonAsync<User>(apiurl + "/" + UserId.ToString());
|
||||
return await http.GetJsonAsync<User>(apiurl + "/" + UserId.ToString() + "?siteid=" + SiteId.ToString());
|
||||
}
|
||||
|
||||
public async Task<User> GetUserAsync(string Username)
|
||||
public async Task<User> GetUserAsync(string Username, int SiteId)
|
||||
{
|
||||
return await http.GetJsonAsync<User>(apiurl + "/name/" + Username);
|
||||
return await http.GetJsonAsync<User>(apiurl + "/name/" + Username + "?siteid=" + SiteId.ToString());
|
||||
}
|
||||
|
||||
public async Task<User> AddUserAsync(User User)
|
||||
@ -57,11 +57,6 @@ namespace Oqtane.Services
|
||||
await http.DeleteAsync(apiurl + "/" + UserId.ToString());
|
||||
}
|
||||
|
||||
public async Task<User> GetCurrentUserAsync()
|
||||
{
|
||||
return await http.GetJsonAsync<User>(apiurl + "/current");
|
||||
}
|
||||
|
||||
public async Task<User> LoginUserAsync(User User)
|
||||
{
|
||||
return await http.PostJsonAsync<User>(apiurl + "/login", User);
|
||||
@ -80,7 +75,7 @@ namespace Oqtane.Services
|
||||
|
||||
if (User != null)
|
||||
{
|
||||
//super user always has full access
|
||||
// super user always has full access
|
||||
isAllowed = User.IsSuperUser;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user