Skip to content

Commit

Permalink
Merge pull request #9 from BeniceSoft/dev/feat-v1.0.0
Browse files Browse the repository at this point in the history
merge 2024/05/05
  • Loading branch information
zengande authored May 5, 2024
2 parents 0dff8a9 + be59808 commit d722f0d
Show file tree
Hide file tree
Showing 14 changed files with 183 additions and 59 deletions.
18 changes: 6 additions & 12 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
name: Build & publish openauthing images

name: deploy openauthing
on:
push:
branches: [ "master" ]


env:
REGISTRY: ghcr.io

jobs:
build-and-push-image:
Expand All @@ -16,9 +11,9 @@ jobs:
matrix:
include:
- dockerfile: ./src/BeniceSoft.OpenAuthing.SSO/Dockerfile
image: ghcr.io/benicesoft/openauthing-sso
image: benicesoft/openauthing-sso
- dockerfile: ./src/BeniceSoft.OpenAuthing.AdminApi/Dockerfile
image: ghcr.io/benicesoft/openauthing-api
image: benicesoft/openauthing-api
permissions:
contents: read
packages: write
Expand All @@ -30,9 +25,8 @@ jobs:
- name: Log in to the Container registry
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GH_PACKAGE_TOKEN }}
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Extract metadata (tags, labels) for Docker
id: meta
Expand Down Expand Up @@ -72,7 +66,7 @@ jobs:
LAST_TAG="latest"
fi
echo "::set-output name=tag::$LAST_TAG"
- name: Deploy SSO
run: docker service update --image ${{ steps.last_tag.outputs.tag }} --update-parallelism 1 --update-delay 10s --with-registry-auth openauthing_sso

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using BeniceSoft.Abp.Core.Models;
using BeniceSoft.OpenAuthing.Commands.UserGroups;
using BeniceSoft.OpenAuthing.Dtos.UserGroups;
using BeniceSoft.OpenAuthing.Queries;
using Microsoft.AspNetCore.Mvc;
Expand All @@ -7,7 +8,7 @@
namespace BeniceSoft.OpenAuthing.Controllers;

/// <summary>
/// 用户组
/// User Groups
/// </summary>
public class UserGroupsController : AuthingApiControllerBase
{
Expand All @@ -19,7 +20,7 @@ public UserGroupsController(IUserGroupQueries userGroupQueries)
}

/// <summary>
/// 获取列表
/// List groups
/// </summary>
/// <param name="searchKey"></param>
/// <param name="pageIndex"></param>
Expand All @@ -39,7 +40,7 @@ public async Task<PagedResultDto<UserGroupPagedRes>> GetAsync(string? searchKey
}

/// <summary>
/// 详情
/// Get group details
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
Expand All @@ -49,4 +50,44 @@ public async Task<GetUserGroupRes> GetAsync(Guid id)
{
return await _userGroupQueries.GetDetailAsync(id);
}

/// <summary>
/// Create a group
/// </summary>
/// <param name="req"></param>
/// <returns></returns>
[HttpPost]
[ProducesResponseType<ResponseResult<Guid>>(StatusCodes.Status200OK)]
public async Task<Guid> CreateAsync([FromBody] InputUserGroupReq req)
{
var command = new CreateUserGroupCommand(req.Name, req.Description);
return await Mediator.Send(command);
}

/// <summary>
/// Update a group
/// </summary>
/// <param name="id"></param>
/// <param name="req"></param>
/// <returns></returns>
[HttpPut("{id}")]
[ProducesResponseType<ResponseResult<bool>>(StatusCodes.Status200OK)]
public async Task<bool> UpdateAsync(Guid id, [FromBody] InputUserGroupReq req)
{
var command = new UpdateUserGroupCommand(id, req.Name, req.Description);
return await Mediator.Send(command);
}

/// <summary>
/// Delete a group
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpDelete("{id}")]
[ProducesResponseType<ResponseResult<bool>>(StatusCodes.Status200OK)]
public async Task<bool> DeleteAsync(Guid id)
{
var command = new DeleteUserGroupCommand(id);
return await Mediator.Send(command);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace BeniceSoft.OpenAuthing.Dtos.UserGroups;

public class InputUserGroupReq
{
public string Name { get; set; }
public string Description { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using MediatR;

namespace BeniceSoft.OpenAuthing.Commands.UserGroups;

public class CreateUserGroupCommand : IRequest<Guid>
{
public string Name { get; private set; }
public string Description { get; private set; }

public CreateUserGroupCommand(string name, string description)
{
Name = name;
Description = description;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using BeniceSoft.OpenAuthing.Entities.UserGroups;
using MediatR;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.Guids;

namespace BeniceSoft.OpenAuthing.Commands.UserGroups;

public class CreateUserGroupCommandHandler(IGuidGenerator guid, IRepository<UserGroup> repository)
: IRequestHandler<CreateUserGroupCommand, Guid>, ITransientDependency
{
public async Task<Guid> Handle(CreateUserGroupCommand request, CancellationToken cancellationToken)
{
var userGroup = new UserGroup(guid.Create(), request.Name, request.Description);
await repository.InsertAsync(userGroup, cancellationToken: cancellationToken);

return userGroup.Id;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using MediatR;

namespace BeniceSoft.OpenAuthing.Commands.UserGroups;

public class DeleteUserGroupCommand : IRequest<bool>
{
public Guid Id { get; private set; }

public DeleteUserGroupCommand(Guid id)
{
Id = id;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using BeniceSoft.OpenAuthing.Entities.UserGroups;
using MediatR;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Repositories;

namespace BeniceSoft.OpenAuthing.Commands.UserGroups;

public class DeleteUserGroupCommandHandler(IRepository<UserGroup, Guid> groupRepository)
: IRequestHandler<DeleteUserGroupCommand, bool>, ITransientDependency
{
public async Task<bool> Handle(DeleteUserGroupCommand request, CancellationToken cancellationToken)
{
await groupRepository.DeleteAsync(request.Id, cancellationToken: cancellationToken);

return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using MediatR;

namespace BeniceSoft.OpenAuthing.Commands.UserGroups;

public class UpdateUserGroupCommand : IRequest<bool>
{
public Guid Id { get; private set; }
public string Name { get; private set; }
public string Description { get; private set; }

public UpdateUserGroupCommand(Guid id, string name, string description)
{
Id = id;
Name = name;
Description = description;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using BeniceSoft.OpenAuthing.Entities.UserGroups;
using MediatR;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Repositories;

namespace BeniceSoft.OpenAuthing.Commands.UserGroups;

public class UpdateUserGroupCommandHandler(IRepository<UserGroup, Guid> groupRepository)
: IRequestHandler<UpdateUserGroupCommand, bool>, ITransientDependency
{
public async Task<bool> Handle(UpdateUserGroupCommand request, CancellationToken cancellationToken)
{
var userGroup = await groupRepository.GetAsync(request.Id, includeDetails: false, cancellationToken: cancellationToken);
userGroup.Update(request.Name, request.Description);

await groupRepository.UpdateAsync(userGroup, cancellationToken: cancellationToken);

return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public static class HostingHostBuilderExtensions
public static IHostBuilder AddAppSettingsOverrideJson(
this IHostBuilder hostBuilder,
bool optional = true,
bool reloadOnChange = true,
bool reloadOnChange = false,
string path = AppSettingsSecretJsonPath)
{
return hostBuilder.ConfigureAppConfiguration((_, builder) =>
Expand Down
27 changes: 15 additions & 12 deletions src/BeniceSoft.OpenAuthing.Domain/Entities/UserGroups/UserGroup.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Volo.Abp.Domain.Entities.Auditing;
using Volo.Abp;
using Volo.Abp.Domain.Entities.Auditing;

namespace BeniceSoft.OpenAuthing.Entities.UserGroups;

Expand All @@ -8,27 +9,22 @@ namespace BeniceSoft.OpenAuthing.Entities.UserGroups;
public class UserGroup : FullAuditedAggregateRoot<Guid>
{
/// <summary>
/// 名称
/// Group name
/// </summary>
public string Name { get; private set; }

/// <summary>
/// 显示名称
/// </summary>
public string DisplayName { get; private set; }

/// <summary>
/// 描述
/// Description
/// </summary>
public string Description { get; private set; }

/// <summary>
/// 是否启用
/// Enabled
/// </summary>
public bool Enabled { get; private set; }

/// <summary>
/// 成员
/// Members
/// </summary>
public IReadOnlyCollection<UserGroupMember> Members => _members;

Expand All @@ -39,12 +35,19 @@ private UserGroup(Guid id) : base(id)
_members = new();
}

public UserGroup(Guid id, string name, string displayName, string description, bool enabled)
public UserGroup(Guid id, string name, string description, bool enabled = true)
: this(id)
{
Name = name;
DisplayName = displayName;
Description = description;
Enabled = enabled;
}

public void Update(string name, string description)
{
Check.NotNullOrWhiteSpace(name, nameof(name));

Name = name;
Description = description;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,10 @@ private static void ConfigureUserGroup(EntityTypeBuilder<UserGroup> builder)
builder.ToTable(AuthingDbProperties.DbTablePrefix + "UserGroups", x => x.HasComment("用户组"));
builder.ConfigureByConvention();
builder.HasKey(x => x.Id);
builder.Property(x => x.Name)
.IsRequired()
.HasMaxLength(200)
.HasComment("名称");
builder.Property(x => x.DisplayName)
.IsRequired()
.HasMaxLength(200)
.HasComment("显示名称");
builder.Property(x => x.Description)
.IsRequired()
.HasMaxLength(500)
.HasComment("描述");
builder.Property(x => x.Enabled)
.HasComment("是否启用");
builder.Property(x => x.Id).ValueGeneratedNever();
builder.Property(x => x.Name).IsRequired().HasMaxLength(200);
builder.Property(x => x.Description).IsRequired().HasMaxLength(500);
builder.Property(x => x.Enabled).HasDefaultValue(true);

builder.Metadata.FindNavigation(nameof(UserGroup.Members))?
.SetPropertyAccessMode(PropertyAccessMode.Field);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -732,18 +732,12 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.Property<string>("Description")
.IsRequired()
.HasMaxLength(500)
.HasColumnType("varchar(500)")
.HasComment("描述");
b.Property<string>("DisplayName")
.IsRequired()
.HasMaxLength(200)
.HasColumnType("varchar(200)")
.HasComment("显示名称");
.HasColumnType("varchar(500)");
b.Property<bool>("Enabled")
.ValueGeneratedOnAdd()
.HasColumnType("tinyint(1)")
.HasComment("是否启用");
.HasDefaultValue(true);
b.Property<string>("ExtraProperties")
.IsRequired()
Expand All @@ -767,8 +761,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(200)
.HasColumnType("varchar(200)")
.HasComment("名称");
.HasColumnType("varchar(200)");
b.HasKey("Id");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,10 @@ public async Task<IActionResult> Login([FromBody] LoginViewModel model)

if (result.Succeeded)
{
if (!Url.IsLocalUrl(model.ReturnUrl))
{
model.ReturnUrl = "/";
}

return Ok(new
{
LoginSuccess = true,
ReturnUrl = model.ReturnUrl ?? "/",
model.ReturnUrl,
UserInfo = user.ToViewModel()
}.ToSucceed());
}
Expand Down

0 comments on commit d722f0d

Please sign in to comment.