コード例 #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 });
            });
        }
コード例 #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);
        }
コード例 #3
0
 private void EnsureIsDistrictAdminOrCurrentTeacher(int teacherId)
 {
     if (!(BaseSecurity.IsDistrictAdmin(Context) || (Context.Role == CoreRoles.TEACHER_ROLE && Context.PersonId == teacherId)))
     {
         throw new ChalkableSecurityException();
     }
 }
コード例 #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)));
        }
コード例 #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);
            }
        }
コード例 #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);
        }
コード例 #7
0
 public void Add(IList <ClassPeriod> classPeriods)
 {
     if (!BaseSecurity.IsDistrictAdmin(Context))
     {
         throw new ChalkableSecurityException();
     }
     DoUpdate(u => new ClassPeriodDataAccess(u).Insert(classPeriods));
 }
コード例 #8
0
ファイル: SchoolService.cs プロジェクト: VijayMVC/chalkable
 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)));
 }
コード例 #9
0
 public void UploadPicture(Guid districtId, int personId, byte[] content)
 {
     if (!(BaseSecurity.IsDistrictAdmin(Context)))
     {
         throw new ChalkableSecurityException();
     }
     base.UploadPicture(GenerateKeyForBlob(districtId, personId), content);
 }
コード例 #10
0
 public void Edit(IList <Date> dates)
 {
     if (!BaseSecurity.IsDistrictAdmin(Context))
     {
         throw new ChalkableSecurityException();
     }
     DoUpdate(u => new DateDataAccess(u).Update(dates));
 }
コード例 #11
0
ファイル: PeriodService.cs プロジェクト: VijayMVC/chalkable
 public void Edit(IList <Period> periods)
 {
     if (!BaseSecurity.IsDistrictAdmin(Context))
     {
         throw new ChalkableSecurityException();
     }
     DoUpdate(u => new PeriodDataAccess(u).Update(periods));
 }
コード例 #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));
     }
 }
コード例 #13
0
 public void DeletePicture(Guid districtId, int personId)
 {
     if (!(BaseSecurity.IsDistrictAdmin(Context)))
     {
         throw new ChalkableSecurityException();
     }
     base.DeletePicture(GenerateKeyForBlob(districtId, personId));
 }
コード例 #14
0
 public Data.School.Model.School GetSchool(int schoolId)
 {
     if (!(BaseSecurity.IsDistrictAdmin(Context) || Context.SchoolLocalId == schoolId))
     {
         throw new ChalkableSecurityException();
     }
     return(SchoolStorage.GetById(schoolId));
 }
コード例 #15
0
ファイル: PeriodService.cs プロジェクト: VijayMVC/chalkable
 public void Delete(IList <int> ids)
 {
     if (!BaseSecurity.IsDistrictAdmin(Context))
     {
         throw new ChalkableSecurityException();
     }
     DoUpdate(u => new PeriodDataAccess(u).Delete(ids));
 }
コード例 #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));
        }
コード例 #17
0
 public Announcement GetLastDraft()
 {
     if (BaseSecurity.IsDistrictAdmin(Context))
     {
         return(ServiceLocator.AdminAnnouncementService.GetLastDraft());
     }
     return(ServiceLocator.ClassAnnouncementService.GetLastDraft()
            ?? (Announcement)ServiceLocator.LessonPlanService.GetLastDraft()
            ?? ServiceLocator.SupplementalAnnouncementService.GetLastDraft());
 }
コード例 #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
     });
 }
コード例 #19
0
ファイル: PersonService.cs プロジェクト: VijayMVC/chalkable
        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);
        }
コード例 #20
0
 public IList <SchoolPerson> GetAll()
 {
     if (!BaseSecurity.IsDistrictAdmin(Context))
     {
         throw new ChalkableSecurityException();
     }
     using (var uow = Read())
     {
         return((new SchoolPersonDataAccess(uow)).GetAll());
     }
 }
コード例 #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);
 }
コード例 #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();
     }
 }
コード例 #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();
     }
 }
コード例 #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();
            }
        }
コード例 #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);
     }
 }
コード例 #26
0
ファイル: PhoneService.cs プロジェクト: VijayMVC/chalkable
 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);
     }
 }
コード例 #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();
            }
        }
コード例 #28
0
ファイル: PhoneService.cs プロジェクト: VijayMVC/chalkable
 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();
     }
 }
コード例 #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");
        }
コード例 #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());
        }