Exemplo n.º 1
0
        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 });
            });
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
 private void EnsureIsDistrictAdminOrCurrentTeacher(int teacherId)
 {
     if (!(BaseSecurity.IsDistrictAdmin(Context) || (Context.Role == CoreRoles.TEACHER_ROLE && Context.PersonId == teacherId)))
     {
         throw new ChalkableSecurityException();
     }
 }
Exemplo n.º 4
0
        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)));
        }
Exemplo n.º 5
0
        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);
            }
        }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
0
 public void Add(IList <ClassPeriod> classPeriods)
 {
     if (!BaseSecurity.IsDistrictAdmin(Context))
     {
         throw new ChalkableSecurityException();
     }
     DoUpdate(u => new ClassPeriodDataAccess(u).Insert(classPeriods));
 }
Exemplo n.º 8
0
 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)));
 }
Exemplo n.º 9
0
 public void UploadPicture(Guid districtId, int personId, byte[] content)
 {
     if (!(BaseSecurity.IsDistrictAdmin(Context)))
     {
         throw new ChalkableSecurityException();
     }
     base.UploadPicture(GenerateKeyForBlob(districtId, personId), content);
 }
Exemplo n.º 10
0
 public void Edit(IList <Date> dates)
 {
     if (!BaseSecurity.IsDistrictAdmin(Context))
     {
         throw new ChalkableSecurityException();
     }
     DoUpdate(u => new DateDataAccess(u).Update(dates));
 }
Exemplo n.º 11
0
 public void Edit(IList <Period> periods)
 {
     if (!BaseSecurity.IsDistrictAdmin(Context))
     {
         throw new ChalkableSecurityException();
     }
     DoUpdate(u => new PeriodDataAccess(u).Update(periods));
 }
Exemplo n.º 12
0
 public override void SetAnnouncementsAsComplete(DateTime?toDate, bool complete)
 {
     Trace.Assert(Context.PersonId.HasValue);
     if (BaseSecurity.IsDistrictAdmin(Context))
     {
         DoUpdate(u => SetAnnouncementsAsComplete(u, ServiceLocator, toDate, complete));
     }
 }
Exemplo n.º 13
0
 public void DeletePicture(Guid districtId, int personId)
 {
     if (!(BaseSecurity.IsDistrictAdmin(Context)))
     {
         throw new ChalkableSecurityException();
     }
     base.DeletePicture(GenerateKeyForBlob(districtId, personId));
 }
Exemplo n.º 14
0
 public Data.School.Model.School GetSchool(int schoolId)
 {
     if (!(BaseSecurity.IsDistrictAdmin(Context) || Context.SchoolLocalId == schoolId))
     {
         throw new ChalkableSecurityException();
     }
     return(SchoolStorage.GetById(schoolId));
 }
Exemplo n.º 15
0
 public void Delete(IList <int> ids)
 {
     if (!BaseSecurity.IsDistrictAdmin(Context))
     {
         throw new ChalkableSecurityException();
     }
     DoUpdate(u => new PeriodDataAccess(u).Delete(ids));
 }
Exemplo n.º 16
0
        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));
        }
Exemplo n.º 17
0
 public Announcement GetLastDraft()
 {
     if (BaseSecurity.IsDistrictAdmin(Context))
     {
         return(ServiceLocator.AdminAnnouncementService.GetLastDraft());
     }
     return(ServiceLocator.ClassAnnouncementService.GetLastDraft()
            ?? (Announcement)ServiceLocator.LessonPlanService.GetLastDraft()
            ?? ServiceLocator.SupplementalAnnouncementService.GetLastDraft());
 }
Exemplo n.º 18
0
 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
     });
 }
Exemplo n.º 19
0
        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);
        }
Exemplo n.º 20
0
 public IList <SchoolPerson> GetAll()
 {
     if (!BaseSecurity.IsDistrictAdmin(Context))
     {
         throw new ChalkableSecurityException();
     }
     using (var uow = Read())
     {
         return((new SchoolPersonDataAccess(uow)).GetAll());
     }
 }
Exemplo n.º 21
0
 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);
 }
Exemplo n.º 22
0
 public void Edit(IList <AttendanceReason> reasons)
 {
     if (!BaseSecurity.IsDistrictAdmin(Context))
     {
         throw new ChalkableSecurityException();
     }
     using (var uow = Update())
     {
         new AttendanceReasonDataAccess(uow).Update(reasons);
         uow.Commit();
     }
 }
Exemplo n.º 23
0
 public void DeleteAttendanceLevelReasons(IList <int> ids)
 {
     if (!BaseSecurity.IsDistrictAdmin(Context))
     {
         throw new ChalkableSecurityException();
     }
     using (var uow = Update())
     {
         new AttendanceLevelReasonDataAccess(uow).Delete(ids);
         uow.Commit();
     }
 }
Exemplo n.º 24
0
        public void Delete(IList <ClassPeriod> classPeriods)
        {
            if (!BaseSecurity.IsDistrictAdmin(Context))
            {
                throw new ChalkableSecurityException();
            }

            using (var uow = Update())
            {
                new ClassPeriodDataAccess(uow).Delete(classPeriods);
                uow.Commit();
            }
        }
Exemplo n.º 25
0
 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);
     }
 }
Exemplo n.º 26
0
 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);
     }
 }
Exemplo n.º 27
0
        public void Edit(IList <GradingPeriod> gradingPeriods)
        {
            if (!BaseSecurity.IsDistrictAdmin(Context))
            {
                throw new ChalkableSecurityException();
            }

            using (var uow = Update())
            {
                new GradingPeriodDataAccess(uow).Update(gradingPeriods);
                uow.Commit();
            }
        }
Exemplo n.º 28
0
 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();
     }
 }
Exemplo n.º 29
0
        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");
        }
Exemplo n.º 30
0
        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());
        }