Skip to content

Commit 3ccfb93

Browse files
committed
Make role id from as key in JSON store.
1 parent b5bd163 commit 3ccfb93

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/DynamicAuthorization.Mvc.JsonStore/Extensions/DynamicAuthorizationJsonBuilderExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ private static void AddRequiredServices(IServiceCollection services, JsonOptions
4646
jsonOptions.FilePath = Path.Combine(Directory, JsonOptions.DefaultRoleStoreName);
4747

4848
services.AddSingleton(jsonOptions);
49-
services.AddSingleton(provider => new DataStore(jsonOptions.FilePath, keyProperty: "id"));
49+
services.AddSingleton(provider => new DataStore(jsonOptions.FilePath, keyProperty: "roleId"));
5050
services.AddScoped<IRoleAccessStore, RoleAccessStore>();
5151
}
5252
}

src/DynamicAuthorization.Mvc.JsonStore/RoleAccessStore.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public RoleAccessStore(DataStore store)
1717

1818
public Task<bool> AddRoleAccessAsync(RoleAccess roleAccess)
1919
{
20-
roleAccess.Id = roleAccess.Id == 0 ? 1 : roleAccess.Id;
20+
//roleAccess.Id = roleAccess.Id == 0 ? 1 : roleAccess.Id;
2121
var collection = _store.GetCollection<RoleAccess>();
2222

2323
return collection.InsertOneAsync(roleAccess);
@@ -30,15 +30,15 @@ public Task<bool> EditRoleAccessAsync(RoleAccess roleAccess)
3030
if (access == null)
3131
return collection.InsertOneAsync(roleAccess);
3232

33-
roleAccess.Id = access.Id;
34-
return collection.ReplaceOneAsync(roleAccess.Id, roleAccess);
33+
//roleAccess.Id = access.Id;
34+
return collection.ReplaceOneAsync(roleAccess.RoleId, roleAccess);
3535
}
3636

3737
public Task<bool> RemoveRoleAccessAsync(string roleId)
3838
{
3939
var collection = _store.GetCollection<RoleAccess>();
4040

41-
return collection.DeleteOneAsync(roleId);
41+
return collection.DeleteOneAsync(r => r.RoleId == roleId);
4242
}
4343

4444
public Task<RoleAccess> GetRoleAccessAsync(string roleId)

0 commit comments

Comments
 (0)