Skip to content

Commit a203a89

Browse files
author
agile.zhou
committed
Permission control almost done
1 parent 4935a8d commit a203a89

File tree

25 files changed

+192
-313
lines changed

25 files changed

+192
-313
lines changed

src/AgileConfig.Server.Apisite/AgileConfig.Server.Apisite.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,9 @@
182182
关联的app
183183
</summary>
184184
</member>
185-
<member name="P:AgileConfig.Server.Apisite.Controllers.api.Models.ApiAppVM.AppAdmin">
185+
<member name="P:AgileConfig.Server.Apisite.Controllers.api.Models.ApiAppVM.Creator">
186186
<summary>
187-
管理员
187+
创建者
188188
</summary>
189189
</member>
190190
<member name="P:AgileConfig.Server.Apisite.Controllers.api.Models.ApiConfigVM.Id">
@@ -513,4 +513,4 @@
513513
<returns></returns>
514514
</member>
515515
</members>
516-
</doc>
516+
</doc>

src/AgileConfig.Server.Apisite/Controllers/AppController.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ private async Task AppendInheritancedInfo(List<AppListVM> list)
9393
appListVm.inheritancedAppNames = appListVm.Inheritanced
9494
? new List<string>()
9595
: inheritancedApps.Select(ia => ia.Name).ToList();
96-
appListVm.AppAdminName = (await _userService.GetUserAsync(appListVm.AppAdmin))?.UserName;
9796
if (appListVm.children != null) await AppendInheritancedInfo(appListVm.children);
9897
}
9998
}
@@ -114,6 +113,8 @@ public async Task<IActionResult> Add([FromBody] AppVM model)
114113

115114
var app = model.ToApp();
116115
app.CreateTime = DateTime.Now;
116+
var creatorId = await this.GetCurrentUserId(_userService);
117+
if (!string.IsNullOrWhiteSpace(creatorId)) app.Creator = creatorId;
117118

118119
var inheritanceApps = new List<AppInheritanced>();
119120
if (!model.Inheritanced && model.inheritancedApps != null)
@@ -345,4 +346,4 @@ public async Task<IActionResult> GetAppGroups()
345346
data = groups.OrderBy(x => x)
346347
});
347348
}
348-
}
349+
}

src/AgileConfig.Server.Apisite/Controllers/RoleController.cs

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,33 +17,6 @@ namespace AgileConfig.Server.Apisite.Controllers;
1717
[Authorize]
1818
public class RoleController : Controller
1919
{
20-
private static readonly IReadOnlyList<string> SupportedFunctions = new List<string>
21-
{
22-
Functions.App_Add,
23-
Functions.App_Edit,
24-
Functions.App_Delete,
25-
Functions.App_Auth,
26-
27-
Functions.Config_Add,
28-
Functions.Config_Edit,
29-
Functions.Config_Delete,
30-
Functions.Config_Publish,
31-
Functions.Config_Offline,
32-
33-
Functions.Node_Add,
34-
Functions.Node_Delete,
35-
36-
Functions.Client_Disconnect,
37-
38-
Functions.User_Add,
39-
Functions.User_Edit,
40-
Functions.User_Delete,
41-
42-
Functions.Role_Add,
43-
Functions.Role_Edit,
44-
Functions.Role_Delete
45-
};
46-
4720
private readonly IRoleFunctionRepository _roleFunctionRepository;
4821
private readonly IRoleService _roleService;
4922

@@ -79,7 +52,7 @@ public IActionResult SupportedPermissions()
7952
return Json(new
8053
{
8154
success = true,
82-
data = SupportedFunctions
55+
data = Functions.GetAllPermissions()
8356
});
8457
}
8558

src/AgileConfig.Server.Apisite/Controllers/api/Models/ApiAppVM.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@ public class ApiAppVM : IAppModel
3030
/// </summary>
3131
public List<string> InheritancedApps { get; set; }
3232

33-
/// <summary>
34-
/// Administrator of the application.
35-
/// </summary>
36-
public string AppAdmin { get; set; }
37-
3833
/// <summary>
3934
/// id
4035
/// </summary>
@@ -47,6 +42,8 @@ public class ApiAppVM : IAppModel
4742

4843
public string Group { get; set; }
4944

45+
public string Creator { get; set; }
46+
5047
public DateTime CreateTime { get; set; }
5148
}
5249

@@ -61,10 +58,10 @@ public static AppVM ToAppVM(this ApiAppVM vm)
6158
Id = vm.Id,
6259
Name = vm.Name,
6360
Secret = vm.Secret,
64-
AppAdmin = vm.AppAdmin,
6561
Inheritanced = vm.Inheritanced,
62+
Creator = vm.Creator,
6663
Group = vm.Group,
6764
Enabled = vm.Enabled.GetValueOrDefault()
6865
};
6966
}
70-
}
67+
}

src/AgileConfig.Server.Apisite/Filters/PermissionCheckAttribute.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,11 @@ public override async Task OnActionExecutionAsync(ActionExecutingContext context
235235
}
236236

237237
var appId = "";
238-
if (GetAppIdParamFuncs.TryGetValue(_actionName, out var func))
238+
var isAppAction = _actionName.StartsWith("App.");
239+
if (!isAppAction && GetAppIdParamFuncs.TryGetValue(_actionName, out var func))
239240
appId = func(context, _permissionService, _configService);
240241

241-
if (!string.IsNullOrEmpty(appId))
242+
if (!isAppAction && !string.IsNullOrEmpty(appId))
242243
{
243244
matchKey = string.Format(AppMatchPatten, appId, _functionKey);
244245
if (userFunctions.Contains(matchKey))
@@ -253,4 +254,4 @@ public override async Task OnActionExecutionAsync(ActionExecutingContext context
253254
context.Result = new ContentResult();
254255
await base.OnActionExecutionAsync(context, next);
255256
}
256-
}
257+
}

src/AgileConfig.Server.Apisite/Models/AppVM.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ public class AppVM : IAppModel
2020

2121
public List<string> inheritancedAppNames { get; set; }
2222

23-
public string AppAdmin { get; set; }
24-
25-
public string AppAdminName { get; set; }
23+
public string Creator { get; set; }
2624

2725
[Required(ErrorMessage = "应用Id不能为空")]
2826
[MaxLength(36, ErrorMessage = "应用Id长度不能超过36位")]
@@ -58,9 +56,9 @@ public static App ToApp(this AppVM vm)
5856
app.Secret = vm.Secret;
5957
app.Enabled = vm.Enabled;
6058
app.Type = vm.Inheritanced ? AppType.Inheritance : AppType.PRIVATE;
61-
app.AppAdmin = vm.AppAdmin;
6259
app.Group = vm.Group;
6360
app.CreateTime = vm.CreateTime;
61+
app.Creator = vm.Creator;
6462

6563
return app;
6664
}
@@ -74,9 +72,9 @@ public static App ToApp(this AppVM vm, App app)
7472
app.Secret = vm.Secret;
7573
app.Enabled = vm.Enabled;
7674
app.Type = vm.Inheritanced ? AppType.Inheritance : AppType.PRIVATE;
77-
app.AppAdmin = vm.AppAdmin;
7875
app.Group = vm.Group;
7976
if (vm.CreateTime > DateTime.MinValue) app.CreateTime = vm.CreateTime;
77+
if (!string.IsNullOrWhiteSpace(vm.Creator)) app.Creator = vm.Creator;
8078

8179
return app;
8280
}
@@ -93,9 +91,9 @@ public static ApiAppVM ToApiAppVM(this AppVM vm)
9391
Inheritanced = vm.Inheritanced,
9492
Enabled = vm.Enabled,
9593
InheritancedApps = vm.inheritancedApps,
96-
AppAdmin = vm.AppAdmin,
9794
Group = vm.Group,
95+
Creator = vm.Creator,
9896
CreateTime = vm.CreateTime
9997
};
10098
}
101-
}
99+
}

src/AgileConfig.Server.Apisite/Models/Mapping/ModelMappingExtension.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public static AppVM ToAppVM(this App app)
2222
Secret = app.Secret,
2323
Enabled = app.Enabled,
2424
Inheritanced = app.Type == AppType.Inheritance,
25-
AppAdmin = app.AppAdmin,
25+
Creator = app.Creator,
2626
CreateTime = app.CreateTime
2727
};
2828

@@ -43,7 +43,7 @@ public static AppListVM ToAppListVM(this App app)
4343
Enabled = app.Enabled,
4444
UpdateTime = app.UpdateTime,
4545
CreateTime = app.CreateTime,
46-
AppAdmin = app.AppAdmin
46+
Creator = app.Creator
4747
};
4848

4949
return vm;
@@ -60,8 +60,8 @@ public static ApiAppVM ToApiAppVM(this App vm)
6060
Secret = vm.Secret,
6161
Inheritanced = vm.Type == AppType.Inheritance,
6262
Enabled = vm.Enabled,
63-
AppAdmin = vm.AppAdmin,
6463
Group = vm.Group,
64+
Creator = vm.Creator,
6565
CreateTime = vm.CreateTime
6666
};
6767
}
@@ -150,4 +150,4 @@ public static ApiConfigVM ToApiConfigVM(this Config config)
150150

151151
return vm;
152152
}
153-
}
153+
}

src/AgileConfig.Server.Data.Entity/App.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ public interface IAppModel
1313

1414
string Group { get; set; }
1515

16+
string Creator { get; set; }
17+
1618
DateTime CreateTime { get; set; }
1719
}
1820

@@ -37,9 +39,6 @@ public class App : IAppModel, IEntity<string>
3739

3840
[Column(Name = "type")] public AppType Type { get; set; }
3941

40-
[Column(Name = "app_admin", StringLength = 36)]
41-
public string AppAdmin { get; set; }
42-
4342
[Column(Name = "id", StringLength = 36)]
4443
public string Id { get; set; }
4544

@@ -49,7 +48,10 @@ public class App : IAppModel, IEntity<string>
4948
[Column(Name = "group", StringLength = 50)]
5049
public string Group { get; set; }
5150

51+
[Column(Name = "creator", StringLength = 36)]
52+
public string Creator { get; set; }
53+
5254
[Column(Name = "create_time")]
5355
[BsonDateTimeOptions(Kind = DateTimeKind.Local)]
5456
public DateTime CreateTime { get; set; }
55-
}
57+
}

src/AgileConfig.Server.Data.Freesql/EnsureTables.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,11 @@ public static void Ensure(IFreeSql instance)
6464
{
6565
if (!ExistTable(instance))
6666
{
67-
if (instance.Ado.DataType == DataType.Oracle) instance.CodeFirst.IsSyncStructureToUpper = true;
68-
6967
try
7068
{
69+
if (instance.Ado.DataType == DataType.Oracle)
70+
instance.CodeFirst.IsSyncStructureToUpper = true;
71+
7172
instance.CodeFirst.SyncStructure<App>();
7273
instance.CodeFirst.SyncStructure<Config>();
7374
instance.CodeFirst.SyncStructure<ServerNode>();
@@ -92,4 +93,4 @@ public static void Ensure(IFreeSql instance)
9293
}
9394
}
9495
}
95-
}
96+
}

src/AgileConfig.Server.Data.Repository.Freesql/SysInitRepository.cs

Lines changed: 5 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public bool InitDefaultApp(string appName)
9797
CreateTime = DateTime.Now,
9898
Enabled = true,
9999
Type = AppType.PRIVATE,
100-
AppAdmin = SystemSettings.SuperAdminId
100+
Creator = SystemSettings.SuperAdminId
101101
}).ExecuteAffrows();
102102

103103
return true;
@@ -106,7 +106,7 @@ public bool InitDefaultApp(string appName)
106106
private static void EnsureSystemRoles(IFreeSql sql)
107107
{
108108
// Super Admin gets all permissions
109-
var superAdminPermissions = GetSuperAdminPermissions();
109+
var superAdminPermissions = Functions.GetAllPermissions();
110110
EnsureRole(sql, SystemRoleConstants.SuperAdminId, "Super Administrator", superAdminPermissions);
111111
EnsureRolePermissions(sql, SystemRoleConstants.SuperAdminId, superAdminPermissions);
112112

@@ -121,61 +121,11 @@ private static void EnsureSystemRoles(IFreeSql sql)
121121
EnsureRolePermissions(sql, SystemRoleConstants.OperatorId, operatorPermissions);
122122
}
123123

124-
private static List<string> GetSuperAdminPermissions()
125-
{
126-
// SuperAdmin has all permissions
127-
return new List<string>
128-
{
129-
// Application permissions
130-
Functions.App_Read,
131-
Functions.App_Add,
132-
Functions.App_Edit,
133-
Functions.App_Delete,
134-
Functions.App_Auth,
135-
136-
// Configuration permissions
137-
Functions.Confing_Read,
138-
Functions.Config_Add,
139-
Functions.Config_Edit,
140-
Functions.Config_Delete,
141-
Functions.Config_Publish,
142-
Functions.Config_Offline,
143-
144-
// Node permissions
145-
Functions.Node_Read,
146-
Functions.Node_Add,
147-
Functions.Node_Delete,
148-
149-
// Client permissions
150-
Functions.Client_Refresh,
151-
Functions.Client_Disconnect,
152-
153-
// User permissions
154-
Functions.User_Read,
155-
Functions.User_Add,
156-
Functions.User_Edit,
157-
Functions.User_Delete,
158-
159-
// Role permissions
160-
Functions.Role_Read,
161-
Functions.Role_Add,
162-
Functions.Role_Edit,
163-
Functions.Role_Delete,
164-
165-
// Service permissions
166-
Functions.Service_Read,
167-
Functions.Service_Add,
168-
Functions.Service_Delete,
169-
170-
// System permissions
171-
Functions.Log_Read
172-
};
173-
}
174124

175125
private static List<string> GetAdminPermissions()
176126
{
177127
// Administrator has all permissions same as SuperAdmin
178-
return GetSuperAdminPermissions();
128+
return Functions.GetAllPermissions();
179129
}
180130

181131
private static List<string> GetOperatorPermissions()
@@ -191,7 +141,7 @@ private static List<string> GetOperatorPermissions()
191141
Functions.App_Auth,
192142

193143
// All Configuration permissions
194-
Functions.Confing_Read,
144+
Functions.Config_Read,
195145
Functions.Config_Add,
196146
Functions.Config_Edit,
197147
Functions.Config_Delete,
@@ -268,4 +218,4 @@ private static void EnsureRolePermissions(IFreeSql sql, string roleId, List<stri
268218
.Where(rf => roleFunctionsToRemove.Select(r => r.Id).Contains(rf.Id))
269219
.ExecuteAffrows();
270220
}
271-
}
221+
}

0 commit comments

Comments
 (0)