| 
 | 1 | +// Copyright 2024 The Gitea Authors. All rights reserved.  | 
 | 2 | +// SPDX-License-Identifier: MIT  | 
 | 3 | + | 
 | 4 | +// WIP RequireAction  | 
 | 5 | + | 
 | 6 | +package setting  | 
 | 7 | + | 
 | 8 | +import (  | 
 | 9 | +    "errors"  | 
 | 10 | +    "net/http"  | 
 | 11 | + | 
 | 12 | +    "code.gitea.io/gitea/models/db"  | 
 | 13 | +    "code.gitea.io/gitea/modules/base"  | 
 | 14 | +    // "code.gitea.io/gitea/modules/log"  | 
 | 15 | + | 
 | 16 | +    "code.gitea.io/gitea/services/context"  | 
 | 17 | + | 
 | 18 | +    //"code.gitea.io/gitea/modules/setting"  | 
 | 19 | +    shared "code.gitea.io/gitea/routers/web/shared/actions"  | 
 | 20 | +    actions_model "code.gitea.io/gitea/models/actions"  | 
 | 21 | +)  | 
 | 22 | + | 
 | 23 | +const (  | 
 | 24 | +        // let start with org WIP  | 
 | 25 | +        tplOrgRequireAction base.TplName = "org/settings/actions"  | 
 | 26 | +)  | 
 | 27 | + | 
 | 28 | +type requireActionsCtx struct {  | 
 | 29 | +    OrgID                  int64  | 
 | 30 | +    IsOrg                  bool  | 
 | 31 | +    RequireActionTemplate  base.TplName  | 
 | 32 | +    RedirectLink           string  | 
 | 33 | +}  | 
 | 34 | + | 
 | 35 | +func getRequireActionCtx(ctx *context.Context) (*requireActionsCtx, error) {  | 
 | 36 | +    if ctx.Data["PageIsOrgSettings"] == true {  | 
 | 37 | +        return &requireActionsCtx{  | 
 | 38 | +            OrgID:                  ctx.Org.Organization.ID,  | 
 | 39 | +            IsOrg:                  true,  | 
 | 40 | +            RequireActionTemplate:  tplOrgRequireAction,  | 
 | 41 | +            RedirectLink:           ctx.Org.OrgLink + "/settings/actions/require_action",  | 
 | 42 | +        }, nil  | 
 | 43 | +    }  | 
 | 44 | +    return nil, errors.New("unable to set Require Actions context")  | 
 | 45 | +}  | 
 | 46 | + | 
 | 47 | +// Listing all RequireAction  | 
 | 48 | +func RequireAction(ctx *context.Context) {  | 
 | 49 | +    ctx.Data["ActionsTitle"] = ctx.Tr("actions.requires")  | 
 | 50 | +    ctx.Data["PageType"] = "require_action"  | 
 | 51 | +    ctx.Data["PageIsSharedSettingsRequireAction"] = true  | 
 | 52 | + | 
 | 53 | +    vCtx, err := getRequireActionCtx(ctx)  | 
 | 54 | +    if err != nil {  | 
 | 55 | +        ctx.ServerError("getRequireActionCtx", err)  | 
 | 56 | +        return  | 
 | 57 | +    }  | 
 | 58 | + | 
 | 59 | +    page := ctx.FormInt("page")  | 
 | 60 | +    if page <= 1 { page = 1 }  | 
 | 61 | +    opts := actions_model.FindRequireActionOptions{  | 
 | 62 | +        ListOptions: db.ListOptions{  | 
 | 63 | +            Page:     page,  | 
 | 64 | +            PageSize: 10,  | 
 | 65 | +        },  | 
 | 66 | +    }  | 
 | 67 | +    shared.SetRequireActionContext(ctx, opts)  | 
 | 68 | +    ctx.Data["Link"] = vCtx.RedirectLink  | 
 | 69 | +    shared.GlobalEnableWorkflow(ctx, ctx.Org.Organization.ID)  | 
 | 70 | +    ctx.HTML(http.StatusOK, vCtx.RequireActionTemplate)  | 
 | 71 | +}  | 
 | 72 | + | 
 | 73 | +func RequireActionCreate(ctx *context.Context) {  | 
 | 74 | +    vCtx, err := getRequireActionCtx(ctx)  | 
 | 75 | +    if err != nil {  | 
 | 76 | +        ctx.ServerError("getRequireActionCtx", err)  | 
 | 77 | +        return  | 
 | 78 | +    }  | 
 | 79 | +    shared.CreateRequireAction(ctx, vCtx.OrgID, vCtx.RedirectLink)  | 
 | 80 | +}  | 
0 commit comments