public static ErrorData InheritPermission(Context context, SiteSettings ss)
        {
            if (!context.CanManagePermission(ss: ss))
            {
                return(new ErrorData(type: Error.Types.HasNotPermission));
            }
            var inheritPermission = context.Forms.Long("InheritPermission");

            if (ss.SiteId != inheritPermission)
            {
                if (!PermissionUtilities.InheritTargetsDataRows(
                        context: context,
                        ss: ss).Any(o =>
                                    o.Long("SiteId") == context.Forms.Long("InheritPermission")))
                {
                    return(new ErrorData(type: Error.Types.CanNotInherit));
                }
                if (!Permissions.CanRead(
                        context: context,
                        siteId: inheritPermission))
                {
                    return(new ErrorData(type: Error.Types.HasNotPermission));
                }
                if (PermissionUtilities.HasInheritedSites(context: context, siteId: ss.SiteId))
                {
                    return(new ErrorData(type: Error.Types.CanNotChangeInheritance));
                }
            }
            return(new ErrorData(type: Error.Types.None));
        }
Пример #2
0
        public static Error.Types InheritPermission(SiteSettings ss)
        {
            if (!ss.CanManagePermission())
            {
                return(Error.Types.HasNotPermission);
            }
            var inheritPermission = Forms.Long("InheritPermission");

            if (ss.SiteId != inheritPermission)
            {
                if (!PermissionUtilities.InheritTargetsDataRows(ss.SiteId).Any(o =>
                                                                               o["SiteId"].ToLong() == Forms.Long("InheritPermission")))
                {
                    return(Error.Types.CanNotInherit);
                }
                if (!Permissions.CanRead(inheritPermission))
                {
                    return(Error.Types.HasNotPermission);
                }
                if (PermissionUtilities.HasInheritedSites(ss.SiteId))
                {
                    return(Error.Types.CanNotChangeInheritance);
                }
            }
            return(Error.Types.None);
        }
Пример #3
0
        public List <Dictionary <string, object> > KeyValues(
            Context context,
            SiteSettings ss,
            View view)
        {
            var data    = new List <Dictionary <string, object> >();
            var columns = ss.GetGridColumns(
                context: context,
                view: view,
                checkPermission: true);

            foreach (var dataRow in DataRows)
            {
                var rowData       = new Dictionary <string, object>();
                var tenants       = new Dictionary <string, TenantModel>();
                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>();
                var wikis         = new Dictionary <string, WikiModel>();
                foreach (var column in columns)
                {
                    var    key              = column.TableName();
                    var    apiColumn        = view.ApiColumnHash.Get(column.ColumnName);
                    var    keyDisplayType   = apiColumn?.KeyDisplayType ?? view.ApiColumnKeyDisplayType;
                    var    valueDisplayType = apiColumn?.ValueDisplayType ?? view.ApiColumnValueDisplayType;
                    string columnKey        = string.Empty;
                    switch (keyDisplayType)
                    {
                    case ApiColumn.KeyDisplayTypes.LabelText:
                        columnKey = column.LabelText;
                        break;

                    case ApiColumn.KeyDisplayTypes.ColumnName:
                        columnKey = column.ColumnName;
                        break;
                    }
                    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.ClearColumnAccessControlCaches(baseModel: deptModel);
                        }
                        switch (valueDisplayType)
                        {
                        case ApiColumn.ValueDisplayTypes.Value:
                            rowData.AddIfNotConainsKey(columnKey, deptModel.ToApiValue(
                                                           context: context,
                                                           ss: ss,
                                                           column: column,
                                                           mine: deptModel.Mine(context: context)));
                            break;

                        case ApiColumn.ValueDisplayTypes.Text:
                            rowData.AddIfNotConainsKey(columnKey, deptModel.ToDisplay(
                                                           context: context,
                                                           ss: ss,
                                                           column: column,
                                                           mine: deptModel.Mine(context: context)));
                            break;

                        default:
                            rowData.AddIfNotConainsKey(columnKey, deptModel.ToApiDisplayValue(
                                                           context: context,
                                                           ss: ss,
                                                           column: column,
                                                           mine: deptModel.Mine(context: context)));
                            break;
                        }
                        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.ClearColumnAccessControlCaches(baseModel: groupModel);
                        }
                        switch (valueDisplayType)
                        {
                        case ApiColumn.ValueDisplayTypes.Value:
                            rowData.AddIfNotConainsKey(columnKey, groupModel.ToApiValue(
                                                           context: context,
                                                           ss: ss,
                                                           column: column,
                                                           mine: groupModel.Mine(context: context)));
                            break;

                        case ApiColumn.ValueDisplayTypes.Text:
                            rowData.AddIfNotConainsKey(columnKey, groupModel.ToDisplay(
                                                           context: context,
                                                           ss: ss,
                                                           column: column,
                                                           mine: groupModel.Mine(context: context)));
                            break;

                        default:
                            rowData.AddIfNotConainsKey(columnKey, groupModel.ToApiDisplayValue(
                                                           context: context,
                                                           ss: ss,
                                                           column: column,
                                                           mine: groupModel.Mine(context: context)));
                            break;
                        }
                        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.ClearColumnAccessControlCaches(baseModel: userModel);
                        }
                        switch (valueDisplayType)
                        {
                        case ApiColumn.ValueDisplayTypes.Value:
                            rowData.AddIfNotConainsKey(columnKey, userModel.ToApiValue(
                                                           context: context,
                                                           ss: ss,
                                                           column: column,
                                                           mine: userModel.Mine(context: context)));
                            break;

                        case ApiColumn.ValueDisplayTypes.Text:
                            rowData.AddIfNotConainsKey(columnKey, userModel.ToDisplay(
                                                           context: context,
                                                           ss: ss,
                                                           column: column,
                                                           mine: userModel.Mine(context: context)));
                            break;

                        default:
                            rowData.AddIfNotConainsKey(columnKey, userModel.ToApiDisplayValue(
                                                           context: context,
                                                           ss: ss,
                                                           column: column,
                                                           mine: userModel.Mine(context: context)));
                            break;
                        }
                        break;

                    case "Issues":
                        var issueModel = issues.Get(key);
                        if (issueModel == null)
                        {
                            issueModel = new IssueModel(
                                context: context,
                                ss: column.SiteSettings,
                                dataRow: dataRow,
                                tableAlias: column.TableAlias);
                            issues.Add(key, issueModel);
                            ss.ClearColumnAccessControlCaches(baseModel: issueModel);
                        }
                        if (column.ColumnName.Contains("~") &&
                            !Permissions.CanRead(
                                context: context,
                                siteId: issueModel.SiteId,
                                id: issueModel.IssueId))
                        {
                            continue;
                        }
                        else
                        {
                            switch (valueDisplayType)
                            {
                            case ApiColumn.ValueDisplayTypes.Value:
                                rowData.AddIfNotConainsKey(columnKey, issueModel.ToApiValue(
                                                               context: context,
                                                               ss: ss,
                                                               column: column,
                                                               mine: issueModel.Mine(context: context)));
                                break;

                            case ApiColumn.ValueDisplayTypes.Text:
                                rowData.AddIfNotConainsKey(columnKey, issueModel.ToDisplay(
                                                               context: context,
                                                               ss: ss,
                                                               column: column,
                                                               mine: issueModel.Mine(context: context)));
                                break;

                            default:
                                rowData.AddIfNotConainsKey(columnKey, issueModel.ToApiDisplayValue(
                                                               context: context,
                                                               ss: ss,
                                                               column: column,
                                                               mine: issueModel.Mine(context: context)));
                                break;
                            }
                        }
                        break;

                    case "Results":
                        var resultModel = results.Get(key);
                        if (resultModel == null)
                        {
                            resultModel = new ResultModel(
                                context: context,
                                ss: column.SiteSettings,
                                dataRow: dataRow,
                                tableAlias: column.TableAlias);
                            results.Add(key, resultModel);
                            ss.ClearColumnAccessControlCaches(baseModel: resultModel);
                        }
                        if (column.ColumnName.Contains("~") &&
                            !Permissions.CanRead(
                                context: context,
                                siteId: resultModel.SiteId,
                                id: resultModel.ResultId))
                        {
                            continue;
                        }
                        else
                        {
                            switch (valueDisplayType)
                            {
                            case ApiColumn.ValueDisplayTypes.Value:
                                rowData.AddIfNotConainsKey(columnKey, resultModel.ToApiValue(
                                                               context: context,
                                                               ss: ss,
                                                               column: column,
                                                               mine: resultModel.Mine(context: context)));
                                break;

                            case ApiColumn.ValueDisplayTypes.Text:
                                rowData.AddIfNotConainsKey(columnKey, resultModel.ToDisplay(
                                                               context: context,
                                                               ss: ss,
                                                               column: column,
                                                               mine: resultModel.Mine(context: context)));
                                break;

                            default:
                                rowData.AddIfNotConainsKey(columnKey, resultModel.ToApiDisplayValue(
                                                               context: context,
                                                               ss: ss,
                                                               column: column,
                                                               mine: resultModel.Mine(context: context)));
                                break;
                            }
                        }
                        break;
                    }
                }
                data.Add(rowData);
            }
            return(data);
        }
Пример #4
0
        public static HtmlBuilder Tr(
            this HtmlBuilder hb,
            Context context,
            SiteSettings ss,
            List <Column> columns,
            DataRow dataRow,
            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");
            ServerScriptModelRow serverScriptModelRow = null;
            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>();

            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.ClearColumnAccessControlCaches(baseModel: issueModel);
                serverScriptModelRow = issueModel?.SetByBeforeOpeningRowServerScript(
                    context: context,
                    ss: ss);
                issues.Add("Issues", 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.ClearColumnAccessControlCaches(baseModel: resultModel);
                serverScriptModelRow = resultModel?.SetByBeforeOpeningRowServerScript(
                    context: context,
                    ss: ss);
                results.Add("Results", resultModel);
                break;
            }
            ;
            var extendedRowCss = serverScriptModelRow?.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"))
                       .Add(name: "data-extension", value: serverScriptModelRow?.ExtendedRowData),
                       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));
                }
                columns.ForEach(column =>
                {
                    var key = column.TableName();
                    var serverScriptModelColumn = serverScriptModelRow
                                                  ?.Columns
                                                  ?.Get(column?.ColumnName);
                    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.ClearColumnAccessControlCaches(baseModel: deptModel);
                        }
                        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.ClearColumnAccessControlCaches(baseModel: groupModel);
                        }
                        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.ClearColumnAccessControlCaches(baseModel: registrationModel);
                        }
                        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.ClearColumnAccessControlCaches(baseModel: userModel);
                        }
                        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.ClearColumnAccessControlCaches(baseModel: siteModel);
                        }
                        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.ClearColumnAccessControlCaches(baseModel: issueModel);
                        }
                        if (!issueModel.Locked &&
                            !issueModel.ReadOnly &&
                            !isHistory &&
                            EditColumn(
                                context: context,
                                ss: ss,
                                column: column,
                                mine: issueModel.Mine(context: context)) &&
                            column.CanEdit(
                                context: context,
                                ss: ss,
                                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 if (column.ColumnName.Contains("~") &&
                                 !Permissions.CanRead(
                                     context: context,
                                     siteId: issueModel.SiteId,
                                     id: issueModel.IssueId))
                        {
                            hb.Td(
                                context: context,
                                column: column,
                                value: string.Empty,
                                tabIndex: null,
                                serverScriptModelColumn: serverScriptModelColumn);
                        }
                        else
                        {
                            hb.TdValue(
                                context: context,
                                ss: column.SiteSettings,
                                column: column,
                                issueModel: issueModel,
                                serverScriptModelColumn: serverScriptModelColumn);
                        }
                        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.ClearColumnAccessControlCaches(baseModel: resultModel);
                        }
                        if (!resultModel.Locked &&
                            !resultModel.ReadOnly &&
                            !isHistory &&
                            EditColumn(
                                context: context,
                                ss: ss,
                                column: column,
                                mine: resultModel.Mine(context: context)) &&
                            column.CanEdit(
                                context: context,
                                ss: ss,
                                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 if (column.ColumnName.Contains("~") &&
                                 !Permissions.CanRead(
                                     context: context,
                                     siteId: resultModel.SiteId,
                                     id: resultModel.ResultId))
                        {
                            hb.Td(
                                context: context,
                                column: column,
                                value: string.Empty,
                                tabIndex: null,
                                serverScriptModelColumn: serverScriptModelColumn);
                        }
                        else
                        {
                            hb.TdValue(
                                context: context,
                                ss: column.SiteSettings,
                                column: column,
                                resultModel: resultModel,
                                serverScriptModelColumn: serverScriptModelColumn);
                        }
                        break;
                    }
                });
            }));
        }
Пример #5
0
        public Dictionary <string, string> LookupData(
            Context context,
            SiteSettings ss,
            Link link,
            long id)
        {
            var currentSs = ss.Destinations.Get(link.SiteId);
            var canRead   = false;

            if (currentSs == null)
            {
                canRead = true;
                switch (link?.TableName)
                {
                case "Depts":
                    currentSs = SiteSettingsUtilities.DeptsSiteSettings(context: context);
                    break;

                case "Users":
                    currentSs = SiteSettingsUtilities.UsersSiteSettings(context: context);
                    break;

                case "Groups":
                    currentSs = SiteSettingsUtilities.GroupsSiteSettings(context: context);
                    break;

                default:
                    canRead = false;
                    break;
                }
            }
            else
            {
                canRead = Permissions.CanRead(
                    context: context,
                    siteId: currentSs.SiteId,
                    id: id);
            }
            var formData = link.Lookups.ToDictionary(
                lookup => $"{currentSs.ReferenceType}_{lookup.To}",
                lookup => string.Empty);

            if (id > 0 &&
                currentSs != null &&
                canRead)
            {
                link.Lookups.ForEach(lookup =>
                {
                    formData.AddOrUpdate(
                        $"{currentSs.ReferenceType}_{lookup.To}",
                        string.Empty);
                });
                switch (currentSs.ReferenceType)
                {
                case "Issues":
                    var issueModel = new IssueModel(
                        context: context,
                        ss: currentSs,
                        issueId: id);
                    link.Lookups.ForEach(lookup =>
                                         formData.AddOrUpdate(
                                             $"{ss.ReferenceType}_{lookup.To}",
                                             lookup.Data(
                                                 context: context,
                                                 ss: currentSs,
                                                 issueModel: issueModel)));
                    break;

                case "Results":
                    var resultModel = new ResultModel(
                        context: context,
                        ss: currentSs,
                        resultId: id);
                    link.Lookups.ForEach(lookup =>
                                         formData.AddOrUpdate(
                                             $"{ss.ReferenceType}_{lookup.To}",
                                             lookup.Data(
                                                 context: context,
                                                 ss: currentSs,
                                                 resultModel: resultModel)));
                    break;

                case "Depts":
                    var deptModel = new DeptModel(
                        context: context,
                        ss: currentSs,
                        deptId: id.ToInt());
                    link.Lookups.ForEach(lookup =>
                                         formData.AddOrUpdate(
                                             $"{ss.ReferenceType}_{lookup.To}",
                                             lookup.Data(
                                                 context: context,
                                                 ss: currentSs,
                                                 deptModel: deptModel)));
                    break;

                case "Users":
                    var userModel = new UserModel(
                        context: context,
                        ss: currentSs,
                        userId: id.ToInt());
                    link.Lookups.ForEach(lookup =>
                                         formData.AddOrUpdate(
                                             $"{ss.ReferenceType}_{lookup.To}",
                                             lookup.Data(
                                                 context: context,
                                                 ss: currentSs,
                                                 userModel: userModel)));
                    break;

                case "Groups":
                    var groupModel = new GroupModel(
                        context: context,
                        ss: currentSs,
                        groupId: id.ToInt());
                    link.Lookups.ForEach(lookup =>
                                         formData.AddOrUpdate(
                                             $"{ss.ReferenceType}_{lookup.To}",
                                             lookup.Data(
                                                 context: context,
                                                 ss: currentSs,
                                                 groupModel: groupModel)));
                    break;
                }
            }
            return(formData);
        }