Exemplo n.º 1
0
 public static IList<TblPermissions> AllPermissionsForCourse(TblCourses course)
 {
     return ServerModel.DB.Query<TblPermissions>(
                 new CompareCondition<int>(
                    DataObject.Schema.CourseRef,
                    new ValueCondition<int>(course.ID), COMPARE_KIND.EQUAL));
 }
        public override void Loaded()
        {
            base.Loaded();

            course = ServerModel.DB.Load<TblCourses>(CourseID);
            Caption.Value = pageCaption.Replace("{0}", course.Name);
            Description.Value = pageDescription.
                Replace("{0}", course.Name);
            Title.Value = Caption.Value;
        }
Exemplo n.º 3
0
 public static IList<TblPermissions> CurrentUserPermissionsForCourse(TblCourses course)
 {
     return ServerModel.DB.Query<TblPermissions>(
           new AndCondtion(
              new CompareCondition<int>(
                    DataObject.Schema.CourseRef,
                    new ValueCondition<int>(course.ID), COMPARE_KIND.EQUAL),
              new CompareCondition<int>(
                    DataObject.Schema.OwnerUserRef,
                    new ValueCondition<int>(ServerModel.User.Current.ID), COMPARE_KIND.EQUAL)));
 }
Exemplo n.º 4
0
    void Initialize()
    {
      TblCourses course = new TblCourses
      {
        Name = "course"
      };
      ServerModel.DB.Insert(course);

      TblOrganizations organisation = new TblOrganizations
      {
        CourseRef = course.ID,
        Title = "organisation"
      };
      ServerModel.DB.Insert(organisation);

      TblResources resource = new TblResources
      {
        CourseRef = course.ID,
        Type = "bob",
        Identifier = "resource"
      };
      ServerModel.DB.Insert(resource);

      TblItems item = new TblItems
      {
        OrganizationRef = organisation.ID,
        ResourceRef = resource.ID,
        Title = "item"
      };
      ServerModel.DB.Insert(item);

      TblLearnerAttempts attempt = new TblLearnerAttempts
      {
        //bug with foreign keys!
      };
      ServerModel.DB.Insert(attempt);

      TblLearnerSessions session = new TblLearnerSessions
      {
        ItemRef = item.ID,
        LearnerAttemptRef = attempt.ID
      };
      ServerModel.DB.Insert(session);
      currentSession = session;

      TblUsers user = GetUniqueUserForTesting();
      ServerModel.DB.Insert(user);

      sessionID = session.ID;
      userID = user.ID;
    }
Exemplo n.º 5
0
        private static int Store(string name, string description)
        {
            var c = new TblCourses
            {
                Name = name,
                Description = description,
                UploadDate = DateTime.Now,
                Version = 1
            };

            ServerModel.DB.Insert(c);

            return c.ID;
        }
Exemplo n.º 6
0
        private static int Store(string name, string description)
        {
            TblCourses t = new TblCourses
            {
                Name        = name,
                Description = description,
                UploadDate  = DateTime.Now,
                Version     = 1
            };

            ServerModel.DB.Insert(t);

            return(t.ID);
        }
Exemplo n.º 7
0
        public override void Loaded()
        {
            base.Loaded();

            course  = ServerModel.DB.Load <TblCourses>(CourseId);
            teacher = ServerModel.DB.Load <TblUsers>(TeacherId);

            Caption.Value = pageCaption.
                            Replace("{0}", course.Name).
                            Replace("{1}", teacher.DisplayName);
            Description.Value = pageDescription.
                                Replace("{0}", course.Name).
                                Replace("{1}", teacher.DisplayName);
            Title.Value = Caption.Value;

            fillOperationsTable();
        }
Exemplo n.º 8
0
        public override void Loaded()
        {
            base.Loaded();

            course = ServerModel.DB.Load<TblCourses>(CourseId);
            teacher = ServerModel.DB.Load<TblUsers>(TeacherId);

            Caption.Value = pageCaption.
                Replace("{0}", course.Name).
                Replace("{1}", teacher.DisplayName);
            Description.Value = pageDescription.
                Replace("{0}", course.Name).
                Replace("{1}", teacher.DisplayName);
            Title.Value = Caption.Value;

            fillOperationsTable();
        }
Exemplo n.º 9
0
        public static TblPermissions CurrentUserPermissionForCourse(TblCourses course, FxCourseOperations operation)
        {
            IList <TblPermissions> permissions = ServerModel.DB.Query <TblPermissions>(
                new AndCondition(
                    new CompareCondition <int>(
                        DataObject.Schema.OwnerUserRef,
                        new ValueCondition <int>(ServerModel.User.Current.ID), COMPARE_KIND.EQUAL),
                    new CompareCondition <int>(
                        DataObject.Schema.CourseOperationRef,
                        new ValueCondition <int>(operation.ID), COMPARE_KIND.EQUAL),
                    new CompareCondition <int>(
                        DataObject.Schema.CourseRef,
                        new ValueCondition <int>(course.ID), COMPARE_KIND.EQUAL)));

            if (permissions.Count == 0)
            {
                return(null);
            }

            return(permissions[0]);
        }
Exemplo n.º 10
0
        public override void Loaded()
        {
            base.Loaded();
            teacher = ServerModel.DB.Load<TblUsers>(TeacherId);
            if (CourseId != -1)
            {
                course = ServerModel.DB.Load<TblCourses>(CourseId);
                Caption.Value = pageCaption.
                    Replace("{0}", courseStr).
                    Replace("{1}", course.Name).
                    Replace("{2}", teacher.DisplayName);
                Description.Value = pageDescription.
                    Replace("{0}", courseStr).
                    Replace("{1}", course.Name).
                    Replace("{2}", teacher.DisplayName);

                fillCourseOperationsTable();
            }
            if (CurriculumId != -1)
            {
                curriculum = ServerModel.DB.Load<TblCurriculums>(CurriculumId);
                Caption.Value = pageCaption.
                    Replace("{0}", curriculumStr).
                    Replace("{1}", curriculum.Name).
                    Replace("{2}", teacher.DisplayName);
                Description.Value = pageDescription.
                    Replace("{0}", curriculumStr).
                    Replace("{1}", curriculum.Name).
                    Replace("{2}", teacher.DisplayName);

                fillCurriculumOperationsTable();
            }

            Title.Value = Caption.Value;

        }
Exemplo n.º 11
0
        public void GetObjectForUserIncludedInGroupTest()
        {
            using (var c = new DataObjectCleaner())
            {
                var user = GetUniqueUserForTesting();
                c.Insert(user);

                var group = new TblGroups {
                    Name = "test group with user"
                };
                c.Insert(group);
                ServerModel.DB.Link(user, group);

                var course = new TblCourses
                {
                    Name        = "test_course",
                    Description = "test description"
                };
                c.Insert(course);

                PermissionsManager.Grand(course, FxCourseOperations.Use, null, group.ID, DateTimeInterval.Full);
                Assert.AreEqual(0, PermissionsManager.GetObjectsForGroup(SECURED_OBJECT_TYPE.COURSE, group.ID, FxCourseOperations.Modify.ID, null).Count);

                var ids1 = PermissionsManager.GetObjectsForGroup(SECURED_OBJECT_TYPE.COURSE, group.ID, FxCourseOperations.Use.ID, null);
                Assert.AreEqual(1, ids1.Count);
                Assert.AreEqual(course.ID, ids1[0]);

                var ids2 = PermissionsManager.GetObjectsForUser(SECURED_OBJECT_TYPE.COURSE, user.ID, null, null);
                Assert.AreEqual(1, ids2.Count);
                Assert.AreEqual(course.ID, ids2[0]);

                var ids3 = PermissionsManager.GetObjectsForUser(SECURED_OBJECT_TYPE.COURSE, user.ID, FxCourseOperations.Use.ID, null);
                Assert.AreEqual(1, ids3.Count);
                Assert.AreEqual(course.ID, ids3[0]);
            }
        }
Exemplo n.º 12
0
        public void SafeDeleteAndPermissionManagerTest_GetGroupsForObject()
        {
            using (var c = new DataObjectCleaner())
            {
                var course = new TblCourses { Name = "TestCourse3" };
                ServerModel.DB.Insert(course);

                var g = new TblGroups { Name = "TestGroup3" };
                ServerModel.DB.Insert(g);

                PermissionsManager.Grand(course, FxCourseOperations.Use, null, g.ID, DateTimeInterval.Full);
                PermissionsManager.Grand(course, FxCourseOperations.Modify, null, g.ID, DateTimeInterval.Full);

                var res1 = PermissionsManager.GetGroupsForObject(SECURED_OBJECT_TYPE.COURSE, course.ID, null, null);
                Assert.AreEqual(1, res1.Count);
                Assert.AreEqual(g.ID, res1[0]);

                ServerModel.DB.Delete<TblCourses>(course.ID);

                var res2 = PermissionsManager.GetGroupsForObject(SECURED_OBJECT_TYPE.COURSE, course.ID, null, null);
                Assert.AreEqual(0, res2.Count);
            }
        }
Exemplo n.º 13
0
        public void GetGroupPermissionsTest()
        {
            using (var cl = new DataObjectCleaner())
            {
                var c = new TblCourses
                            {
                                Name = "test course",
                                Description = "unit test course"
                            };
                cl.Insert(c);

                var g = new TblGroups
                            {
                                Name = "test group"
                            };
                cl.Insert(g);

                PermissionsManager.Grand(c, FxCourseOperations.Modify, null, g.ID, new DateTimeInterval(DateTime.Now.AddDays(-1), DateTime.Now.AddDays(1)));

                var ids = PermissionsManager.GetObjectsForGroup(SECURED_OBJECT_TYPE.COURSE, g.ID, FxCourseOperations.Modify.ID, DateTime.Now);
                Assert.AreEqual(1, ids.Count);
                Assert.AreEqual(c.ID, ids[0]);

                ids = PermissionsManager.GetObjectsForGroup(SECURED_OBJECT_TYPE.COURSE, g.ID, null, null);
                Assert.AreEqual(1, ids.Count);
                Assert.AreEqual(c.ID, ids[0]);
            }
        }
Exemplo n.º 14
0
 public IdendtityNode(TblCourses course)
     : this(course.Name, course.ID, course.Description)
 {
     Type = NodeType.Course;
 }
Exemplo n.º 15
0
 public IdendtityNode(TblCourses course)
     : this(course.Name, course.ID, course.Description)
 {
     Type = NodeType.Course;
     
 }
Exemplo n.º 16
0
        public static IList <TblThemes> ThemesOfCourse(TblCourses course)
        {
            List <int> themesIDs = ServerModel.DB.LookupIds <TblThemes>(course, null);

            return(ServerModel.DB.Load <TblThemes>(themesIDs));
        }
Exemplo n.º 17
0
        public static bool CanChildDelegateCourse(TblPermissions parentPermission, TblUsers child, TblCourses course)
        {
            IList <TblPermissions> childPermissions =
                ServerModel.DB.Query <TblPermissions>(
                    new AndCondition(
                        new CompareCondition <int>(
                            DataObject.Schema.OwnerUserRef,
                            new ValueCondition <int>(child.ID), COMPARE_KIND.EQUAL),
                        new CompareCondition <int>(
                            DataObject.Schema.CourseRef,
                            new ValueCondition <int>(course.ID), COMPARE_KIND.EQUAL)));

            foreach (TblPermissions childPermission in childPermissions)
            {
                if (childPermission.ParentPermitionRef.HasValue &&
                    childPermission.ParentPermitionRef.Value == parentPermission.ID)
                {
                    return(childPermission.CanBeDelagated);
                }
            }

            return(false);
        }
Exemplo n.º 18
0
 public static IList <TblThemes> ThemesOfCourse(TblCourses course)
 {
     return(ServerModel.DB.Query <TblThemes>(new CompareCondition <int>(
                                                 DataObject.Schema.CourseRef,
                                                 new ValueCondition <int>(course.ID), COMPARE_KIND.EQUAL)));
 }
Exemplo n.º 19
0
        public static bool CanChildDelegateCourse(TblPermissions parentPermission, TblUsers child, TblCourses course)
        {
            IList<TblPermissions> childPermissions =
                ServerModel.DB.Query<TblPermissions>(
                      new AndCondition(
                         new CompareCondition<int>(
                            DataObject.Schema.OwnerUserRef,
                            new ValueCondition<int>(child.ID), COMPARE_KIND.EQUAL),
                         new CompareCondition<int>(
                            DataObject.Schema.CourseRef,
                            new ValueCondition<int>(course.ID), COMPARE_KIND.EQUAL)));

            foreach (TblPermissions childPermission in childPermissions)
            {
                if (childPermission.ParentPermitionRef.HasValue
                    && childPermission.ParentPermitionRef.Value == parentPermission.ID)
                {
                    return childPermission.CanBeDelagated;
                }
            }

            return false;
        }
Exemplo n.º 20
0
        public void GetObjectForUserIncludedInGroupTest()
        {
            using (var c = new DataObjectCleaner())
            {
                var user = GetUniqueUserForTesting();
                c.Insert(user);

                var group = new TblGroups {Name = "test group with user"};
                c.Insert(group);
                ServerModel.DB.Link(user, group);

                var course = new TblCourses
                {
                    Name = "test_course",
                    Description = "test description"
                };
                c.Insert(course);

                PermissionsManager.Grand(course, FxCourseOperations.Use, null, group.ID, DateTimeInterval.Full);
                Assert.AreEqual(0, PermissionsManager.GetObjectsForGroup(SECURED_OBJECT_TYPE.COURSE, group.ID, FxCourseOperations.Modify.ID, null).Count);

                var ids1 = PermissionsManager.GetObjectsForGroup(SECURED_OBJECT_TYPE.COURSE, group.ID, FxCourseOperations.Use.ID, null);
                Assert.AreEqual(1, ids1.Count);
                Assert.AreEqual(course.ID, ids1[0]);

                var ids2 = PermissionsManager.GetObjectsForUser(SECURED_OBJECT_TYPE.COURSE, user.ID, null, null);                
                Assert.AreEqual(1, ids2.Count);
                Assert.AreEqual(course.ID, ids2[0]);

                var ids3 = PermissionsManager.GetObjectsForUser(SECURED_OBJECT_TYPE.COURSE, user.ID, FxCourseOperations.Use.ID, null);
                Assert.AreEqual(1, ids3.Count);
                Assert.AreEqual(course.ID, ids3[0]);
            }
        }
Exemplo n.º 21
0
        public override void Loaded()
        {
            base.Loaded();

            string message = "";

            if (CourseId != -1)
            {
                course        = ServerModel.DB.Load <TblCourses>(CourseId);
                Caption.Value = pageCaption.
                                Replace("{0}", courseStr).
                                Replace("{1}", course.Name);
                Description.Value = pageDescription.
                                    Replace("{0}", courseStr).
                                    Replace("{1}", course.Name);

                foreach (TblPermissions permission in TeacherHelper.CurrentUserPermissionsForCourse(course))
                {
                    FxCourseOperations operation = ServerModel.DB.Load <FxCourseOperations>(permission.CourseOperationRef.Value);
                    if (permission.ParentPermitionRef.HasValue)
                    {
                        TblPermissions parentPermission = ServerModel.DB.Load <TblPermissions>(permission.ParentPermitionRef.Value);
                        TblUsers       parent           = ServerModel.DB.Load <TblUsers>(parentPermission.OwnerUserRef.Value);
                        message += grantedObject.
                                   Replace("{0}", parent.DisplayName).
                                   Replace("{1}", operation.Name).
                                   Replace("{2}", courseStr) + breakLine;
                    }
                    else
                    {
                        message += ownObject.Replace("{0}", courseStr).Replace("{1}", operation.Name) + breakLine;
                    }
                }
            }

            if (CurriculumId != -1)
            {
                curriculum    = ServerModel.DB.Load <TblCurriculums>(CurriculumId);
                Caption.Value = pageCaption.
                                Replace("{0}", curriculumStr).
                                Replace("{1}", curriculum.Name);
                Description.Value = pageDescription.
                                    Replace("{0}", curriculumStr).
                                    Replace("{1}", curriculum.Name);

                foreach (TblPermissions permission in TeacherHelper.CurrentUserPermissionsForCurriculum(curriculum))
                {
                    FxCurriculumOperations operation = ServerModel.DB.Load <FxCurriculumOperations>(permission.CurriculumOperationRef.Value);
                    if (permission.ParentPermitionRef.HasValue)
                    {
                        TblPermissions parentPermission = ServerModel.DB.Load <TblPermissions>(permission.ParentPermitionRef.Value);
                        TblUsers       parent           = ServerModel.DB.Load <TblUsers>(parentPermission.OwnerUserRef.Value);
                        message += grantedObject.
                                   Replace("{0}", parent.DisplayName).
                                   Replace("{1}", operation.Name).
                                   Replace("{2}", curriculumStr) + breakLine;
                    }
                    else
                    {
                        message += ownObject.Replace("{0}", curriculumStr).Replace("{1}", operation.Name) + breakLine;
                    }
                }
            }

            Message.Value = message;
            Title.Value   = Caption.Value;

            fillTeachersTable();
        }
Exemplo n.º 22
0
        public static TblPermissions GetPermissionForCourse(TblPermissions parentPermission, TblUsers user, TblCourses course, FxCourseOperations operation)
        {
            IList<TblPermissions> permissions = ServerModel.DB.Query<TblPermissions>(
                           new AndCondition(
                              new CompareCondition<int>(
                                 DataObject.Schema.OwnerUserRef,
                                 new ValueCondition<int>(user.ID), COMPARE_KIND.EQUAL),
                              new CompareCondition<int>(
                                 DataObject.Schema.CourseOperationRef,
                                 new ValueCondition<int>(operation.ID), COMPARE_KIND.EQUAL),
                              new CompareCondition<int>(
                                 DataObject.Schema.CourseRef,
                                 new ValueCondition<int>(course.ID), COMPARE_KIND.EQUAL),
                              new CompareCondition<int>(
                                 DataObject.Schema.ParentPermitionRef,
                                 new ValueCondition<int>(parentPermission.ID), COMPARE_KIND.EQUAL)));

            if (permissions.Count == 0)
            {
                return null;
            }

            return permissions[0];
        }
Exemplo n.º 23
0
        public override void Loaded()
        {
            base.Loaded();

            string message = "";
            if (CourseId != -1)
            {
                course = ServerModel.DB.Load<TblCourses>(CourseId);
                Caption.Value = pageCaption.
                    Replace("{0}", courseStr).
                    Replace("{1}", course.Name);
                Description.Value = pageDescription.
                    Replace("{0}", courseStr).
                    Replace("{1}", course.Name);
                              
                foreach (TblPermissions permission in TeacherHelper.CurrentUserPermissionsForCourse(course))
                {
                    FxCourseOperations operation = ServerModel.DB.Load<FxCourseOperations>(permission.CourseOperationRef.Value);
                    if (permission.ParentPermitionRef.HasValue)
                    {
                        TblPermissions parentPermission = ServerModel.DB.Load<TblPermissions>(permission.ParentPermitionRef.Value);
                        TblUsers parent = ServerModel.DB.Load<TblUsers>(parentPermission.OwnerUserRef.Value);
                        message += grantedObject.
                            Replace("{0}", parent.DisplayName).
                            Replace("{1}", operation.Name).
                            Replace("{2}", courseStr) + breakLine;
                    }
                    else
                    {
                        message += ownObject.Replace("{0}", courseStr).Replace("{1}", operation.Name) + breakLine;
                    }
                }
            }

            if (CurriculumId != -1)
            {
                curriculum = ServerModel.DB.Load<TblCurriculums>(CurriculumId);
                Caption.Value = pageCaption.
                    Replace("{0}", curriculumStr).
                    Replace("{1}", curriculum.Name);
                Description.Value = pageDescription.
                    Replace("{0}", curriculumStr).
                    Replace("{1}", curriculum.Name);

                foreach (TblPermissions permission in TeacherHelper.CurrentUserPermissionsForCurriculum(curriculum))
                {
                    FxCurriculumOperations operation = ServerModel.DB.Load<FxCurriculumOperations>(permission.CurriculumOperationRef.Value);
                    if (permission.ParentPermitionRef.HasValue)
                    {
                        TblPermissions parentPermission = ServerModel.DB.Load<TblPermissions>(permission.ParentPermitionRef.Value);
                        TblUsers parent = ServerModel.DB.Load<TblUsers>(parentPermission.OwnerUserRef.Value);
                        message += grantedObject.
                            Replace("{0}", parent.DisplayName).
                            Replace("{1}", operation.Name).
                            Replace("{2}", curriculumStr) + breakLine;
                    }
                    else
                    {
                        message += ownObject.Replace("{0}", curriculumStr).Replace("{1}", operation.Name) + breakLine;
                    }
                }
            }

            Message.Value = message;
            Title.Value = Caption.Value;

            fillTeachersTable();
        }
Exemplo n.º 24
0
 public static IList<TblThemes> ThemesOfCourse(TblCourses course)
 {
     List<int> themesIDs = ServerModel.DB.LookupIds<TblThemes>(course, null);
     return ServerModel.DB.Load<TblThemes>(themesIDs);
 }