Exemplo n.º 1
0
        public static void Grand <TSecuredDataObject, TOperation>([NotNull] TSecuredDataObject dataObject, [NotNull] TOperation operation, int?userID, int?groupID, DateTimeInterval interval)
            where TSecuredDataObject : class, ISecuredDataObject <TOperation>
            where TOperation : class, IFxDataObject
        {
            if (dataObject == null)
            {
                throw new ArgumentNullException("dataObject");
            }

            if (operation == null)
            {
                throw new ArgumentNullException("operation");
            }

            if ((userID == null && groupID == null) || (userID != null && groupID != null))
            {
                throw new ArgumentException(Translations.PermissionsManager_Grand_One_and_only_one_of_parameters__userID__groupID__must_be_specified);
            }
            var doType = ObjectTypeHelper.GetObjectType(dataObject.GetType());
            var p      = new TblPermissions
            {
                OwnerUserRef    = userID,
                OwnerGroupRef   = groupID,
                CanBeDelagated  = true,
                WorkingInterval = interval
            };

            p.SetObjectID(doType, dataObject.ID);
            p.SetOperationID(doType, operation.ID);
            ServerModel.DB.Insert(p);
        }
Exemplo n.º 2
0
    private void ApppyButton_Click(object sender, EventArgs e)
    {
        Button button       = sender as Button;
        int    permissionID = int.Parse(button.ID.Replace(applyChar, ""));

        GMDatePicker sinceDatePicker = (button.Parent.Parent as TableRow).Cells[2].Controls[0] as GMDatePicker;
        GMDatePicker tillDatePicker  = (button.Parent.Parent as TableRow).Cells[4].Controls[0] as GMDatePicker;

        TblPermissions permission = ServerModel.DB.Load <TblPermissions>(permissionID);

        if (sinceDatePicker.IsNull)
        {
            permission.DateSince = null;
        }
        else
        {
            permission.DateSince = sinceDatePicker.Date;
            sinceDatePicker.Date = sinceDatePicker.Date;
        }

        if (tillDatePicker.IsNull)
        {
            permission.DateTill = null;
        }
        else
        {
            permission.DateTill = tillDatePicker.Date;
            tillDatePicker.Date = tillDatePicker.Date;
        }

        ServerModel.DB.Update <TblPermissions>(permission);
    }
Exemplo n.º 3
0
        private void fillOperationsTable()
        {
            Operations.Rows.Clear();

            foreach (FxCourseOperations operation in TeacherHelper.CourseOperations())
            {
                TableRow  operationRow  = new TableRow();
                TableCell operationCell = new TableCell();

                CheckBox operationCheckBox = new CheckBox();
                operationCheckBox.Text = operation.Name;
                operationCheckBox.ID   = operation.ID.ToString();

                TblPermissions permission = TeacherHelper.GetPermissionForCourse(course, operation);
                if (permission == null || !permission.CanBeDelagated)
                {
                    operationCheckBox.Enabled = false;
                }
                else
                {
                    operationCheckBox.Checked = TeacherHelper.AreParentAndChildByCourse(permission, teacher, course);
                }
                operationCell.Controls.Add(operationCheckBox);

                operationRow.Cells.Add(operationCell);
                Operations.Rows.Add(operationRow);
            }
        }
Exemplo n.º 4
0
        public static void Share(TblPermissions myPermission, int userID, bool canBeDelegated)
        {
            TblPermissions sharedPermission = myPermission.Clone() as TblPermissions;

            sharedPermission.CanBeDelagated = canBeDelegated;
            if (sharedPermission.OwnerGroupRef != null)
            {
                throw new Exception(Translations.TeacherHelper_Share_Only_user_based_permissions_can_be_shared);
            }
            sharedPermission.OwnerUserRef       = userID;
            sharedPermission.ParentPermitionRef = myPermission.ID;
            ServerModel.DB.Insert <TblPermissions>(sharedPermission);
        }
Exemplo n.º 5
0
        public static void RemoveChildPermissions(TblPermissions parentPermission)
        {
            IList <TblPermissions> childPermissions = ServerModel.DB.Query <TblPermissions>(
                new CompareCondition <int>(
                    DataObject.Schema.ParentPermitionRef,
                    new ValueCondition <int>(parentPermission.ID), COMPARE_KIND.EQUAL));

            foreach (TblPermissions childPermission in childPermissions)
            {
                RemoveChildPermissions(childPermission);
                ServerModel.DB.Delete <TblPermissions>(childPermission.ID);
            }
        }
Exemplo n.º 6
0
        public static void Share(TblPermissions myPermission, int userID, bool canBeDelegated)
        {
            TblPermissions sharedPermission = myPermission.Clone() as TblPermissions;

            sharedPermission.CanBeDelagated = canBeDelegated;
            if (sharedPermission.OwnerGroupRef != null)
            {
                throw new Exception("Only user based permissions can be shared");
            }
            sharedPermission.OwnerUserRef       = userID;
            sharedPermission.ParentPermitionRef = myPermission.ID;
            ServerModel.DB.Insert <TblPermissions>(sharedPermission);
        }
Exemplo n.º 7
0
        private void fillCourseOperationsTable()
        {
            Operations.Rows.Clear();

            foreach (FxCourseOperations operation in TeacherHelper.CourseOperations())
            {
                TableRow  operationRow  = new TableRow();
                TableCell operationCell = new TableCell();

                CheckBox operationCheckBox = new CheckBox();
                operationCheckBox.Text = operation.Name;

                operationCheckBox.AutoPostBack    = true;
                operationCheckBox.CheckedChanged += new EventHandler(operationCheckBox_CheckedChanged);

                CheckBox delegateCheckBox = new CheckBox();
                delegateCheckBox.Text = delegateStr;

                TblPermissions permission = TeacherHelper.CurrentUserPermissionForCourse(course, operation);
                if (permission == null || !permission.CanBeDelagated)
                {
                    operationCheckBox.Enabled = false;
                    delegateCheckBox.Enabled  = false;
                }
                else
                {
                    operationCheckBox.ID      = permission.ID.ToString();
                    operationCheckBox.Checked = TeacherHelper.AreParentAndChildByCourse(permission, teacher, course);
                    if (operationCheckBox.Checked)
                    {
                        delegateCheckBox.Checked = TeacherHelper.CanChildDelegateCourse(permission, teacher, course);
                    }
                    else
                    {
                        delegateCheckBox.Enabled = false;
                    }
                }

                TableCell leftCell = new TableCell();
                leftCell.HorizontalAlign = HorizontalAlign.Left;
                leftCell.Controls.Add(operationCheckBox);

                TableCell rightCell = new TableCell();
                rightCell.HorizontalAlign = HorizontalAlign.Right;
                rightCell.Controls.Add(delegateCheckBox);

                operationRow.Cells.Add(leftCell);
                operationRow.Cells.Add(rightCell);
                Operations.Rows.Add(operationRow);
            }
        }
Exemplo n.º 8
0
        private void UpdateCurriculumButton_Click()
        {
            foreach (TableRow operationRow in Operations.Rows)
            {
                CheckBox operationCheckBox = operationRow.Cells[0].Controls[0] as CheckBox;
                CheckBox delegateCheckBox  = operationRow.Cells[1].Controls[0] as CheckBox;

                if (operationCheckBox.Enabled)
                {
                    TblPermissions         parentPermission = ServerModel.DB.Load <TblPermissions>(int.Parse(operationCheckBox.ID));
                    FxCurriculumOperations operation        = ServerModel.DB.Load <FxCurriculumOperations>(parentPermission.CurriculumOperationRef.Value);

                    TblPermissions childPermission = TeacherHelper.GetPermissionForCurriculum(parentPermission, teacher, curriculum, operation);
                    if (operationCheckBox.Checked)
                    {
                        if (childPermission == null)
                        {
                            TeacherHelper.Share(TeacherHelper.CurrentUserPermissionForCurriculum(curriculum, operation), teacher.ID, delegateCheckBox.Checked);
                        }
                        else
                        {
                            if (childPermission.CanBeDelagated && !delegateCheckBox.Checked)
                            {
                                TeacherHelper.RemoveChildPermissions(childPermission);
                            }

                            childPermission.CanBeDelagated = delegateCheckBox.Checked;
                            ServerModel.DB.Update <TblPermissions>(childPermission);
                        }
                    }
                    else
                    {
                        if (childPermission != null)
                        {
                            TeacherHelper.RemoveChildPermissions(childPermission);
                            ServerModel.DB.Delete <TblPermissions>(childPermission.ID);
                        }
                    }
                }
            }

            Redirect(BackUrl);
        }
Exemplo n.º 9
0
        public void SimpleDBOperationsTest()
        {
            using (var c = new DataObjectCleaner())
            {
                var r = new TblPermissions
                            {
                                CanBeDelagated = false
                            };
                var r2 = new TblPermissions
                             {
                                 CanBeDelagated = false
                             };
                var r3 = new TblPermissions
                             {
                                 CanBeDelagated = false
                             };
                c.Insert(r);
                c.Insert<TblPermissions>(new[] {r2, r3});
                var id1 = r.ID;
                var id2 = r2.ID;
                var id3 = r3.ID;

                r = ServerModel.DB.Load<TblPermissions>(id1);
                Assert.IsNotNull(r);
                Assert.IsFalse(r.CanBeDelagated);
                var dt1 = DateTime.Now;
                r.DateTill = dt1;
                ServerModel.DB.Update(r);

                r = ServerModel.DB.Load<TblPermissions>(id1);
                AreEqual(r.DateTill, dt1);

                IList<TblPermissions> ls = ServerModel.DB.Load<TblPermissions>(new[] {id2, id3});
                ls[0].DateSince = dt1;
                ls[1].DateTill = dt1;
                ServerModel.DB.Update(ls);

                ls = ServerModel.DB.Load<TblPermissions>(new[] {id2, id3});
                AreEqual(ls[0].DateSince, dt1);
                AreEqual(ls[1].DateTill, dt1);
            }
        }
Exemplo n.º 10
0
        public void SimpleDBOperationsTest()
        {
            using (var c = new DataObjectCleaner())
            {
                var r = new TblPermissions
                {
                    CanBeDelagated = false
                };
                var r2 = new TblPermissions
                {
                    CanBeDelagated = false
                };
                var r3 = new TblPermissions
                {
                    CanBeDelagated = false
                };
                c.Insert(r);
                c.Insert <TblPermissions>(new[] { r2, r3 });
                var id1 = r.ID;
                var id2 = r2.ID;
                var id3 = r3.ID;

                r = ServerModel.DB.Load <TblPermissions>(id1);
                Assert.IsNotNull(r);
                Assert.IsFalse(r.CanBeDelagated);
                var dt1 = DateTime.Now;
                r.DateTill = dt1;
                ServerModel.DB.Update(r);

                r = ServerModel.DB.Load <TblPermissions>(id1);
                AreEqual(r.DateTill, dt1);

                IList <TblPermissions> ls = ServerModel.DB.Load <TblPermissions>(new[] { id2, id3 });
                ls[0].DateSince = dt1;
                ls[1].DateTill  = dt1;
                ServerModel.DB.Update(ls);

                ls = ServerModel.DB.Load <TblPermissions>(new[] { id2, id3 });
                AreEqual(ls[0].DateSince, dt1);
                AreEqual(ls[1].DateTill, dt1);
            }
        }
Exemplo n.º 11
0
        public static void Delegate <TSecuredDataObject, TOperation>(int ownerUserID, [NotNull] TSecuredDataObject dataObject, [NotNull] TOperation operation, int?targetUserID, int?targetGroupID, DateTimeInterval interval)
            where TSecuredDataObject : class, ISecuredDataObject <TOperation>
            where TOperation : class, IFxDataObject
        {
            if (dataObject == null)
            {
                throw new ArgumentNullException("dataObject");
            }

            if ((targetUserID == null && targetGroupID == null) || (targetUserID != null && targetGroupID != null))
            {
                throw new ArgumentException("One and only one of parameters (targetUserID, targetGroupID) must be specified");
            }

            if (operation == null)
            {
                throw new ArgumentNullException("operation");
            }

            var doType = ObjectTypeHelper.GetObjectType(dataObject.GetType());

            var prm = GetPermissions(doType, ownerUserID, null, operation.ID);

            if (prm.Count < 0)
            {
                throw new SecurityException(string.Format("User {0} have no access to do {1} on {2} ID = {3}. Cannot perform delegation", ownerUserID, operation.Name, dataObject.GetType().Name, dataObject.ID));
            }

            var p = new TblPermissions
            {
                CanBeDelagated     = true,
                OwnerGroupRef      = targetGroupID,
                OwnerUserRef       = targetUserID,
                WorkingInterval    = interval,
                ParentPermitionRef = prm[0]
            };

            p.SetObjectID(doType, dataObject.ID);
            p.SetOperationID(doType, operation.ID);
            ServerModel.DB.Insert(p);
        }
Exemplo n.º 12
0
        public static void Delegate <TSecuredDataObject, TOperation>(int ownerUserID, [NotNull] TSecuredDataObject dataObject, [NotNull] TOperation operation, int?targetUserID, int?targetGroupID, DateTimeInterval interval)
            where TSecuredDataObject : class, ISecuredDataObject <TOperation>
            where TOperation : class, IFxDataObject
        {
            if (dataObject == null)
            {
                throw new ArgumentNullException("dataObject");
            }

            if ((targetUserID == null && targetGroupID == null) || (targetUserID != null && targetGroupID != null))
            {
                throw new ArgumentException(Translations.PermissionsManager_Delegate_One_and_only_one_of_parameters__targetUserID__targetGroupID__must_be_specified);
            }

            if (operation == null)
            {
                throw new ArgumentNullException("operation");
            }

            var doType = ObjectTypeHelper.GetObjectType(dataObject.GetType());

            var prm = GetPermissions(doType, ownerUserID, null, operation.ID);

            if (prm.Count < 0)
            {
                throw new SecurityException(string.Format(Translations.PermissionsManager_Delegate_, ownerUserID, operation.Name, dataObject.GetType().Name, dataObject.ID));
            }

            var p = new TblPermissions
            {
                CanBeDelagated     = true,
                OwnerGroupRef      = targetGroupID,
                OwnerUserRef       = targetUserID,
                WorkingInterval    = interval,
                ParentPermitionRef = prm[0]
            };

            p.SetObjectID(doType, dataObject.ID);
            p.SetOperationID(doType, operation.ID);
            ServerModel.DB.Insert(p);
        }
Exemplo n.º 13
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.º 14
0
        public static bool AreParentAndChildByCurriculum(TblPermissions parentPermission, TblUsers child, TblCurriculums curriculum)
        {
            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.CurriculumRef,
                            new ValueCondition <int>(curriculum.ID), COMPARE_KIND.EQUAL)));

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

            return(false);
        }
Exemplo n.º 15
0
        public static TblPermissions GetPermissionForCurriculum(TblPermissions parentPermission, TblUsers user, TblCurriculums curriculum, FxCurriculumOperations 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.CurriculumOperationRef,
                        new ValueCondition <int>(operation.ID), COMPARE_KIND.EQUAL),
                    new CompareCondition <int>(
                        DataObject.Schema.CurriculumRef,
                        new ValueCondition <int>(curriculum.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.º 16
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.º 17
0
        public static bool AreParentAndChildByCurriculum(TblPermissions parentPermission, TblUsers child, TblCurriculums curriculum)
        {
            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.CurriculumRef,
                            new ValueCondition<int>(curriculum.ID), COMPARE_KIND.EQUAL)));

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

            return false;
        }
Exemplo n.º 18
0
    private TableRow buildPermissionRow(TblPermissions permission)
    {
        TableRow operationRow = new TableRow();

        
        Label dateSinceLabel = new Label();
        dateSinceLabel.Text = since + ": ";
        GMDatePicker dateSinceDatePicker = recreateDatePicker(since + permission.ID.ToString());
        Label dateTillLabel = new Label();
        dateTillLabel.Text = till + ": ";
        GMDatePicker dateTillDatePicker = recreateDatePicker(till + permission.ID.ToString());

        TableCell operationNameCell = new TableCell();
        if (permission.StageOperationRef.HasValue)
        {
            FxStageOperations stageOperation =
                            ServerModel.DB.Load<FxStageOperations>(permission.StageOperationRef.Value);
            operationNameCell.Text = stageOperation.Name;
        }
        if (permission.CurriculumOperationRef.HasValue)
        {
            FxCurriculumOperations curriculumOperation =
                            ServerModel.DB.Load<FxCurriculumOperations>(permission.CurriculumOperationRef.Value);
            operationNameCell.Text = curriculumOperation.Name;
        }
        operationRow.Cells.Add(operationNameCell);

        Table layoutTable = new Table();
        TableRow layoutRow = new TableRow();

        TableCell sinceLabelCell = new TableCell();
        sinceLabelCell.Controls.Add(dateSinceLabel);

        TableCell sincePickerCell = new TableCell();
        sincePickerCell.HorizontalAlign = HorizontalAlign.Right;
        sincePickerCell.Controls.Add(dateSinceDatePicker);

        TableCell tillLabelCell = new TableCell();
        tillLabelCell.Controls.Add(dateTillLabel);

        TableCell tillPickerCell = new TableCell();
        tillPickerCell.HorizontalAlign = HorizontalAlign.Right;
        tillPickerCell.Controls.Add(dateTillDatePicker);

        operationRow.Cells.Add(sinceLabelCell);
        operationRow.Cells.Add(sincePickerCell);
        operationRow.Cells.Add(tillLabelCell);
        operationRow.Cells.Add(tillPickerCell);
        if (permission.DateSince.HasValue)
        {
            dateSinceDatePicker.InitialText = permission.DateSince.Value.ToShortDateString();
            dateSinceDatePicker.InitialTimePickerText = permission.DateSince.Value.ToShortTimeString();
        }

        if (permission.DateTill.HasValue)
        {
            dateTillDatePicker.InitialText = permission.DateTill.Value.ToShortDateString();
            dateTillDatePicker.InitialTimePickerText = permission.DateTill.Value.ToShortTimeString();
        }

        TableCell operationCell = new TableCell();

        Button ApppyButton = new Button();
        ApppyButton.ID = applyChar + permission.ID.ToString();
        ApppyButton.Click += new EventHandler(ApppyButton_Click);
        ApppyButton.Text = apply;

        Button RemoveButton = new Button();
        RemoveButton.ID = removeChar + permission.ID.ToString();
        RemoveButton.Click += new EventHandler(RemoveButton_Click);
        RemoveButton.Text = remove;

        operationCell.Controls.Add(ApppyButton);
        operationCell.Controls.Add(RemoveButton);
        operationRow.Cells.Add(operationCell);

        return operationRow;
    }
Exemplo n.º 19
0
        public static void RemoveChildPermissions(TblPermissions parentPermission)
        {
            IList<TblPermissions> childPermissions = ServerModel.DB.Query<TblPermissions>(
                              new CompareCondition<int>(
                                 DataObject.Schema.ParentPermitionRef,
                                 new ValueCondition<int>(parentPermission.ID), COMPARE_KIND.EQUAL));

            foreach (TblPermissions childPermission in childPermissions)
            {
                RemoveChildPermissions(childPermission);
                ServerModel.DB.Delete<TblPermissions>(childPermission.ID);
            }
        }
Exemplo n.º 20
0
        public static TblPermissions GetPermissionForCurriculum(TblPermissions parentPermission, TblUsers user, TblCurriculums curriculum, FxCurriculumOperations 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.CurriculumOperationRef,
                                 new ValueCondition<int>(operation.ID), COMPARE_KIND.EQUAL),
                              new CompareCondition<int>(
                                 DataObject.Schema.CurriculumRef,
                                 new ValueCondition<int>(curriculum.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.º 21
0
 public static void Share(TblPermissions myPermission, int userID, bool canBeDelegated)
 {
     TblPermissions sharedPermission = myPermission.Clone() as TblPermissions;
     sharedPermission.CanBeDelagated = canBeDelegated;
     if (sharedPermission.OwnerGroupRef != null)
     {
         throw new Exception("Only user based permissions can be shared");
     }
     sharedPermission.OwnerUserRef = userID;
     sharedPermission.ParentPermitionRef = myPermission.ID;
     ServerModel.DB.Insert<TblPermissions>(sharedPermission);
 }
Exemplo n.º 22
0
 public DatePeriod(TblPermissions permission)
 {
     _start = permission.DateSince;
     _end = permission.DateTill;
 }
Exemplo n.º 23
0
 public DatePeriod(TblPermissions permission)
 {
     _start = permission.DateSince;
     _end   = permission.DateTill;
 }
Exemplo n.º 24
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.º 25
0
 public static void Share(TblPermissions myPermission, int userID, bool canBeDelegated)
 {
     TblPermissions sharedPermission = myPermission.Clone() as TblPermissions;
     sharedPermission.CanBeDelagated = canBeDelegated;
     if (sharedPermission.OwnerGroupRef != null)
     {
         throw new Exception(Translations.TeacherHelper_Share_Only_user_based_permissions_can_be_shared);
     }
     sharedPermission.OwnerUserRef = userID;
     sharedPermission.ParentPermitionRef = myPermission.ID;
     ServerModel.DB.Insert<TblPermissions>(sharedPermission);
 }
Exemplo n.º 26
0
    private TableRow buildPermissionRow(TblPermissions permission)
    {
        TableRow operationRow = new TableRow();


        Label dateSinceLabel = new Label();

        dateSinceLabel.Text = since + ": ";
        GMDatePicker dateSinceDatePicker = recreateDatePicker(since + permission.ID.ToString());
        Label        dateTillLabel       = new Label();

        dateTillLabel.Text = till + ": ";
        GMDatePicker dateTillDatePicker = recreateDatePicker(till + permission.ID.ToString());

        TableCell operationNameCell = new TableCell();

        if (permission.StageOperationRef.HasValue)
        {
            FxStageOperations stageOperation =
                ServerModel.DB.Load <FxStageOperations>(permission.StageOperationRef.Value);
            operationNameCell.Text = stageOperation.Name;
        }
        if (permission.CurriculumOperationRef.HasValue)
        {
            FxCurriculumOperations curriculumOperation =
                ServerModel.DB.Load <FxCurriculumOperations>(permission.CurriculumOperationRef.Value);
            operationNameCell.Text = curriculumOperation.Name;
        }
        operationRow.Cells.Add(operationNameCell);

        Table    layoutTable = new Table();
        TableRow layoutRow   = new TableRow();

        TableCell sinceLabelCell = new TableCell();

        sinceLabelCell.Controls.Add(dateSinceLabel);

        TableCell sincePickerCell = new TableCell();

        sincePickerCell.HorizontalAlign = HorizontalAlign.Right;
        sincePickerCell.Controls.Add(dateSinceDatePicker);

        TableCell tillLabelCell = new TableCell();

        tillLabelCell.Controls.Add(dateTillLabel);

        TableCell tillPickerCell = new TableCell();

        tillPickerCell.HorizontalAlign = HorizontalAlign.Right;
        tillPickerCell.Controls.Add(dateTillDatePicker);

        operationRow.Cells.Add(sinceLabelCell);
        operationRow.Cells.Add(sincePickerCell);
        operationRow.Cells.Add(tillLabelCell);
        operationRow.Cells.Add(tillPickerCell);
        if (permission.DateSince.HasValue)
        {
            dateSinceDatePicker.InitialText           = permission.DateSince.Value.ToShortDateString();
            dateSinceDatePicker.InitialTimePickerText = permission.DateSince.Value.ToShortTimeString();
        }

        if (permission.DateTill.HasValue)
        {
            dateTillDatePicker.InitialText           = permission.DateTill.Value.ToShortDateString();
            dateTillDatePicker.InitialTimePickerText = permission.DateTill.Value.ToShortTimeString();
        }

        TableCell operationCell = new TableCell();

        Button ApppyButton = new Button();

        ApppyButton.ID     = applyChar + permission.ID.ToString();
        ApppyButton.Click += new EventHandler(ApppyButton_Click);
        ApppyButton.Text   = apply;

        Button RemoveButton = new Button();

        RemoveButton.ID     = removeChar + permission.ID.ToString();
        RemoveButton.Click += new EventHandler(RemoveButton_Click);
        RemoveButton.Text   = remove;

        operationCell.Controls.Add(ApppyButton);
        operationCell.Controls.Add(RemoveButton);
        operationRow.Cells.Add(operationCell);

        return(operationRow);
    }