@ -52,11 +52,12 @@ type orgRepoCtx struct {
OrgID int64
OrgID int64
RepoID int64
RepoID int64
IsAdmin bool
IsAdmin bool
IsSystemWebhook bool
Link string
Link string
NewTemplate base . TplName
NewTemplate base . TplName
}
}
// getOrgRepoCtx determines whether this is a repo, organization, or admin context.
// getOrgRepoCtx determines whether this is a repo, organization, or admin (both default and system) context.
func getOrgRepoCtx ( ctx * context . Context ) ( * orgRepoCtx , error ) {
func getOrgRepoCtx ( ctx * context . Context ) ( * orgRepoCtx , error ) {
if len ( ctx . Repo . RepoLink ) > 0 {
if len ( ctx . Repo . RepoLink ) > 0 {
return & orgRepoCtx {
return & orgRepoCtx {
@ -75,6 +76,8 @@ func getOrgRepoCtx(ctx *context.Context) (*orgRepoCtx, error) {
}
}
if ctx . User . IsAdmin {
if ctx . User . IsAdmin {
// Are we looking at default webhooks?
if ctx . Params ( ":configType" ) == "hooks" {
return & orgRepoCtx {
return & orgRepoCtx {
IsAdmin : true ,
IsAdmin : true ,
Link : path . Join ( setting . AppSubURL , "/admin/hooks" ) ,
Link : path . Join ( setting . AppSubURL , "/admin/hooks" ) ,
@ -82,6 +85,15 @@ func getOrgRepoCtx(ctx *context.Context) (*orgRepoCtx, error) {
} , nil
} , nil
}
}
// Must be system webhooks instead
return & orgRepoCtx {
IsAdmin : true ,
IsSystemWebhook : true ,
Link : path . Join ( setting . AppSubURL , "/admin/system-hooks" ) ,
NewTemplate : tplAdminHookNew ,
} , nil
}
return nil , errors . New ( "Unable to set OrgRepo context" )
return nil , errors . New ( "Unable to set OrgRepo context" )
}
}
@ -105,7 +117,10 @@ func WebhooksNew(ctx *context.Context) {
return
return
}
}
if orCtx . IsAdmin {
if orCtx . IsAdmin && orCtx . IsSystemWebhook {
ctx . Data [ "PageIsAdminSystemHooks" ] = true
ctx . Data [ "PageIsAdminSystemHooksNew" ] = true
} else if orCtx . IsAdmin {
ctx . Data [ "PageIsAdminHooks" ] = true
ctx . Data [ "PageIsAdminHooks" ] = true
ctx . Data [ "PageIsAdminHooksNew" ] = true
ctx . Data [ "PageIsAdminHooksNew" ] = true
} else {
} else {
@ -159,8 +174,8 @@ func ParseHookEvent(form auth.WebhookForm) *models.HookEvent {
}
}
}
}
// WebHooksNewPost response for creating webhook
// GiteaHooksNewPost response for creating Gitea webhook
func Web HooksNewPost( ctx * context . Context , form auth . NewWebhookForm ) {
func Gitea HooksNewPost( ctx * context . Context , form auth . NewWebhookForm ) {
ctx . Data [ "Title" ] = ctx . Tr ( "repo.settings.add_webhook" )
ctx . Data [ "Title" ] = ctx . Tr ( "repo.settings.add_webhook" )
ctx . Data [ "PageIsSettingsHooks" ] = true
ctx . Data [ "PageIsSettingsHooks" ] = true
ctx . Data [ "PageIsSettingsHooksNew" ] = true
ctx . Data [ "PageIsSettingsHooksNew" ] = true
@ -194,6 +209,7 @@ func WebHooksNewPost(ctx *context.Context, form auth.NewWebhookForm) {
IsActive : form . Active ,
IsActive : form . Active ,
HookTaskType : models . GITEA ,
HookTaskType : models . GITEA ,
OrgID : orCtx . OrgID ,
OrgID : orCtx . OrgID ,
IsSystemWebhook : orCtx . IsSystemWebhook ,
}
}
if err := w . UpdateEvent ( ) ; err != nil {
if err := w . UpdateEvent ( ) ; err != nil {
ctx . ServerError ( "UpdateEvent" , err )
ctx . ServerError ( "UpdateEvent" , err )
@ -246,6 +262,7 @@ func newGogsWebhookPost(ctx *context.Context, form auth.NewGogshookForm, kind mo
IsActive : form . Active ,
IsActive : form . Active ,
HookTaskType : kind ,
HookTaskType : kind ,
OrgID : orCtx . OrgID ,
OrgID : orCtx . OrgID ,
IsSystemWebhook : orCtx . IsSystemWebhook ,
}
}
if err := w . UpdateEvent ( ) ; err != nil {
if err := w . UpdateEvent ( ) ; err != nil {
ctx . ServerError ( "UpdateEvent" , err )
ctx . ServerError ( "UpdateEvent" , err )
@ -295,6 +312,7 @@ func DiscordHooksNewPost(ctx *context.Context, form auth.NewDiscordHookForm) {
HookTaskType : models . DISCORD ,
HookTaskType : models . DISCORD ,
Meta : string ( meta ) ,
Meta : string ( meta ) ,
OrgID : orCtx . OrgID ,
OrgID : orCtx . OrgID ,
IsSystemWebhook : orCtx . IsSystemWebhook ,
}
}
if err := w . UpdateEvent ( ) ; err != nil {
if err := w . UpdateEvent ( ) ; err != nil {
ctx . ServerError ( "UpdateEvent" , err )
ctx . ServerError ( "UpdateEvent" , err )
@ -335,6 +353,7 @@ func DingtalkHooksNewPost(ctx *context.Context, form auth.NewDingtalkHookForm) {
HookTaskType : models . DINGTALK ,
HookTaskType : models . DINGTALK ,
Meta : "" ,
Meta : "" ,
OrgID : orCtx . OrgID ,
OrgID : orCtx . OrgID ,
IsSystemWebhook : orCtx . IsSystemWebhook ,
}
}
if err := w . UpdateEvent ( ) ; err != nil {
if err := w . UpdateEvent ( ) ; err != nil {
ctx . ServerError ( "UpdateEvent" , err )
ctx . ServerError ( "UpdateEvent" , err )
@ -384,6 +403,7 @@ func TelegramHooksNewPost(ctx *context.Context, form auth.NewTelegramHookForm) {
HookTaskType : models . TELEGRAM ,
HookTaskType : models . TELEGRAM ,
Meta : string ( meta ) ,
Meta : string ( meta ) ,
OrgID : orCtx . OrgID ,
OrgID : orCtx . OrgID ,
IsSystemWebhook : orCtx . IsSystemWebhook ,
}
}
if err := w . UpdateEvent ( ) ; err != nil {
if err := w . UpdateEvent ( ) ; err != nil {
ctx . ServerError ( "UpdateEvent" , err )
ctx . ServerError ( "UpdateEvent" , err )
@ -424,6 +444,7 @@ func MSTeamsHooksNewPost(ctx *context.Context, form auth.NewMSTeamsHookForm) {
HookTaskType : models . MSTEAMS ,
HookTaskType : models . MSTEAMS ,
Meta : "" ,
Meta : "" ,
OrgID : orCtx . OrgID ,
OrgID : orCtx . OrgID ,
IsSystemWebhook : orCtx . IsSystemWebhook ,
}
}
if err := w . UpdateEvent ( ) ; err != nil {
if err := w . UpdateEvent ( ) ; err != nil {
ctx . ServerError ( "UpdateEvent" , err )
ctx . ServerError ( "UpdateEvent" , err )
@ -481,6 +502,7 @@ func SlackHooksNewPost(ctx *context.Context, form auth.NewSlackHookForm) {
HookTaskType : models . SLACK ,
HookTaskType : models . SLACK ,
Meta : string ( meta ) ,
Meta : string ( meta ) ,
OrgID : orCtx . OrgID ,
OrgID : orCtx . OrgID ,
IsSystemWebhook : orCtx . IsSystemWebhook ,
}
}
if err := w . UpdateEvent ( ) ; err != nil {
if err := w . UpdateEvent ( ) ; err != nil {
ctx . ServerError ( "UpdateEvent" , err )
ctx . ServerError ( "UpdateEvent" , err )
@ -521,6 +543,7 @@ func FeishuHooksNewPost(ctx *context.Context, form auth.NewFeishuHookForm) {
HookTaskType : models . FEISHU ,
HookTaskType : models . FEISHU ,
Meta : "" ,
Meta : "" ,
OrgID : orCtx . OrgID ,
OrgID : orCtx . OrgID ,
IsSystemWebhook : orCtx . IsSystemWebhook ,
}
}
if err := w . UpdateEvent ( ) ; err != nil {
if err := w . UpdateEvent ( ) ; err != nil {
ctx . ServerError ( "UpdateEvent" , err )
ctx . ServerError ( "UpdateEvent" , err )
@ -549,6 +572,8 @@ func checkWebhook(ctx *context.Context) (*orgRepoCtx, *models.Webhook) {
w , err = models . GetWebhookByRepoID ( ctx . Repo . Repository . ID , ctx . ParamsInt64 ( ":id" ) )
w , err = models . GetWebhookByRepoID ( ctx . Repo . Repository . ID , ctx . ParamsInt64 ( ":id" ) )
} else if orCtx . OrgID > 0 {
} else if orCtx . OrgID > 0 {
w , err = models . GetWebhookByOrgID ( ctx . Org . Organization . ID , ctx . ParamsInt64 ( ":id" ) )
w , err = models . GetWebhookByOrgID ( ctx . Org . Organization . ID , ctx . ParamsInt64 ( ":id" ) )
} else if orCtx . IsSystemWebhook {
w , err = models . GetSystemWebhook ( ctx . ParamsInt64 ( ":id" ) )
} else {
} else {
w , err = models . GetDefaultWebhook ( ctx . ParamsInt64 ( ":id" ) )
w , err = models . GetDefaultWebhook ( ctx . ParamsInt64 ( ":id" ) )
}
}