Exemplo n.º 1
0
        public IList <ClassStatsInfo> GetClassesStatsForStudent(int studentId, int gradingPeriodId, ClassSortType?sortType)
        {
            Trace.Assert(Context.SchoolYearId.HasValue);
            if (!(BaseSecurity.IsDistrictOrTeacher(Context) || studentId == Context.PersonId))
            {
                throw new ChalkableSecurityException();
            }

            IList <SectionSummaryForStudent> iNowRes;

            try
            {
                iNowRes = ConnectorLocator.ClassesDashboardConnector.GetSectionSummaryForStudent(Context.SchoolYearId.Value, studentId, gradingPeriodId);
            }
            catch (ChalkableSisNotSupportVersionException)
            {
                var gp           = ServiceLocator.GradingPeriodService.GetGradingPeriodById(gradingPeriodId);
                var chalkableRes = DoRead(u => new ClassDataAccess(u).GetStudentClasses(Context.SchoolYearId.Value, studentId, gp.MarkingPeriodRef));
                return(SortClassesStats(chalkableRes.Select(ClassStatsInfo.Create), sortType).ToList());
            }
            using (var u = Read())
            {
                var classesIds    = iNowRes.Select(x => x.SectionId).ToList();
                var classes       = new ClassDataAccess(u).GetByIds(classesIds);
                var classTeachers = new ClassTeacherDataAccess(u).GetClassTeachers(classesIds);
                var res           = ClassStatsInfo.Create(iNowRes, classes, classTeachers);
                return(SortClassesStats(res, sortType).ToList());
            }
        }
Exemplo n.º 2
0
        public string BuildLESingOnUrl()
        {
            Trace.Assert(Context.PersonId.HasValue);
            Trace.Assert(Context.SchoolLocalId.HasValue);
            Trace.Assert(Context.SchoolYearId.HasValue);

            if (Context.LEEnabled && IsLELinkActive())
            {
                return(BuildIntegratedSingOnUrl());
            }

            if (Context.Role == CoreRoles.STUDENT_ROLE)
            {
                var person = ServiceLocator.StudentService.GetById(Context.PersonId.Value, Context.SchoolYearId.Value);
                return(BuildNonIntegratedSingOnUrl(Context.SchoolLocalId.Value, person.UserId, person.FirstName, person.LastName));
            }
            if (BaseSecurity.IsDistrictOrTeacher(Context))
            {
                var person = ServiceLocator.StaffService.GetStaff(Context.PersonId.Value);
                return(BuildNonIntegratedSingOnUrl(Context.SchoolLocalId.Value, person.UserId.Value, person.FirstName, person.LastName));
            }
            else
            {
                var person = ServiceLocator.PersonService.GetPerson(Context.PersonId.Value);
                return(BuildNonIntegratedSingOnUrl(Context.SchoolLocalId.Value, person.UserId.Value, person.FirstName, person.LastName));
            }
        }
Exemplo n.º 3
0
        public ActionResult Me()
        {
            if (!Context.PersonId.HasValue)
            {
                throw new UnassignedUserException();
            }
            var person = SchoolLocator.PersonService.GetPersonDetails(Context.PersonId.Value);

            if (!Context.SchoolYearId.HasValue)
            {
                throw new ChalkableException("User has no valid school year id");
            }
            if (!Context.DistrictId.HasValue || !Context.SchoolLocalId.HasValue)
            {
                throw new UnassignedUserException("User is not assigned to any school");
            }

            var district   = MasterLocator.DistrictService.GetByIdOrNull(Context.DistrictId.Value);
            var school     = MasterLocator.SchoolService.GetById(Context.DistrictId.Value, Context.SchoolLocalId.Value);
            var schoolYear = SchoolLocator.SchoolYearService.GetSchoolYearById(Context.SchoolYearId.Value);
            var user       = MasterLocator.UserService.GetBySisUserId(person.UserId.Value, Context.DistrictId);

            if (BaseSecurity.IsDistrictOrTeacher(Context))
            {
                person.Email = user.Login;
            }
            else
            {
                person.Email = user.Id + "@chalkable.com";
            }

            return(Json(CurrentPersonViewData.Create(person, district, school, schoolYear, Context.Claims)));
        }
Exemplo n.º 4
0
 public IList <Address> GetAddress()
 {
     if (!BaseSecurity.IsDistrictOrTeacher(Context))
     {
         throw new ChalkableSecurityException();
     }
     return(DoRead(u => new DataAccessBase <Address>(u).GetAll()));
 }
Exemplo n.º 5
0
 private void EnsureInDeleteAccess(AnnouncementComment comment, AnnouncementTypeEnum?type = null)
 {
     EnsureInCreateAccess(comment.AnnouncementRef, type);
     if (!BaseSecurity.IsDistrictOrTeacher(Context))
     {
         throw new ChalkableSecurityException();
     }
 }
 private IList <TAnnouncement> PrepareRecipientsData <TAnnouncement>(IList <TAnnouncement> anns) where TAnnouncement : AnnouncementComplex
 {
     if (BaseSecurity.IsDistrictOrTeacher(Context))
     {
         var recipients = DoRead(u => new SupplementalAnnouncementRecipientDataAccess(u).GetRecipientsByAnnouncementIds(anns.Select(x => x.Id).ToList()));
         foreach (var announcementDetailse in anns)
         {
             announcementDetailse.SupplementalAnnouncementData.Recipients = recipients
                                                                            .Where(x => x.SupplementalAnnouncementRef == announcementDetailse.Id)
                                                                            .Select(x => x.Recipient).ToList();
         }
     }
     return(anns);
 }
Exemplo n.º 7
0
        public ActionResult AttachSettings(int announcementId, int?announcementType)
        {
            Trace.Assert(Context.PersonId.HasValue);

            var assesmentId          = (!ApplicationSecurity.HasStudyCenterAccess(Context) && !ApplicationSecurity.HasAssessmentEnabled(Context)) ? null : MasterLocator.ApplicationService.GetAssessmentId();
            var type                 = (AnnouncementTypeEnum?)announcementType ?? AnnouncementTypeEnum.Class;
            var canAddStandard       = SchoolLocator.GetAnnouncementService(type).CanAddStandard(announcementId);
            var isAppEnabled         = BaseSecurity.IsDistrictOrTeacher(Context) && Context.SCEnabled;
            var isFileCabinetEnabled = Context.Role == CoreRoles.TEACHER_ROLE; //only teacher can use file cabinet for now

            var apps = MasterLocator.ApplicationService.GetApplications(live: true).ToList();

            apps = apps.Where(app => MasterLocator.ApplicationService.HasExternalAttachMode(app)).ToList();
            return(Json(AttachSettingsViewData.Create(assesmentId, canAddStandard, isAppEnabled, isFileCabinetEnabled, apps)));
        }
Exemplo n.º 8
0
        public void DeleteComments(IList <int> commentsIds, int teacherId)
        {
            if (!Context.PersonId.HasValue)
            {
                throw new UnassignedUserException();
            }
            if (!BaseSecurity.IsDistrictOrTeacher(Context))
            {
                throw new ChalkableSecurityException();
            }
            var syId = ServiceLocator.SchoolYearService.GetCurrentSchoolYear().Id;

            foreach (var commentId in commentsIds)
            {
                ConnectorLocator.SectionCommentConnector.DeleteComment(syId, teacherId, commentId);
            }
        }
Exemplo n.º 9
0
        protected LessonPlanDataAccess CreateLessonPlanDataAccess(UnitOfWork unitOfWork, bool?ownedOnly = null)
        {
            Trace.Assert(Context.SchoolYearId.HasValue);
            if (BaseSecurity.IsDistrictOrTeacher(Context))
            {
                if (Context.Claims.HasPermission(ClaimInfo.VIEW_CLASSROOM_ADMIN) || Context.Claims.HasPermission(ClaimInfo.MAINTAIN_CLASSROOM_ADMIN))
                {
                    return(new LessonPlanForAdminDataAccess(unitOfWork, Context.SchoolYearId.Value, ownedOnly));
                }
                if (Context.Claims.HasPermission(ClaimInfo.VIEW_CLASSROOM) || Context.Claims.HasPermission(ClaimInfo.MAINTAIN_CLASSROOM))
                {
                    return(new LessonPlanForTeacherDataAccess(unitOfWork, Context.SchoolYearId.Value));
                }
            }
            if (Context.Role == CoreRoles.STUDENT_ROLE)
            {
                return(new LessonPlanForStudentDataAccess(unitOfWork, Context.SchoolYearId.Value));
            }

            throw new ChalkableException("Not supported role for lesson plan");
        }
Exemplo n.º 10
0
        protected static ClassAnnouncementDataAccess CreateClassAnnouncementDataAccess(IServiceLocatorSchool locator, UnitOfWork unitOfWork)
        {
            var context = locator.Context;

            Trace.Assert(context.SchoolYearId.HasValue);
            if (BaseSecurity.IsDistrictOrTeacher(locator.Context))
            {
                if (context.Claims.HasPermission(ClaimInfo.VIEW_CLASSROOM_ADMIN) || context.Claims.HasPermission(ClaimInfo.MAINTAIN_CLASSROOM_ADMIN))
                {
                    return(new ClassAnnouncementForAdminDataAccess(unitOfWork, context.SchoolYearId.Value));
                }
                if (context.Claims.HasPermission(ClaimInfo.VIEW_CLASSROOM) || context.Claims.HasPermission(ClaimInfo.MAINTAIN_CLASSROOM))
                {
                    return(new ClassAnnouncementForTeacherDataAccess(unitOfWork, context.SchoolYearId.Value));
                }
            }
            if (context.Role == CoreRoles.STUDENT_ROLE)
            {
                return(new ClassAnnouncementForStudentDataAccess(unitOfWork, context.SchoolYearId.Value));
            }

            throw new ChalkableSecurityException("Current user has no permission to view or edit activities");
        }
Exemplo n.º 11
0
        public AnnouncementQnA Answer(int announcementQnAId, AnnouncementTypeEnum announcementType, string question, string answer)
        {
            Trace.Assert(Context.PersonId.HasValue);

            using (var uow = Update())
            {
                var da     = new AnnouncementQnADataAccess(uow);
                var annQnA = GetAnnouncementQnA(announcementQnAId);
                // todo: think about security
                if (!CanEditQuestion(annQnA, uow))
                {
                    throw new ChalkableSecurityException();
                }

                annQnA.State    = AnnouncementQnAState.Answered;
                annQnA.Question = question;
                if ((BaseSecurity.IsDistrictOrTeacher(Context)) && (!annQnA.AnswererRef.HasValue || annQnA.AnswererRef == Context.PersonId))
                {
                    var answerer = new PersonDataAccess(uow).GetById(Context.PersonId.Value);
                    annQnA.Answerer     = answerer;
                    annQnA.AnswererRef  = answerer.Id;
                    annQnA.AnsweredTime = Context.NowSchoolTime;
                    annQnA.Answer       = answer;
                }
                da.Update(annQnA);
                uow.Commit();
                var  ann = ServiceLocator.GetAnnouncementService(announcementType).GetAnnouncementById(annQnA.AnnouncementRef);
                bool visibleForStudent = (ann is LessonPlan && (ann as LessonPlan).VisibleForStudent) ||
                                         (ann is ClassAnnouncement && (ann as ClassAnnouncement).VisibleForStudent) ||
                                         (ann is AdminAnnouncement);
                if (visibleForStudent)
                {
                    ServiceLocator.NotificationService.AddAnnouncementNotificationAnswerToStudent(annQnA.Id, annQnA.AnnouncementRef, announcementType);
                }
                return(annQnA);
            }
        }
Exemplo n.º 12
0
 protected virtual bool CanGetInfo(int personId)
 {
     return(BaseSecurity.IsDistrictOrTeacher(SchoolLocator.Context) || SchoolLocator.Context.PersonId == personId);
 }