public void ReplaceLessonPlanInGallery(int oldLessonPlanId, int newLessonPlanId) { BaseSecurity.EnsureStudyCenterEnabled(Context); // only study center customers can use lesson plan gallery var newLessonPlan = GetLessonPlanById(newLessonPlanId); DoUpdate(u => { var da = CreateLessonPlanDataAccess(u); var oldLessonPlan = da.GetLessonPlanTemplate(oldLessonPlanId, Context.PersonId.Value); if (!oldLessonPlan.LpGalleryCategoryRef.HasValue) { throw new ChalkableException($@"'{oldLessonPlan.Title}' was deleted from Gallery."); } if (!BaseSecurity.IsDistrictAdmin(Context) && oldLessonPlan.GalleryOwnerRef != Context.PersonId) { throw new ChalkableException("Current user has no access to replace lesson plan in gallery!"); } newLessonPlan.LpGalleryCategoryRef = oldLessonPlan.LpGalleryCategoryRef; oldLessonPlan.LpGalleryCategoryRef = null; CreateLessonPlanDataAccess(u).Update(new[] { oldLessonPlan, newLessonPlan }); }); }
public IList <AnnouncementDetails> GetAnnouncementDetailses(DateTime?fromDate, DateTime?toDate, int?classId, bool?complete, AnnouncementTypeEnum?announcementType) { var res = new List <AnnouncementDetails>(); if (!BaseSecurity.IsTeacher(Context) && !classId.HasValue) { if (!announcementType.HasValue || announcementType == AnnouncementTypeEnum.Admin) { res.AddRange(ServiceLocator.AdminAnnouncementService.GetAnnouncementDetailses(fromDate, toDate, null, complete, true)); } } if (!BaseSecurity.IsDistrictAdmin(Context) || classId.HasValue) { var onlyOwners = !Context.Claims.HasPermission(ClaimInfo.VIEW_CLASSROOM_ADMIN); if (!announcementType.HasValue || announcementType == AnnouncementTypeEnum.Class) { res.AddRange(ServiceLocator.ClassAnnouncementService.GetAnnouncementDetailses(fromDate, toDate, classId, complete, onlyOwners)); } if (!announcementType.HasValue || announcementType == AnnouncementTypeEnum.LessonPlan) { res.AddRange(ServiceLocator.LessonPlanService.GetAnnouncementDetailses(fromDate, toDate, classId, complete, onlyOwners)); } if (!announcementType.HasValue || announcementType == AnnouncementTypeEnum.Supplemental) { res.AddRange(ServiceLocator.SupplementalAnnouncementService.GetAnnouncementDetailses(fromDate, toDate, classId, complete, onlyOwners)); } } return(res); }
private void EnsureIsDistrictAdminOrCurrentTeacher(int teacherId) { if (!(BaseSecurity.IsDistrictAdmin(Context) || (Context.Role == CoreRoles.TEACHER_ROLE && Context.PersonId == teacherId))) { throw new ChalkableSecurityException(); } }
public bool HasMessagingSettgingsAccess(UserContext context, Guid?districtId) { var hasPermission = Context.Claims.HasPermission(ClaimInfo.MAINTAIN_CHALKABLE_DISTRICT_SETTINGS); return((!districtId.HasValue || districtId == Context.DistrictId) && (BaseSecurity.IsSysAdmin(context) || (BaseSecurity.IsDistrictAdmin(context) && hasPermission))); }
private PaginatedList <NotificationDetails> GetNotifications(NotificationQuery query) { Trace.Assert(Context.SchoolLocalId.HasValue); Trace.Assert(Context.PersonId.HasValue); using (var uow = Read()) { if (BaseSecurity.IsDistrictAdmin(Context)) { query.SchoolId = Context.SchoolLocalId.Value; } query.PersonId = Context.PersonId.Value; query.RoleId = Context.RoleId; var notifications = new NotificationDataAccess(uow).GetPaginatedNotificationsDetails(query, !Context.MessagingDisabled); var classIds = notifications.Where(x => x.AnnouncementRef.HasValue && x.Announcement is ClassAnnouncement) .Select(x => (x.Announcement as ClassAnnouncement).ClassRef) .ToList(); IList <ClassAnnouncementType> classAnnouncementTypes = ServiceLocator.ClassAnnouncementTypeService.GetClassAnnouncementTypes(classIds); foreach (var notification in notifications) { var classAnn = notification.Announcement as ClassAnnouncement; if (classAnn != null && classAnn.ClassAnnouncementTypeRef.HasValue) { var classAnnType = classAnnouncementTypes.First(x => x.Id == classAnn.ClassAnnouncementTypeRef); notification.ClassAnnouncementType = classAnnType; } } return(notifications); } }
public override Announcement EditTitle(int announcementId, string title) { Trace.Assert(Context.PersonId.HasValue); var announcement = GetLessonPlanById(announcementId); if (announcement.Title != title) { using (var uow = Update()) { if (!announcement.IsOwner && !BaseSecurity.IsDistrictAdmin(Context) && announcement.GalleryOwnerRef != Context.PersonId) { throw new ChalkableSecurityException(); } var da = CreateLessonPlanDataAccess(uow); if (string.IsNullOrEmpty(title)) { throw new ChalkableException("Title parameter is empty"); } if (da.ExistsInGallery(title, announcement.Id) && announcement.InGallery) { throw new ChalkableException("The item with current title already exists in the gallery"); } announcement.Title = title; da.Update(announcement); uow.Commit(); } } return(announcement); }
public void Add(IList <ClassPeriod> classPeriods) { if (!BaseSecurity.IsDistrictAdmin(Context)) { throw new ChalkableSecurityException(); } DoUpdate(u => new ClassPeriodDataAccess(u).Insert(classPeriods)); }
public Data.School.Model.School GetSchool(int schoolId) { if (!(BaseSecurity.IsDistrictAdmin(Context) || Context.SchoolLocalId == schoolId)) { throw new ChalkableSecurityException(); } return(DoRead(u => new SchoolDataAccess(u).GetById(schoolId))); }
public void UploadPicture(Guid districtId, int personId, byte[] content) { if (!(BaseSecurity.IsDistrictAdmin(Context))) { throw new ChalkableSecurityException(); } base.UploadPicture(GenerateKeyForBlob(districtId, personId), content); }
public void Edit(IList <Date> dates) { if (!BaseSecurity.IsDistrictAdmin(Context)) { throw new ChalkableSecurityException(); } DoUpdate(u => new DateDataAccess(u).Update(dates)); }
public void Edit(IList <Period> periods) { if (!BaseSecurity.IsDistrictAdmin(Context)) { throw new ChalkableSecurityException(); } DoUpdate(u => new PeriodDataAccess(u).Update(periods)); }
public override void SetAnnouncementsAsComplete(DateTime?toDate, bool complete) { Trace.Assert(Context.PersonId.HasValue); if (BaseSecurity.IsDistrictAdmin(Context)) { DoUpdate(u => SetAnnouncementsAsComplete(u, ServiceLocator, toDate, complete)); } }
public void DeletePicture(Guid districtId, int personId) { if (!(BaseSecurity.IsDistrictAdmin(Context))) { throw new ChalkableSecurityException(); } base.DeletePicture(GenerateKeyForBlob(districtId, personId)); }
public Data.School.Model.School GetSchool(int schoolId) { if (!(BaseSecurity.IsDistrictAdmin(Context) || Context.SchoolLocalId == schoolId)) { throw new ChalkableSecurityException(); } return(SchoolStorage.GetById(schoolId)); }
public void Delete(IList <int> ids) { if (!BaseSecurity.IsDistrictAdmin(Context)) { throw new ChalkableSecurityException(); } DoUpdate(u => new PeriodDataAccess(u).Delete(ids)); }
private bool CanEditQuestion(AnnouncementQnAComplex announcementQnA, UnitOfWork uow) { var da = new ClassTeacherDataAccess(uow); return(BaseSecurity.IsSysAdmin(Context) || announcementQnA.AskerRef == Context.PersonId || (Context.PersonId.HasValue && Context.Role == CoreRoles.TEACHER_ROLE && da.Exists(announcementQnA.ClassRef, Context.PersonId.Value)) || (BaseSecurity.IsDistrictAdmin(Context) && announcementQnA.AdminRef == Context.PersonId)); }
public Announcement GetLastDraft() { if (BaseSecurity.IsDistrictAdmin(Context)) { return(ServiceLocator.AdminAnnouncementService.GetLastDraft()); } return(ServiceLocator.ClassAnnouncementService.GetLastDraft() ?? (Announcement)ServiceLocator.LessonPlanService.GetLastDraft() ?? ServiceLocator.SupplementalAnnouncementService.GetLastDraft()); }
public void AddGroup(string name) { if (!Context.PersonId.HasValue) { throw new UnassignedUserException(); } BaseSecurity.IsDistrictAdmin(Context); // only admin can create group ... think do we need this for demo GroupStorage.Add(new Group { Name = name, OwnerRef = Context.PersonId.Value }); }
public PersonDetails GetPersonDetails(int id, int?schoolId = null) { Trace.Assert(Context.SchoolLocalId.HasValue); var res = DoRead(uow => new PersonDataAccess(uow).GetPersonDetails(id, schoolId ?? Context.SchoolLocalId.Value)); if (BaseSecurity.IsDistrictAdmin(Context) && Context.PersonId == res.Id) { res.RoleRef = Context.Role.Id; } return(res); }
public IList <SchoolPerson> GetAll() { if (!BaseSecurity.IsDistrictAdmin(Context)) { throw new ChalkableSecurityException(); } using (var uow = Read()) { return((new SchoolPersonDataAccess(uow)).GetAll()); } }
public bool HasMyApps(Application application) { if (BaseSecurity.IsDistrictAdmin(ServiceLocator.Context)) { return(application.HasAdminMyApps); } if (Context.Role.Id == CoreRoles.TEACHER_ROLE.Id) { return(application.HasTeacherMyApps); } return(Context.Role.Id == CoreRoles.STUDENT_ROLE.Id && application.HasStudentMyApps); }
public void Edit(IList <AttendanceReason> reasons) { if (!BaseSecurity.IsDistrictAdmin(Context)) { throw new ChalkableSecurityException(); } using (var uow = Update()) { new AttendanceReasonDataAccess(uow).Update(reasons); uow.Commit(); } }
public void DeleteAttendanceLevelReasons(IList <int> ids) { if (!BaseSecurity.IsDistrictAdmin(Context)) { throw new ChalkableSecurityException(); } using (var uow = Update()) { new AttendanceLevelReasonDataAccess(uow).Delete(ids); uow.Commit(); } }
public void Delete(IList <ClassPeriod> classPeriods) { if (!BaseSecurity.IsDistrictAdmin(Context)) { throw new ChalkableSecurityException(); } using (var uow = Update()) { new ClassPeriodDataAccess(uow).Delete(classPeriods); uow.Commit(); } }
public IList <MarkingPeriod> Edit(IList <MarkingPeriod> markingPeriods) { if (!BaseSecurity.IsDistrictAdmin(Context)) { throw new ChalkableSecurityException(); } using (var uow = Update()) { new MarkingPeriodDataAccess(uow).Update(markingPeriods); uow.Commit(); return(markingPeriods); } }
public IList <Phone> EditPhones(IList <Phone> phones) { if (!(BaseSecurity.IsDistrictAdmin(Context))) { throw new ChalkableSecurityException(); } using (var uow = Update()) { new PhoneDataAccess(uow).Update(phones); uow.Commit(); return(phones); } }
public void Edit(IList <GradingPeriod> gradingPeriods) { if (!BaseSecurity.IsDistrictAdmin(Context)) { throw new ChalkableSecurityException(); } using (var uow = Update()) { new GradingPeriodDataAccess(uow).Update(gradingPeriods); uow.Commit(); } }
public void Delete(IList <Phone> phones) { if (!(BaseSecurity.IsDistrictAdmin(Context))) { throw new ChalkableSecurityException(); } using (var uow = Update()) { var da = new PhoneDataAccess(uow); da.Delete(phones); uow.Commit(); } }
private static AdminAnnouncementDataAccess CreateAdminAnnouncementDataAccess(UnitOfWork unitOfWork, IServiceLocatorSchool locator) { var context = locator.Context; if (BaseSecurity.IsDistrictAdmin(context)) { return(new AdminAnnouncementForAdminDataAccess(unitOfWork)); } if (context.Role == CoreRoles.STUDENT_ROLE) { return(new AdminAnnouncementForStudentDataAccess(unitOfWork)); } throw new ChalkableException("Not supported role for admin announcements"); }
public IList <Announcement> GetAnnouncementsByFilter(string filter) { var res = new List <Announcement>(); if (BaseSecurity.IsDistrictAdmin(Context) || CoreRoles.STUDENT_ROLE == Context.Role) { res.AddRange(ServiceLocator.AdminAnnouncementService.GetAdminAnnouncementsByFilter(filter)); } if (BaseSecurity.IsTeacher(Context) || CoreRoles.STUDENT_ROLE == Context.Role) { res.AddRange(ServiceLocator.LessonPlanService.GetLessonPlansbyFilter(filter)); res.AddRange(ServiceLocator.ClassAnnouncementService.GetClassAnnouncementsByFilter(filter)); } return(res.OrderBy(x => x.Created).ToList()); }