forked from ServiceStack/ServiceStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUnAssignRolesService.cs
More file actions
68 lines (54 loc) · 1.93 KB
/
UnAssignRolesService.cs
File metadata and controls
68 lines (54 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using System.Collections.Generic;
using ServiceStack.Common;
using ServiceStack.Common.Web;
using ServiceStack.OrmLite;
using ServiceStack.ServiceInterface.ServiceModel;
namespace ServiceStack.ServiceInterface.Auth
{
public class UnAssignRoles
{
public UnAssignRoles()
{
this.Roles = new List<string>();
this.Permissions = new List<string>();
}
public string UserName { get; set; }
public List<string> Permissions { get; set; }
public List<string> Roles { get; set; }
}
public class UnAssignRolesResponse : IHasResponseStatus
{
public UnAssignRolesResponse()
{
this.AllRoles = new List<string>();
}
public List<string> AllRoles { get; set; }
public List<string> AllPermissions { get; set; }
public ResponseStatus ResponseStatus { get; set; }
}
[RequiredRole(RoleNames.Admin)]
public class UnAssignRolesService : RestServiceBase<UnAssignRoles>
{
public IUserAuthRepository UserAuthRepo { get; set; }
public override object OnPost(UnAssignRoles request)
{
request.UserName.ThrowIfNullOrEmpty();
var userAuth = UserAuthRepo.GetUserAuthByUserName(request.UserName);
if (userAuth == null)
throw HttpError.NotFound(request.UserName);
if (!request.Roles.IsEmpty())
{
request.Roles.ForEach(x => userAuth.Roles.Remove(x));
}
if (!request.Permissions.IsEmpty())
{
request.Permissions.ForEach(x => userAuth.Permissions.Remove(x));
}
UserAuthRepo.SaveUserAuth(userAuth);
return new UnAssignRolesResponse {
AllRoles = userAuth.Roles,
AllPermissions = userAuth.Permissions,
};
}
}
}