aboutsummaryrefslogtreecommitdiff
path: root/Timeline/Services/TimelineService.cs
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-02-02 22:37:47 +0800
committercrupest <crupest@outlook.com>2020-02-02 22:37:47 +0800
commitc4fcf37d6018a0a0408920593fbfb7c01af96859 (patch)
tree38f99c0b8631d34facfe81c23bab274168643040 /Timeline/Services/TimelineService.cs
parentb9dc0062241f4dcf5221808d97a7e4c337a8b6cc (diff)
downloadtimeline-c4fcf37d6018a0a0408920593fbfb7c01af96859.tar.gz
timeline-c4fcf37d6018a0a0408920593fbfb7c01af96859.tar.bz2
timeline-c4fcf37d6018a0a0408920593fbfb7c01af96859.zip
...
Diffstat (limited to 'Timeline/Services/TimelineService.cs')
-rw-r--r--Timeline/Services/TimelineService.cs31
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)