Skip to content
This repository was archived by the owner on Jan 16, 2020. It is now read-only.

Commit 85d1c97

Browse files
committed
Rename PermissionEntity to PermissionActor
1 parent a40b7d4 commit 85d1c97

20 files changed

Lines changed: 178 additions & 96 deletions

Rocket.API/Permissions/IPermissionChecker.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public interface IPermissionChecker: IProxyableService
1010
/// </summary>
1111
/// <param name="target">The target to check.</param>
1212
/// <returns><b>true</b> if the given target is supported; otherwise, <b>false</b>.</returns>
13-
bool SupportsTarget(IPermissionEntity target);
13+
bool SupportsTarget(IPermissionActor target);
1414

1515
/// <summary>
1616
/// Check if the target has the given permission.
@@ -22,6 +22,6 @@ public interface IPermissionChecker: IProxyableService
2222
/// <see cref="PermissionResult.Deny" /> if the target explicitly does not have the permission; otherwise,
2323
/// <see cref="PermissionResult.Default" />
2424
/// </returns>
25-
Task<PermissionResult> CheckPermissionAsync(IPermissionEntity target, string permission);
25+
Task<PermissionResult> CheckPermissionAsync(IPermissionActor target, string permission);
2626
}
2727
}

Rocket.API/Permissions/IPermissionEntity.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Text;
4-
5-
namespace Rocket.API.Permissions
1+
namespace Rocket.API.Permissions
62
{
73
/// <summary>
8-
/// Represents an object that can have permissions.
4+
/// Represents an actor that can have permissions.
95
/// </summary>
10-
public interface IPermissionEntity
6+
public interface IPermissionActor
117
{
128
/// <summary>
13-
/// The unique and persistent ID of the entity.
9+
/// The unique and persistent ID of the actor.
1410
/// </summary>
1511
string Id { get; }
1612
}

Rocket.API/Permissions/IPermissionGroup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace Rocket.API.Permissions
55
/// <summary>
66
/// A permission group contains a collection of permissions.
77
/// </summary>
8-
public interface IPermissionGroup : IPermissionEntity
8+
public interface IPermissionGroup : IPermissionActor
99
{
1010
/// <summary>
1111
/// The priority of this group.

Rocket.API/Permissions/IPermissionProvider.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,55 +18,55 @@ public interface IPermissionProvider
1818
/// <param name="target">The target whichs permissions to get.</param>
1919
/// <param name="inherit">Defines if the parent groups permissions should be included.</param>
2020
/// <returns>A list of all permissions of the target.</returns>
21-
Task<IEnumerable<string>> GetGrantedPermissionsAsync(IPermissionEntity target, bool inherit = true);
21+
Task<IEnumerable<string>> GetGrantedPermissionsAsync(IPermissionActor target, bool inherit = true);
2222

2323
/// <summary>
2424
/// Gets the denied permissions of the given target.
2525
/// </summary>
2626
/// <param name="target">The target whichs denied permissions to get.</param>
2727
/// <param name="inherit">Defines if the parent groups denied permissions should be included.</param>
2828
/// <returns>A list of all denied permissions of the target.</returns>
29-
Task<IEnumerable<string>> GetDeniedPermissionsAsync(IPermissionEntity target, bool inherit = true);
29+
Task<IEnumerable<string>> GetDeniedPermissionsAsync(IPermissionActor target, bool inherit = true);
3030

3131
/// <summary>
3232
/// Adds an explicitly granted permission to the target.
3333
/// </summary>
3434
/// <param name="target">The target.</param>
3535
/// <param name="permission">The permission to add.</param>
3636
/// <returns><b>true</b> if the permission was successfully added; otherwise, <b>false</b>.</returns>
37-
Task<bool> AddPermissionAsync(IPermissionEntity target, string permission);
37+
Task<bool> AddPermissionAsync(IPermissionActor target, string permission);
3838

3939
/// <summary>
4040
/// Adds an explicitly denied permission to the target.
4141
/// </summary>
4242
/// <param name="target">The target.</param>
4343
/// <param name="permission">The denied permission to add.</param>
4444
/// <returns><b>true</b> if the permission was successfully added; otherwise, <b>false</b>.</returns>
45-
Task<bool> AddDeniedPermissionAsync(IPermissionEntity target, string permission);
45+
Task<bool> AddDeniedPermissionAsync(IPermissionActor target, string permission);
4646

4747
/// <summary>
4848
/// Removes an explicitly granted permission from the target.
4949
/// </summary>
5050
/// <param name="target">The target.</param>
5151
/// <param name="permission">The permission to remove.</param>
5252
/// <returns><b>true</b> if the permission was successfully removed; otherwise, <b>false</b>.</returns>
53-
Task<bool> RemovePermissionAsync(IPermissionEntity target, string permission);
53+
Task<bool> RemovePermissionAsync(IPermissionActor target, string permission);
5454

5555
/// <summary>
5656
/// Removes an explicitly denied permission from the target.
5757
/// </summary>
5858
/// <param name="target">The target.</param>
5959
/// <param name="permission">The permission to remove.</param>
6060
/// <returns><b>true</b> if the permission was successfully removed; otherwise, <b>false</b>.</returns>
61-
Task<bool> RemoveDeniedPermissionAsync(IPermissionEntity target, string permission);
61+
Task<bool> RemoveDeniedPermissionAsync(IPermissionActor target, string permission);
6262

6363
/// <summary>
6464
/// Gets the primary group of the given user.
6565
/// </summary>
6666
/// <param name="user">The user wose primary group to get of.</param>
6767
/// <returns>the primary group if it exists; otherwise, <b>null</b>.</returns>
6868
[Obsolete("Might be removed")]
69-
Task<IPermissionGroup> GetPrimaryGroupAsync(IPermissionEntity user);
69+
Task<IPermissionGroup> GetPrimaryGroupAsync(IPermissionActor user);
7070

7171
/// <summary>
7272
/// Gets the primary group with the given ID.
@@ -80,7 +80,7 @@ public interface IPermissionProvider
8080
/// </summary>
8181
/// <param name="target">The target.</param>
8282
/// <returns>the inherited groups of the target.</returns>
83-
Task<IEnumerable<IPermissionGroup>> GetGroupsAsync(IPermissionEntity target);
83+
Task<IEnumerable<IPermissionGroup>> GetGroupsAsync(IPermissionActor target);
8484

8585
/// <summary>
8686
/// Gets all registered groups.
@@ -101,15 +101,15 @@ public interface IPermissionProvider
101101
/// <param name="target">The target to add the group to.</param>
102102
/// <param name="group">The group to add.</param>
103103
/// <returns><b>true</b> if the group was successfully added; otherwise, <b>false</b>.</returns>
104-
Task<bool> AddGroupAsync(IPermissionEntity target, IPermissionGroup group);
104+
Task<bool> AddGroupAsync(IPermissionActor target, IPermissionGroup group);
105105

106106
/// <summary>
107107
/// Removes the given group from the user.
108108
/// </summary>
109109
/// <param name="target">The target to add the group to.</param>
110110
/// <param name="group">The group to remove.</param>
111111
/// <returns><b>true</b> if the group was successfully removed; otherwise, <b>false</b>.</returns>
112-
Task<bool> RemoveGroupAsync(IPermissionEntity target, IPermissionGroup group);
112+
Task<bool> RemoveGroupAsync(IPermissionActor target, IPermissionGroup group);
113113

114114
/// <summary>
115115
/// Creates a new permission group.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
using Rocket.API.DependencyInjection;
3+
4+
namespace Rocket.API.Scheduling
5+
{
6+
public interface ITaskRunner: IProxyableService
7+
{
8+
bool SupportsTask(IScheduledTask task);
9+
10+
void Run(IScheduledTask task, Action<Exception> completedAction);
11+
}
12+
}

Rocket.API/User/IUser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace Rocket.API.User
88
/// <summary>
99
/// A message communication User.
1010
/// </summary>
11-
public interface IUser : IPermissionEntity
11+
public interface IUser : IPermissionActor
1212
{
1313
/// <summary>
1414
/// Gets the last time the user was online on the server or null if the user was never online before.

Rocket.Console/Properties/DependencyRegistrator.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using Rocket.API.DependencyInjection;
33
using Rocket.API.Scheduling;
44
using Rocket.API.User;
5-
using Rocket.Console.Scheduling;
5+
using Rocket.Core.Scheduling;
66
using Rocket.Core.User;
77

88
namespace Rocket.Console.Properties
@@ -11,7 +11,6 @@ public class DependencyRegistrator : IDependencyRegistrator
1111
{
1212
public void Register(IDependencyContainer container, IDependencyResolver resolver)
1313
{
14-
container.RegisterSingletonType<ITaskScheduler, SimpleTaskScheduler>();
1514
container.RegisterSingletonType<IHost, ConsoleHost>();
1615
container.RegisterSingletonType<IUserManager, StdConsoleUserManager>("host", "stdconsole");
1716
}

Rocket.Console/Rocket.Console.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@
3636
</ProjectReference>
3737
<ProjectReference Include="..\Rocket.Runtime\Rocket.Runtime.csproj" />
3838
</ItemGroup>
39+
40+
<ItemGroup>
41+
<Folder Include="Scheduling\" />
42+
</ItemGroup>
3943
<PropertyGroup>
4044
<DefineConstants Condition="$(NuGetBootstrap) == 'true'">NUGET_BOOTSTRAP</DefineConstants>
4145
</PropertyGroup>

Rocket.Core/Commands/RocketCommands/CommandPermission.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public async Task ExecuteAsync(ICommandContext context)
4949
if (context.Parameters.Length != 3)
5050
throw new CommandWrongUsageException();
5151

52-
IPermissionEntity target;
52+
IPermissionActor target;
5353
string permission;
5454
string permissionFailMessage;
5555

@@ -94,7 +94,7 @@ public async Task ExecuteAsync(ICommandContext context)
9494
}
9595

9696
protected abstract Task UpdatePermissionAsync(IUser user, IPermissionProvider permissions,
97-
IPermissionEntity target, string permissionToUpdate);
97+
IPermissionActor target, string permissionToUpdate);
9898
}
9999

100100
public class CommandPermissionAdd : CommandPermissionUpdate
@@ -105,7 +105,7 @@ public class CommandPermissionAdd : CommandPermissionUpdate
105105
public override string[] Aliases => new[] {"a", "+"};
106106

107107
protected override async Task UpdatePermissionAsync(IUser user, IPermissionProvider permissions,
108-
IPermissionEntity target, string permissionToUpdate)
108+
IPermissionActor target, string permissionToUpdate)
109109
{
110110
if (await permissions.AddPermissionAsync(target, permissionToUpdate))
111111
await user.SendMessageAsync($"Successfully added \"{permissionToUpdate}\" to \"{target.GetDisplayName()}\"!",
@@ -123,7 +123,7 @@ public class CommandPermissionRemove : CommandPermissionUpdate
123123
public override string[] Aliases => new[] {"r", "-"};
124124

125125
protected override async Task UpdatePermissionAsync(IUser user, IPermissionProvider permissions,
126-
IPermissionEntity target, string permissionToUpdate)
126+
IPermissionActor target, string permissionToUpdate)
127127
{
128128
if (await permissions.RemovePermissionAsync(target, permissionToUpdate))
129129
await user.SendMessageAsync($"Successfully removed \"{permissionToUpdate}\" from \"{target.GetDisplayName()}\"!",

Rocket.Core/Permissions/ConfigurationPermissionProvider.cs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public ConfigurationPermissionProvider(IConfiguration groupsConfig,
2323
public IConfiguration GroupsConfig { get; protected set; }
2424
public IConfiguration PlayersConfig { get; protected set; }
2525

26-
public async Task<IEnumerable<string>> GetGrantedPermissionsAsync(IPermissionEntity target, bool inherit = true)
26+
public async Task<IEnumerable<string>> GetGrantedPermissionsAsync(IPermissionActor target, bool inherit = true)
2727
{
2828
PermissionSection section = target is IPermissionGroup
2929
? (PermissionSection)await GetConfigSectionAsync<GroupPermissionSection>(target, false)
@@ -52,7 +52,7 @@ public async Task<IEnumerable<string>> GetGrantedPermissionsAsync(IPermissionEnt
5252
return permissions.Distinct();
5353
}
5454

55-
public async Task<IEnumerable<string>> GetDeniedPermissionsAsync(IPermissionEntity target, bool inherit = true)
55+
public async Task<IEnumerable<string>> GetDeniedPermissionsAsync(IPermissionActor target, bool inherit = true)
5656
{
5757
PermissionSection section = target is IPermissionGroup
5858
? (PermissionSection)await GetConfigSectionAsync<GroupPermissionSection>(target, false)
@@ -81,10 +81,10 @@ public async Task<IEnumerable<string>> GetDeniedPermissionsAsync(IPermissionEnti
8181
return permissions.Distinct();
8282
}
8383

84-
public bool SupportsTarget(IPermissionEntity target)
84+
public bool SupportsTarget(IPermissionActor target)
8585
=> target is IPermissionGroup || target is IUser;
8686

87-
public async Task<PermissionResult> CheckPermissionAsync(IPermissionEntity target, string permission)
87+
public async Task<PermissionResult> CheckPermissionAsync(IPermissionActor target, string permission)
8888
{
8989
GuardLoaded();
9090
GuardPermission(ref permission);
@@ -132,7 +132,7 @@ public async Task<PermissionResult> CheckPermissionAsync(IPermissionEntity targe
132132
return PermissionResult.Default;
133133
}
134134

135-
public async Task<bool> AddPermissionAsync(IPermissionEntity target, string permission)
135+
public async Task<bool> AddPermissionAsync(IPermissionActor target, string permission)
136136
{
137137
GuardPermission(ref permission);
138138
GuardTarget(target);
@@ -148,15 +148,15 @@ public async Task<bool> AddPermissionAsync(IPermissionEntity target, string perm
148148
return true;
149149
}
150150

151-
public Task<bool> AddDeniedPermissionAsync(IPermissionEntity target, string permission)
151+
public Task<bool> AddDeniedPermissionAsync(IPermissionActor target, string permission)
152152
{
153153
GuardPermission(ref permission);
154154
GuardTarget(target);
155155

156156
return AddPermissionAsync(target, "!" + permission);
157157
}
158158

159-
public async Task<bool> RemovePermissionAsync(IPermissionEntity target, string permission)
159+
public async Task<bool> RemovePermissionAsync(IPermissionActor target, string permission)
160160
{
161161
GuardPermission(ref permission);
162162

@@ -174,24 +174,24 @@ public async Task<bool> RemovePermissionAsync(IPermissionEntity target, string p
174174
return i > 0;
175175
}
176176

177-
public async Task<bool> RemoveDeniedPermissionAsync(IPermissionEntity target, string permission)
177+
public async Task<bool> RemoveDeniedPermissionAsync(IPermissionActor target, string permission)
178178
{
179179
GuardPermission(ref permission);
180180
GuardTarget(target);
181181

182182
return await RemovePermissionAsync(target, "!" + permission);
183183
}
184184

185-
public async Task<IPermissionGroup> GetPrimaryGroupAsync(IPermissionEntity permissionEntity)
185+
public async Task<IPermissionGroup> GetPrimaryGroupAsync(IPermissionActor permissionActor)
186186
{
187187
GuardLoaded();
188-
if (!(permissionEntity is IUser))
188+
if (!(permissionActor is IUser))
189189
throw new NotSupportedException();
190190

191-
return (await GetGroupsAsync(permissionEntity)).OrderByDescending(c => c.Priority).FirstOrDefault();
191+
return (await GetGroupsAsync(permissionActor)).OrderByDescending(c => c.Priority).FirstOrDefault();
192192
}
193193

194-
public async Task<IEnumerable<IPermissionGroup>> GetGroupsAsync(IPermissionEntity target)
194+
public async Task<IEnumerable<IPermissionGroup>> GetGroupsAsync(IPermissionActor target)
195195
{
196196
GuardLoaded();
197197
GuardTarget(target);
@@ -246,7 +246,7 @@ public async Task<bool> UpdateGroupAsync(IPermissionGroup group)
246246
return true;
247247
}
248248

249-
public async Task<bool> AddGroupAsync(IPermissionEntity target, IPermissionGroup group)
249+
public async Task<bool> AddGroupAsync(IPermissionActor target, IPermissionGroup group)
250250
{
251251
GuardLoaded();
252252
GuardTarget(target);
@@ -264,7 +264,7 @@ public async Task<bool> AddGroupAsync(IPermissionEntity target, IPermissionGroup
264264
return true;
265265
}
266266

267-
public async Task<bool> RemoveGroupAsync(IPermissionEntity target, IPermissionGroup group)
267+
public async Task<bool> RemoveGroupAsync(IPermissionActor target, IPermissionGroup group)
268268
{
269269
GuardLoaded();
270270
GuardTarget(target);
@@ -411,7 +411,7 @@ private void GuardPermissions(string[] permissions)
411411
}
412412
}
413413

414-
private bool DeleteConfigSection(IPermissionEntity target)
414+
private bool DeleteConfigSection(IPermissionActor target)
415415
{
416416
IConfigurationElement config = target is IPermissionGroup
417417
? GroupsConfig["Groups"]
@@ -423,7 +423,7 @@ private bool DeleteConfigSection(IPermissionEntity target)
423423
return i > 0;
424424
}
425425

426-
public async Task<T> GetConfigSectionAsync<T>(IPermissionEntity target, bool createIfNotFound) where T : PermissionSection
426+
public async Task<T> GetConfigSectionAsync<T>(IPermissionActor target, bool createIfNotFound) where T : PermissionSection
427427
{
428428
GuardTarget(target);
429429

@@ -487,7 +487,7 @@ private void GuardLoaded()
487487
throw new Exception("Players config has not been loaded");
488488
}
489489

490-
private void GuardTarget(IPermissionEntity target)
490+
private void GuardTarget(IPermissionActor target)
491491
{
492492
if (!SupportsTarget(target))
493493
throw new NotSupportedException(target.GetType().FullName + " is not supported!");

0 commit comments

Comments
 (0)