// NOTE: Implementation Example (MDJ) // TODO: Use this to secure editing CalendarEvents internal bool AuthorizeForEdit(Models.CalendarEvent calendarEvent) { var userContext = _userContextAccessor.GetContext(); // Has Author permission and this is their event if (HasAnyClaim(CalendarClaimTypes.CalendarAuthor)) { return(true); } // Is a SiteAdmin and this is their event if (HasAnyClaim(SiteClaimTypes.SitePrimaryAdmin)) { return(true); } // Has been granted contribute permissions for this specific event if (HasDelegateClaim(CalendarClaimTypes.CalendarEventContribute, calendarEvent)) { return(true); } // Client Level Content Admin can manage all user content if (HasAdminClaim(ClientClaimTypes.UserContentManage)) { return(true); } // Client Level Primary Admin can manage everything if (HasAdminClaim(ClientClaimTypes.PrimaryAdmin)) { return(true); } return(false); }
private bool HasDelegateClaim(string claimType, Models.CalendarEvent calendarEvent) { var userContext = _userContextAccessor.GetContext(); //EG, has a claim against this specific event return(userContext.SecurityClaims.Any(x => x.Type == claimType && x.Value == calendarEvent.EventId)); }
private bool HasAuthorClaim(string claimType, Models.CalendarEvent calendarEvent) { var userContext = _userContextAccessor.GetContext(); if (userContext.UserId == calendarEvent.UserId) { // Not checking value because it doesn't matter which site issued this claim return(userContext.SecurityClaims.Any(x => x.Type == claimType)); } return(false); }
public async Task <bool> Handle(CreateCalendarEventCommand request, CancellationToken cancellationToken) { var model = new Models.CalendarEvent() { Description = request.Description }; var addedEvent = await _calendarRepository.AddEvent(model); var @event = new CalendarEventAddedEvent() { Description = addedEvent.Description, Id = addedEvent.Id }; _bus.Publish(@event); return(true); }
public static void InsertSeedData(CalendarDbContext dbContext) { if (dbContext.CalendarEvents.Count() == 0) { var event1 = new Models.CalendarEvent { EventId = Guid.NewGuid().ToString("N"), DocumentId = Guid.NewGuid().ToString("N"), Title = "Health Forms are Due", Posted = DateTime.Now, SiteId = "b75cbabb-839f-4b20-ba6e-b74241080201", UserId = "AFCF7980-4BA7-4DD2-879D-599D058F7E73", //ADMIN Style = "event-info", Description = @"<p><img class='img-responsive' src='/img/SeedImages/cats1_200_200.jpg' /></p> <h2>How to Be a Godly Man</h2> <p>Men's Breakfast is our monthly event where all men of the church are invited to grow in the knowledge and love of Jesus Christ.</p> <p>We encourage Lifers to invite other men - unconnected, no-believers, friends, neighbors, co-workers - to join them as an outreach to the community around us</p>", EventStart = DateTime.Parse($"{DateTime.Now.Month.ToString()}/26/{DateTime.Now.Year.ToString()} 2:00:00 PM"), EventEnd = DateTime.Parse($"4/30/{DateTime.Now.Year.ToString()} 10:15:00 PM"), Phone = "919-277-2222", BackgroundColor = "Red", IsRecurrent = true, ShowOrganizerName = true, ShowPhoneNumber = true }; var eventRecurrence = new Models.CalendarEventRecurrence { Id = Guid.NewGuid().ToString("N"), EventId = event1.EventId, Frequency = "Daily", Interval = 1, Count = 7 }; var event2 = new Models.CalendarEvent { EventId = Guid.NewGuid().ToString("N"), DocumentId = Guid.NewGuid().ToString("N"), Title = "Women's Soccer Fundraising", SiteId = "b75cbabb-839f-4b20-ba6e-b74241080201", UserId = "AFCF7980-4BA7-4DD2-879D-599D058F7E73", //ADMIN Posted = DateTime.Now, Style = "event-success", Description = "Classes will be held at our main location.", EventStart = DateTime.Parse($"{DateTime.Now.Month.ToString()}/25/2018 2:00:00 PM"), EventEnd = DateTime.Parse($"4/25/2017 3:15:00 PM"), Phone = "919-277-1111", BackgroundColor = "Pink", IsRecurrent = true, ShowOrganizerName = true, ShowPhoneNumber = true }; var eventRecurrence2 = new Models.CalendarEventRecurrence { Id = Guid.NewGuid().ToString("N"), EventId = event2.EventId, Frequency = "Weekly", Interval = 1, Count = 10, DaysOfWeek = "0,3" }; var event3 = new Models.CalendarEvent { EventId = Guid.NewGuid().ToString("N"), DocumentId = Guid.NewGuid().ToString("N"), Title = "Child Custody Battle", Posted = DateTime.Now, SiteId = "b75cbabb-839f-4b20-ba6e-b74241080201", UserId = "AFCF7980-4BA7-4DD2-879D-599D058F7E73", //ADMIN Style = "event-info", Description = @"<p><img class='img-responsive' src='/img/SeedImages/cats1_200_200.jpg' /></p> <h2>How to Be a Godly Man</h2> <p>Men's Breakfast is our monthly event where all men of the church are invited to grow in the knowledge and love of Jesus Christ.</p> <p>We encourage Lifers to invite other men - unconnected, no-believers, friends, neighbors, co-workers - to join them as an outreach to the community around us</p>", EventStart = DateTime.Parse($"3/26/2018 2:00:00 PM"), EventEnd = DateTime.Parse($"12/30/2018 10:15:00 PM"), Phone = "919-277-2222", BackgroundColor = "Purple", IsRecurrent = true, ShowOrganizerName = true, ShowPhoneNumber = true }; var eventRecurrence3 = new Models.CalendarEventRecurrence { Id = Guid.NewGuid().ToString("N"), EventId = event3.EventId, Frequency = "Monthly", Interval = 1, EndDate = DateTime.Parse($"12/30/2018 10:15:00 PM"), DayOfMonth = 21 }; var event4 = new Models.CalendarEvent { EventId = Guid.NewGuid().ToString("N"), DocumentId = Guid.NewGuid().ToString("N"), Title = "My Yearly Event", Posted = DateTime.Now, SiteId = "b75cbabb-839f-4b20-ba6e-b74241080201", UserId = "AFCF7980-4BA7-4DD2-879D-599D058F7E73", //ADMIN Style = "event-info", Description = @"<p><img class='img-responsive' src='/img/SeedImages/cats1_200_200.jpg' /></p> <h2>How to Be a Godly Man</h2> <p>Men's Breakfast is our monthly event where all men of the church are invited to grow in the knowledge and love of Jesus Christ.</p> <p>We encourage Lifers to invite other men - unconnected, no-believers, friends, neighbors, co-workers - to join them as an outreach to the community around us</p>", EventStart = DateTime.Parse($"1/27/2018 2:00:00 PM"), EventEnd = DateTime.Parse($"12/30/2020 10:15:00 PM"), Phone = "919-277-2222", BackgroundColor = "Blue", IsRecurrent = true, ShowOrganizerName = true, ShowPhoneNumber = true }; var eventRecurrence4 = new Models.CalendarEventRecurrence { Id = Guid.NewGuid().ToString("N"), EventId = event4.EventId, Frequency = "Yearly", Interval = 1, Count = 2, //EndDate = DateTime.Parse($"12/30/2020 10:15:00 PM"), DayOfMonth = 27, Months = "1" }; var group1 = new Models.CalendarEventGroup() { SiteId = "b75cbabb-839f-4b20-ba6e-b74241080201", UserId = "AFCF7980-4BA7-4DD2-879D-599D058F7E73", Title = "2017 Softball Events", EventGroupId = Guid.NewGuid().ToString("N") }; var group2 = new Models.CalendarEventGroup() { SiteId = "b75cbabb-839f-4b20-ba6e-b74241080201", UserId = "AFCF7980-4BA7-4DD2-879D-599D058F7E73", Title = "2017 Soccer Events", EventGroupId = Guid.NewGuid().ToString("N") }; dbContext.Add(group1); dbContext.Add(group2); dbContext.AddRange( new Models.CalendarEventGroupEvent() { Event = event1, EventGroupId = group1.EventGroupId }, new Models.CalendarEventGroupEvent() { Event = event1, EventGroupId = group2.EventGroupId }, new Models.CalendarEventGroupEvent() { Event = event2, EventGroupId = group1.EventGroupId }, new Models.CalendarEventGroupEvent() { Event = event3, EventGroupId = group2.EventGroupId } ); dbContext.Add(eventRecurrence); dbContext.Add(eventRecurrence2); dbContext.Add(eventRecurrence3); dbContext.Add(event4); dbContext.Add(eventRecurrence4); dbContext.SaveChanges(); } }