public static ErrorData OnCreating(Context context, SiteSettings ss, SiteModel siteModel)
        {
            if (!context.CanManageSite(ss: ss))
            {
                return(new ErrorData(type: Error.Types.HasNotPermission));
            }
            ss.SetColumnAccessControls(context: context, mine: siteModel.Mine(context: context));
            foreach (var controlId in context.Forms.Keys)
            {
                switch (controlId)
                {
                case "Sites_Title":
                    if (!ss.GetColumn(context: context, columnName: "Title").CanCreate)
                    {
                        return(new ErrorData(type: Error.Types.HasNotPermission));
                    }
                    break;

                case "Sites_Body":
                    if (!ss.GetColumn(context: context, columnName: "Body").CanCreate)
                    {
                        return(new ErrorData(type: Error.Types.HasNotPermission));
                    }
                    break;

                case "Sites_ReferenceType":
                    if (!ss.GetColumn(context: context, columnName: "ReferenceType").CanCreate)
                    {
                        return(new ErrorData(type: Error.Types.HasNotPermission));
                    }
                    break;

                case "Sites_InheritPermission":
                    if (!ss.GetColumn(context: context, columnName: "InheritPermission").CanCreate)
                    {
                        return(new ErrorData(type: Error.Types.HasNotPermission));
                    }
                    break;

                case "Comments":
                    if (!ss.GetColumn(context: context, columnName: "Comments").CanCreate)
                    {
                        return(new ErrorData(type: Error.Types.HasNotPermission));
                    }
                    break;
                }
            }
            return(new ErrorData(type: Error.Types.None));
        }
Beispiel #2
0
        public static Error.Types OnCreating(SiteSettings ss, SiteModel siteModel)
        {
            if (!ss.CanManageSite())
            {
                return(Error.Types.HasNotPermission);
            }
            ss.SetColumnAccessControls(siteModel.Mine());
            foreach (var controlId in Forms.Keys())
            {
                switch (controlId)
                {
                case "Sites_Title":
                    if (!ss.GetColumn("Title").CanCreate)
                    {
                        return(Error.Types.HasNotPermission);
                    }
                    break;

                case "Sites_Body":
                    if (!ss.GetColumn("Body").CanCreate)
                    {
                        return(Error.Types.HasNotPermission);
                    }
                    break;

                case "Sites_ReferenceType":
                    if (!ss.GetColumn("ReferenceType").CanCreate)
                    {
                        return(Error.Types.HasNotPermission);
                    }
                    break;

                case "Sites_InheritPermission":
                    if (!ss.GetColumn("InheritPermission").CanCreate)
                    {
                        return(Error.Types.HasNotPermission);
                    }
                    break;

                case "Comments":
                    if (!ss.GetColumn("Comments").CanCreate)
                    {
                        return(Error.Types.HasNotPermission);
                    }
                    break;
                }
            }
            return(Error.Types.None);
        }
        public static HtmlBuilder Tr(
            this HtmlBuilder hb,
            Context context,
            SiteSettings ss,
            DataRow dataRow,
            IEnumerable <Column> columns,
            bool editRow,
            bool checkRow,
            string idColumn,
            RecordSelector recordSelector = null,
            FormDataSet formDataSet       = null)
        {
            var dataId      = dataRow.Long(idColumn);
            var dataVersion = dataRow.Int("Ver");
            var isHistory   = dataRow.Bool("IsHistory");
            var EditColumns = !isHistory
                ? columns.ToDictionary(
                column => column.ColumnName,
                column => EditColumn(
                    context: context,
                    column: column))
                : new Dictionary <string, bool>();

            BaseItemModel rowModel = null;

            switch (ss.ReferenceType)
            {
            case "Issues":
                var issueModel = new IssueModel(
                    context: context,
                    ss: ss,
                    dataRow: dataRow,
                    formData: editRow
                            ? formDataSet?.FirstOrDefault(o =>
                                                          o.Id == dataRow.Long("IssueId"))?.Data
                            : null);
                ss.SetColumnAccessControls(
                    context: context,
                    mine: issueModel.Mine(context: context));
                rowModel = issueModel;
                break;

            case "Results":
                var resultModel = new ResultModel(
                    context: context,
                    ss: ss,
                    dataRow: dataRow,
                    formData: editRow
                            ? formDataSet?.FirstOrDefault(o =>
                                                          o.Id == dataRow.Long("ResultId"))?.Data
                            : null);
                ss.SetColumnAccessControls(
                    context: context,
                    mine: resultModel.Mine(context: context));
                rowModel = resultModel;
                break;
            }
            ;
            var serverScriptRowValues = rowModel?.SetByBeforeOpeningPageServerScript(
                context: context,
                ss: ss);
            var extendedRowCss = serverScriptRowValues?.ExtendedRowCss;

            extendedRowCss = extendedRowCss.IsNullOrEmpty() ? string.Empty : " " + extendedRowCss;
            return(hb.Tr(
                       attributes: new HtmlAttributes()
                       .Class("grid-row" + extendedRowCss)
                       .DataId(dataId.ToString())
                       .DataVer(dataVersion)
                       .DataLatest(1, _using: !isHistory)
                       .Add(name: "data-history", value: "1", _using: isHistory)
                       .Add(name: "data-locked", value: "1", _using: dataRow.Bool("Locked")),
                       action: () =>
            {
                if (editRow)
                {
                    hb.Td(action: () => hb
                          .Button(
                              title: Displays.Reload(context: context),
                              controlCss: "button-icon",
                              onClick: $"$p.getData($(this)).Id={dataId};$p.send($(this));",
                              icon: "ui-icon-refresh",
                              action: "ReloadRow",
                              method: "post",
                              _using: !isHistory)
                          .Button(
                              title: Displays.Copy(context: context),
                              controlCss: "button-icon",
                              onClick: $"$p.getData($(this)).OriginalId={dataId};$p.send($(this));",
                              icon: "ui-icon-copy",
                              action: "CopyRow",
                              method: "post",
                              _using: !isHistory && context.CanCreate(ss: ss))
                          .Hidden(
                              controlId: $"{ss.ReferenceType}_Timestamp_{ss.SiteId}_{dataId}",
                              css: "timestamp",
                              value: dataRow
                              .Field <DateTime>("UpdatedTime")
                              .ToString("yyyy/M/d H:m:s.fff")));
                }
                else if (checkRow)
                {
                    hb.Td(action: () => hb
                          .CheckBox(
                              controlCss: "grid-check",
                              _checked: recordSelector.Checked(dataId),
                              dataId: dataId.ToString(),
                              _using: !isHistory));
                }
                var depts = new Dictionary <string, DeptModel>();
                var groups = new Dictionary <string, GroupModel>();
                var registrations = new Dictionary <string, RegistrationModel>();
                var users = new Dictionary <string, UserModel>();
                var sites = new Dictionary <string, SiteModel>();
                var issues = new Dictionary <string, IssueModel>();
                var results = new Dictionary <string, ResultModel>();
                ServerScriptModelRow serverScriptValues = null;
                columns.ForEach(column =>
                {
                    var key = column.TableName();
                    switch (column.SiteSettings?.ReferenceType)
                    {
                    case "Depts":
                        var deptModel = depts.Get(key);
                        if (deptModel == null)
                        {
                            deptModel = new DeptModel(
                                context: context,
                                ss: column.SiteSettings,
                                dataRow: dataRow,
                                tableAlias: column.TableAlias);
                            depts.Add(key, deptModel);
                            ss.SetColumnAccessControls(
                                context: context,
                                mine: deptModel.Mine(context: context));
                            serverScriptValues = deptModel.SetByBeforeOpeningPageServerScript(
                                context: context,
                                ss: ss);
                        }
                        hb.TdValue(
                            context: context,
                            ss: column.SiteSettings,
                            column: column,
                            deptModel: deptModel);
                        break;

                    case "Groups":
                        var groupModel = groups.Get(key);
                        if (groupModel == null)
                        {
                            groupModel = new GroupModel(
                                context: context,
                                ss: column.SiteSettings,
                                dataRow: dataRow,
                                tableAlias: column.TableAlias);
                            groups.Add(key, groupModel);
                            ss.SetColumnAccessControls(
                                context: context,
                                mine: groupModel.Mine(context: context));
                            serverScriptValues = groupModel.SetByBeforeOpeningPageServerScript(
                                context: context,
                                ss: ss);
                        }
                        hb.TdValue(
                            context: context,
                            ss: column.SiteSettings,
                            column: column,
                            groupModel: groupModel);
                        break;

                    case "Registrations":
                        var registrationModel = registrations.Get(key);
                        if (registrationModel == null)
                        {
                            registrationModel = new RegistrationModel(
                                context: context,
                                ss: column.SiteSettings,
                                dataRow: dataRow,
                                tableAlias: column.TableAlias);
                            registrations.Add(key, registrationModel);
                            ss.SetColumnAccessControls(
                                context: context,
                                mine: registrationModel.Mine(context: context));
                            serverScriptValues = registrationModel.SetByBeforeOpeningPageServerScript(
                                context: context,
                                ss: ss);
                        }
                        hb.TdValue(
                            context: context,
                            ss: column.SiteSettings,
                            column: column,
                            registrationModel: registrationModel);
                        break;

                    case "Users":
                        var userModel = users.Get(key);
                        if (userModel == null)
                        {
                            userModel = new UserModel(
                                context: context,
                                ss: column.SiteSettings,
                                dataRow: dataRow,
                                tableAlias: column.TableAlias);
                            users.Add(key, userModel);
                            ss.SetColumnAccessControls(
                                context: context,
                                mine: userModel.Mine(context: context));
                            serverScriptValues = userModel.SetByBeforeOpeningPageServerScript(
                                context: context,
                                ss: ss);
                        }
                        hb.TdValue(
                            context: context,
                            ss: column.SiteSettings,
                            column: column,
                            userModel: userModel);
                        break;

                    case "Sites":
                        var siteModel = sites.Get(key);
                        if (siteModel == null)
                        {
                            siteModel = new SiteModel(
                                context: context,
                                dataRow: dataRow,
                                formData: editRow
                                            ? formDataSet?.FirstOrDefault(o =>
                                                                          o.Id == dataRow.Long("SiteId"))?.Data
                                            : null,
                                tableAlias: column.TableAlias);
                            sites.Add(key, siteModel);
                            ss.SetColumnAccessControls(
                                context: context,
                                mine: siteModel.Mine(context: context));
                            serverScriptValues = siteModel.SetByBeforeOpeningPageServerScript(
                                context: context,
                                ss: ss);
                        }
                        hb.TdValue(
                            context: context,
                            ss: column.SiteSettings,
                            column: column,
                            siteModel: siteModel);
                        break;

                    case "Issues":
                        var issueModel = issues.Get(key);
                        if (issueModel == null)
                        {
                            issueModel = new IssueModel(
                                context: context,
                                ss: column.SiteSettings,
                                dataRow: dataRow,
                                formData: editRow
                                            ? formDataSet?.FirstOrDefault(o =>
                                                                          o.Id == dataRow.Long("IssueId"))?.Data
                                            : null,
                                tableAlias: column.TableAlias);
                            issues.Add(key, issueModel);
                            ss.SetColumnAccessControls(
                                context: context,
                                mine: issueModel.Mine(context: context));
                            serverScriptValues = issueModel.SetByBeforeOpeningPageServerScript(
                                context: context,
                                ss: ss);
                        }
                        if (!issueModel.Locked && EditColumns.Get(column.ColumnName) && column.CanUpdate(baseModel: issueModel))
                        {
                            hb.Td(
                                css: column.TextAlign == SiteSettings.TextAlignTypes.Right
                                            ? " right-align"
                                            : string.Empty,
                                action: () => hb.Field(
                                    context: context,
                                    column: column,
                                    issueModel: issueModel,
                                    ss: column.SiteSettings,
                                    controlOnly: true,
                                    idSuffix: issueModel.IdSuffix()));
                        }
                        else
                        {
                            hb.TdValue(
                                context: context,
                                ss: column.SiteSettings,
                                column: column,
                                issueModel: issueModel,
                                serverScriptValues: serverScriptValues
                                ?.Columns
                                ?.Get(column?.ColumnName));
                        }
                        break;

                    case "Results":
                        var resultModel = results.Get(key);
                        if (resultModel == null)
                        {
                            resultModel = new ResultModel(
                                context: context,
                                ss: column.SiteSettings,
                                dataRow: dataRow,
                                formData: editRow
                                            ? formDataSet?.FirstOrDefault(o =>
                                                                          o.Id == dataRow.Long("ResultId"))?.Data
                                            : null,
                                tableAlias: column.TableAlias);
                            results.Add(key, resultModel);
                            ss.SetColumnAccessControls(
                                context: context,
                                mine: resultModel.Mine(context: context));
                            serverScriptValues = resultModel.SetByBeforeOpeningPageServerScript(
                                context: context,
                                ss: ss);
                        }
                        if (!resultModel.Locked && EditColumns.Get(column.ColumnName) && column.CanUpdate(baseModel: resultModel))
                        {
                            hb.Td(
                                css: column.TextAlign == SiteSettings.TextAlignTypes.Right
                                            ? " right-align"
                                            : string.Empty,
                                action: () => hb.Field(
                                    context: context,
                                    column: column,
                                    resultModel: resultModel,
                                    ss: column.SiteSettings,
                                    controlOnly: true,
                                    idSuffix: resultModel.IdSuffix()));
                        }
                        else
                        {
                            hb.TdValue(
                                context: context,
                                ss: column.SiteSettings,
                                column: column,
                                resultModel: resultModel,
                                serverScriptValues: serverScriptValues
                                ?.Columns
                                ?.Get(column?.ColumnName));
                        }
                        break;
                    }
                });
            }));
        }
        public static ErrorData OnUpdating(Context context, SiteSettings ss, SiteModel siteModel)
        {
            if (!context.CanManageSite(ss: ss))
            {
                return(new ErrorData(type: Error.Types.HasNotPermission));
            }
            ss.SetColumnAccessControls(context: context, mine: siteModel.Mine(context: context));
            foreach (var controlId in context.Forms.Keys)
            {
                switch (controlId)
                {
                case "Sites_Title":
                    if (siteModel.Title_Updated(context: context) &&
                        !ss.GetColumn(context: context, columnName: "Title").CanUpdate)
                    {
                        return(new ErrorData(type: Error.Types.HasNotPermission));
                    }
                    break;

                case "Sites_Body":
                    if (siteModel.Body_Updated(context: context) &&
                        !ss.GetColumn(context: context, columnName: "Body").CanUpdate)
                    {
                        return(new ErrorData(type: Error.Types.HasNotPermission));
                    }
                    break;

                case "Sites_ReferenceType":
                    if (siteModel.ReferenceType_Updated(context: context) &&
                        !ss.GetColumn(context: context, columnName: "ReferenceType").CanUpdate)
                    {
                        return(new ErrorData(type: Error.Types.HasNotPermission));
                    }
                    break;

                case "Sites_InheritPermission":
                    if (siteModel.InheritPermission_Updated(context: context) &&
                        !ss.GetColumn(context: context, columnName: "InheritPermission").CanUpdate)
                    {
                        return(new ErrorData(type: Error.Types.HasNotPermission));
                    }
                    break;

                case "InheritPermission":
                    var errorData = InheritPermission(context: context, ss: ss);
                    if (errorData.Type != Error.Types.None)
                    {
                        return(errorData);
                    }
                    break;

                case "CurrentPermissionsAll":
                    if (!context.CanManagePermission(ss: ss))
                    {
                        return(new ErrorData(type: Error.Types.HasNotPermission));
                    }
                    if (!new PermissionCollection(
                            context: context,
                            referenceId: ss.SiteId,
                            permissions: context.Forms.List("CurrentPermissionsAll"))
                        .InTenant(context: context))
                    {
                        return(new ErrorData(type: Error.Types.InvalidRequest));
                    }
                    break;

                case "SearchPermissionElements":
                case "OpenPermissionsDialog":
                case "AddPermissions":
                case "DeletePermissions":
                    if (!context.CanManagePermission(ss: ss))
                    {
                        return(new ErrorData(type: Error.Types.HasNotPermission));
                    }
                    break;

                case "Comments":
                    if (!ss.GetColumn(context: context, columnName: "Comments").CanUpdate)
                    {
                        return(new ErrorData(type: Error.Types.HasNotPermission));
                    }
                    break;
                }
            }
            return(new ErrorData(type: Error.Types.None));
        }
Beispiel #5
0
        public static Error.Types OnUpdating(SiteSettings ss, SiteModel siteModel)
        {
            if (!ss.CanManageSite())
            {
                return(Error.Types.HasNotPermission);
            }
            ss.SetColumnAccessControls(siteModel.Mine());
            foreach (var controlId in Forms.Keys())
            {
                switch (controlId)
                {
                case "Sites_Title":
                    if (siteModel.Title_Updated() &&
                        !ss.GetColumn("Title").CanUpdate)
                    {
                        return(Error.Types.HasNotPermission);
                    }
                    break;

                case "Sites_Body":
                    if (siteModel.Body_Updated() &&
                        !ss.GetColumn("Body").CanUpdate)
                    {
                        return(Error.Types.HasNotPermission);
                    }
                    break;

                case "Sites_ReferenceType":
                    if (siteModel.ReferenceType_Updated() &&
                        !ss.GetColumn("ReferenceType").CanUpdate)
                    {
                        return(Error.Types.HasNotPermission);
                    }
                    break;

                case "Sites_InheritPermission":
                    if (siteModel.InheritPermission_Updated() &&
                        !ss.GetColumn("InheritPermission").CanUpdate)
                    {
                        return(Error.Types.HasNotPermission);
                    }
                    break;

                case "InheritPermission":
                    var type = InheritPermission(ss);
                    if (type != Error.Types.None)
                    {
                        return(type);
                    }
                    break;

                case "CurrentPermissionsAll":
                    if (!ss.CanManagePermission())
                    {
                        return(Error.Types.HasNotPermission);
                    }
                    if (!new PermissionCollection(
                            ss.SiteId, Forms.List("CurrentPermissionsAll")).InTenant())
                    {
                        return(Error.Types.InvalidRequest);
                    }
                    break;

                case "SearchPermissionElements":
                case "OpenPermissionsDialog":
                case "AddPermissions":
                case "DeletePermissions":
                    if (!ss.CanManagePermission())
                    {
                        return(Error.Types.HasNotPermission);
                    }
                    break;

                case "Comments":
                    if (!ss.GetColumn("Comments").CanUpdate)
                    {
                        return(Error.Types.HasNotPermission);
                    }
                    break;
                }
            }
            return(Error.Types.None);
        }