diff options
author | crupest <crupest@outlook.com> | 2020-02-02 22:37:47 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2020-02-02 22:37:47 +0800 |
commit | 12f85448cde94d70d9030b757b09caa5e2f53061 (patch) | |
tree | 38f99c0b8631d34facfe81c23bab274168643040 /Timeline/Services | |
parent | cb18564275735da0614be39371e2e3e7f5467e88 (diff) | |
download | timeline-12f85448cde94d70d9030b757b09caa5e2f53061.tar.gz timeline-12f85448cde94d70d9030b757b09caa5e2f53061.tar.bz2 timeline-12f85448cde94d70d9030b757b09caa5e2f53061.zip |
...
Diffstat (limited to 'Timeline/Services')
-rw-r--r-- | Timeline/Services/TimelineService.cs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/Timeline/Services/TimelineService.cs b/Timeline/Services/TimelineService.cs index b031297e..991669ad 100644 --- a/Timeline/Services/TimelineService.cs +++ b/Timeline/Services/TimelineService.cs @@ -139,6 +139,26 @@ namespace Timeline.Services Task ChangeMember(string name, IList<string>? add, IList<string>? remove);
/// <summary>
+ /// Check whether a user can manage(change timeline info, member, ...) a timeline.
+ /// </summary>
+ /// <param name="name"></param>
+ /// <param name="id"></param>
+ /// <returns>True if the user can manage the timeline, otherwise false.</returns>
+ /// <exception cref="ArgumentNullException">Thrown when <paramref name="name"/> is null.</exception>
+ /// <exception cref="ArgumentException">Thrown when <paramref name="name"/> is illegal. It is not a valid timeline name (for normal timeline service) or a valid username (for personal timeline service).</exception>
+ /// <exception cref="TimelineNotExistException">
+ /// Thrown when timeline does not exist.
+ /// For normal timeline, it means the name does not exist.
+ /// For personal timeline, it means the user of that username does not exist
+ /// and the inner exception should be a <see cref="UserNotExistException"/>.
+ /// </exception>
+ /// <remarks>
+ /// This method does not check whether visitor is administrator.
+ /// Return false if user with user id does not exist.
+ /// </remarks>
+ Task<bool> HasManagePermission(string name, long userId);
+
+ /// <summary>
/// Verify whether a visitor has the permission to read a timeline.
/// </summary>
/// <param name="name">Username or the timeline name. See remarks of <see cref="IBaseTimelineService"/>.</param>
@@ -490,6 +510,17 @@ namespace Timeline.Services await Database.SaveChangesAsync();
}
+ public async Task<bool> HasManagePermission(string name, long userId)
+ {
+ if (name == null)
+ throw new ArgumentNullException(nameof(name));
+
+ var timelineId = await FindTimelineId(name);
+ var timelineEntity = await Database.Timelines.Where(t => t.Id == timelineId).Select(t => new { t.OwnerId }).SingleAsync();
+
+ return userId == timelineEntity.OwnerId;
+ }
+
public async Task<bool> HasReadPermission(string name, long? visitorId)
{
if (name == null)
|