forked from ServiceStack/ServiceStack
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/master'
- Loading branch information
Showing
53 changed files
with
1,621 additions
and
772 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
COPY ..\NuGet\ServiceStack\lib\* latest\ServiceStack | ||
COPY ..\NuGet\ServiceStack.Common\lib\* latest\ServiceStack | ||
|
||
COPY ..\..\ServiceStack.Text\NuGet\lib\* latest\ServiceStack | ||
COPY ..\..\ServiceStack.Redis\NuGet\lib\* latest\ServiceStack | ||
COPY ..\..\ServiceStack.OrmLite\NuGet\ServiceStack.OrmLite.SqlServer\lib\* latest\ServiceStack |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
src/ServiceStack.ServiceInterface/Auth/AssignRolesService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using ServiceStack.Common; | ||
using ServiceStack.Common.Web; | ||
using ServiceStack.ServiceInterface.ServiceModel; | ||
|
||
namespace ServiceStack.ServiceInterface.Auth | ||
{ | ||
public class AssignRoles | ||
{ | ||
public AssignRoles() | ||
{ | ||
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 AssignRolesResponse : IHasResponseStatus | ||
{ | ||
public AssignRolesResponse() | ||
{ | ||
this.AllRoles = new List<string>(); | ||
this.AllPermissions = new List<string>(); | ||
} | ||
|
||
public List<string> AllRoles { get; set; } | ||
|
||
public List<string> AllPermissions { get; set; } | ||
|
||
public ResponseStatus ResponseStatus { get; set; } | ||
} | ||
|
||
[RequiredRole(AuthFeature.AdminRole)] | ||
public class AssignRolesService : RestServiceBase<AssignRoles> | ||
{ | ||
public IUserAuthRepository UserAuthRepo { get; set; } | ||
|
||
public override object OnPost(AssignRoles request) | ||
{ | ||
request.UserName.ThrowIfNullOrEmpty(); | ||
|
||
var userAuth = UserAuthRepo.GetUserAuthByUserName(request.UserName); | ||
if (userAuth == null) | ||
throw HttpError.NotFound(request.UserName); | ||
|
||
if (!request.Roles.IsEmpty()) | ||
{ | ||
foreach (var missingRole in request.Roles.Where(x => !userAuth.Roles.Contains(x))) | ||
{ | ||
userAuth.Roles.Add(missingRole); | ||
} | ||
} | ||
if (!request.Permissions.IsEmpty()) | ||
{ | ||
foreach (var missingPermission in request.Permissions.Where(x => !userAuth.Permissions.Contains(x))) | ||
{ | ||
userAuth.Permissions.Add(missingPermission); | ||
} | ||
} | ||
|
||
UserAuthRepo.SaveUserAuth(userAuth); | ||
|
||
return new AssignRolesResponse { | ||
AllRoles = userAuth.Roles, | ||
AllPermissions = userAuth.Permissions, | ||
}; | ||
} | ||
} | ||
} |
Oops, something went wrong.