Ejemplo n.º 1
0
        public static ErrorData OnCreating(
            Context context, SiteSettings ss, WikiModel wikiModel, bool api = false)
        {
            if (api && (context.ContractSettings.Api == false || !Parameters.Api.Enabled))
            {
                return(new ErrorData(type: Error.Types.InvalidRequest));
            }
            if (!context.CanCreate(ss: ss))
            {
                return(new ErrorData(type: Error.Types.HasNotPermission));
            }
            ss.SetColumnAccessControls(context: context, mine: wikiModel.Mine(context: context));
            foreach (var column in ss.Columns
                     .Where(o => !o.CanCreate)
                     .Where(o => !ss.FormulaTarget(o.ColumnName))
                     .Where(o => !o.Linking))
            {
                switch (column.ColumnName)
                {
                case "Title":
                    if (wikiModel.Title_Updated(context: context, column: column))
                    {
                        return(new ErrorData(type: Error.Types.HasNotPermission));
                    }
                    break;

                case "Body":
                    if (wikiModel.Body_Updated(context: context, column: column))
                    {
                        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;

                default:
                    switch (Def.ExtendedColumnTypes.Get(column.Name))
                    {
                    case "Class":
                        if (wikiModel.Class_Updated(
                                columnName: column.Name,
                                context: context,
                                column: column))
                        {
                            return(new ErrorData(type: Error.Types.HasNotPermission));
                        }
                        break;

                    case "Num":
                        if (wikiModel.Num_Updated(
                                columnName: column.Name,
                                context: context,
                                column: column))
                        {
                            return(new ErrorData(type: Error.Types.HasNotPermission));
                        }
                        break;

                    case "Date":
                        if (wikiModel.Date_Updated(
                                columnName: column.Name,
                                context: context,
                                column: column))
                        {
                            return(new ErrorData(type: Error.Types.HasNotPermission));
                        }
                        break;

                    case "Description":
                        if (wikiModel.Description_Updated(
                                columnName: column.Name,
                                context: context,
                                column: column))
                        {
                            return(new ErrorData(type: Error.Types.HasNotPermission));
                        }
                        break;

                    case "Check":
                        if (wikiModel.Check_Updated(
                                columnName: column.Name,
                                context: context,
                                column: column))
                        {
                            return(new ErrorData(type: Error.Types.HasNotPermission));
                        }
                        break;

                    case "Attachments":
                        if (wikiModel.Attachments_Updated(
                                columnName: column.Name,
                                context: context,
                                column: column))
                        {
                            return(new ErrorData(type: Error.Types.HasNotPermission));
                        }
                        break;
                    }
                    break;
                }
            }
            return(new ErrorData(type: Error.Types.None));
        }
Ejemplo n.º 2
0
        public static ErrorData OnCreating(
            Context context, SiteSettings ss, WikiModel wikiModel, bool api = false)
        {
            if (api)
            {
                if ((context.ContractSettings.Api == false || !Parameters.Api.Enabled))
                {
                    return(new ErrorData(type: Error.Types.InvalidRequest));
                }
                if (context.InvalidJsonData)
                {
                    return(new ErrorData(type: Error.Types.InvalidJsonData));
                }
            }
            if (ss.LockedTable())
            {
                return(new ErrorData(
                           type: Error.Types.LockedTable,
                           data: new string[]
                {
                    ss.LockedTableUser.Name,
                    ss.LockedTableTime.DisplayValue.ToString(context.CultureInfo())
                }));
            }
            if (!context.CanCreate(ss: ss) || wikiModel.ReadOnly)
            {
                return(!context.CanRead(ss: ss)
                    ? new ErrorData(type: Error.Types.NotFound)
                    : new ErrorData(type: Error.Types.HasNotPermission));
            }
            foreach (var column in ss.Columns
                     .Where(o => !o.CanCreate(
                                context: context,
                                ss: ss,
                                mine: wikiModel.Mine(context: context)))
                     .Where(o => !ss.FormulaTarget(o.ColumnName))
                     .Where(o => !o.Linking))
            {
                switch (column.ColumnName)
                {
                case "Title":
                    if (wikiModel.Title_Updated(context: context, column: column))
                    {
                        return(new ErrorData(type: Error.Types.HasNotPermission));
                    }
                    break;

                case "Body":
                    if (wikiModel.Body_Updated(context: context, column: column))
                    {
                        return(new ErrorData(type: Error.Types.HasNotPermission));
                    }
                    break;

                case "Locked":
                    if (wikiModel.Locked_Updated(context: context, column: column))
                    {
                        return(new ErrorData(type: Error.Types.HasNotPermission));
                    }
                    break;

                case "Comments":
                    if (wikiModel.Comments_Updated(context: context))
                    {
                        return(new ErrorData(type: Error.Types.HasNotPermission));
                    }
                    break;

                default:
                    switch (Def.ExtendedColumnTypes.Get(column.Name))
                    {
                    case "Class":
                        if (wikiModel.Class_Updated(
                                columnName: column.Name,
                                context: context,
                                column: column))
                        {
                            return(new ErrorData(type: Error.Types.HasNotPermission));
                        }
                        break;

                    case "Num":
                        if (wikiModel.Num_Updated(
                                columnName: column.Name,
                                context: context,
                                column: column))
                        {
                            return(new ErrorData(type: Error.Types.HasNotPermission));
                        }
                        break;

                    case "Date":
                        if (wikiModel.Date_Updated(
                                columnName: column.Name,
                                context: context,
                                column: column))
                        {
                            return(new ErrorData(type: Error.Types.HasNotPermission));
                        }
                        break;

                    case "Description":
                        if (wikiModel.Description_Updated(
                                columnName: column.Name,
                                context: context,
                                column: column))
                        {
                            return(new ErrorData(type: Error.Types.HasNotPermission));
                        }
                        break;

                    case "Check":
                        if (wikiModel.Check_Updated(
                                columnName: column.Name,
                                context: context,
                                column: column))
                        {
                            return(new ErrorData(type: Error.Types.HasNotPermission));
                        }
                        break;

                    case "Attachments":
                        if (wikiModel.Attachments_Updated(
                                columnName: column.Name,
                                context: context,
                                column: column))
                        {
                            return(new ErrorData(type: Error.Types.HasNotPermission));
                        }
                        break;
                    }
                    break;
                }
            }
            return(new ErrorData(type: Error.Types.None));
        }