本文整理汇总了C#中IPrincipal.HasAccessFor方法的典型用法代码示例。如果您正苦于以下问题:C# IPrincipal.HasAccessFor方法的具体用法?C# IPrincipal.HasAccessFor怎么用?C# IPrincipal.HasAccessFor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IPrincipal
的用法示例。
在下文中一共展示了IPrincipal.HasAccessFor方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetVisibleUnits
public List<string> GetVisibleUnits(string courseId, IPrincipal user)
{
var canSeeEverything = user.HasAccessFor(courseId, CourseRole.Tester);
if (canSeeEverything)
return courseManager.GetCourse(courseId).Slides.Select(s => s.Info.UnitName).Distinct().ToList();
return db.Units.Where(u => u.CourseId == courseId && u.PublishTime <= DateTime.Now).Select(u => u.UnitName).ToList();
}
示例2: CanAddCommentHere
private bool CanAddCommentHere(IPrincipal user, string courseId, bool isReply)
{
if (!User.Identity.IsAuthenticated)
return false;
var commentsPolicy = commentsRepo.GetCommentsPolicy(courseId);
var isInstructor = user.HasAccessFor(courseId, CourseRole.Instructor);
if (!isInstructor && !commentsPolicy.IsCommentsEnabled)
return false;
if (isReply && !isInstructor && commentsPolicy.OnlyInstructorsCanReply)
return false;
return true;
}
示例3: AddComment
public async Task<Comment> AddComment(IPrincipal author, string courseId, Guid slideId, int parentCommentId, string commentText)
{
var commentsPolicy = GetCommentsPolicy(courseId);
var isInstructor = author.HasAccessFor(courseId, CourseRole.Instructor);
var isApproved = commentsPolicy.ModerationPolicy == CommentModerationPolicy.Postmoderation || isInstructor;
/* Instructors' replies are automaticly correct */
var isReply = parentCommentId != -1;
var isCorrectAnswer = isReply && isInstructor;
var comment = db.Comments.Create();
comment.AuthorId = author.Identity.GetUserId();
comment.CourseId = courseId;
comment.SlideId = slideId;
comment.ParentCommentId = parentCommentId;
comment.Text = commentText;
comment.IsApproved = isApproved;
comment.IsCorrectAnswer = isCorrectAnswer;
comment.PublishTime = DateTime.Now;
db.Comments.Add(comment);
await db.SaveChangesAsync();
return db.Comments.Find(comment.Id);
}
示例4: CanAddCommentNow
private bool CanAddCommentNow(IPrincipal user, string courseId)
{
// Instructors have unlimited comments
if (user.HasAccessFor(courseId, CourseRole.Instructor))
return true;
var commentsPolicy = commentsRepo.GetCommentsPolicy(courseId);
return ! commentsRepo.IsUserAddedMaxCommentsInLastTime(user.Identity.GetUserId(),
commentsPolicy.MaxCommentsCountInLastTime,
commentsPolicy.LastTimeForMaxCommentsLimit);
}
示例5: CanEditAndDeleteComment
private bool CanEditAndDeleteComment(IPrincipal user, Comment comment)
{
return user.HasAccessFor(comment.CourseId, CourseRole.Instructor) ||
user.Identity.GetUserId() == comment.AuthorId;
}
示例6: CanUserSeeAllCourseGroups
public bool CanUserSeeAllCourseGroups(IPrincipal user, string courseId)
{
return user.HasAccessFor(courseId, CourseRole.CourseAdmin);
}
示例7: GetAvailableForUserGroups
public List<Group> GetAvailableForUserGroups(string courseId, IPrincipal user)
{
if (!user.HasAccessFor(courseId, CourseRole.Instructor))
return new List<Group>();
IEnumerable<Group> groups;
var userId = user.Identity.GetUserId();
/* Course admins can see all groups */
if (CanUserSeeAllCourseGroups(user, courseId))
groups = GetGroups(courseId);
else
/* Other instructor can see only public or own groups */
groups = db.Groups.Where(g => g.CourseId == courseId && !g.IsDeleted && (g.OwnerId == userId || g.IsPublic));
return groups
.OrderBy(g => g.OwnerId != userId)
.ThenBy(g => g.Name)
.ToList();
}
示例8: IsGroupAvailableForUser
public bool IsGroupAvailableForUser(int groupId, IPrincipal user)
{
var group = FindGroupById(groupId);
/* Course admins can see all groups */
if (CanUserSeeAllCourseGroups(user, group.CourseId))
return true;
if (!user.HasAccessFor(group.CourseId, CourseRole.Instructor))
return false;
var userId = user.Identity.GetUserId();
return !group.IsDeleted && (group.OwnerId == userId || group.IsPublic);
}