mirror of
https://github.com/go-gitea/gitea.git
synced 2025-04-18 00:47:48 -04:00
Some improvements
This commit is contained in:
parent
e7d5c99b42
commit
b5520f098f
@ -32,12 +32,12 @@ var nameRE = regexp.MustCompile("[^a-zA-Z0-9-_.]+")
|
|||||||
// Secret represents a secret
|
// Secret represents a secret
|
||||||
type Secret struct {
|
type Secret struct {
|
||||||
ID int64
|
ID int64
|
||||||
UserID int64 `xorm:"index"`
|
UserID int64 `xorm:"index NOTNULL"`
|
||||||
RepoID int64 `xorm:"index"`
|
RepoID int64 `xorm:"index NOTNULL"`
|
||||||
Name string
|
Name string `xorm:"NOTNULL"`
|
||||||
Data string
|
Data string `xorm:"TEXT"`
|
||||||
PullRequest bool
|
PullRequest bool `xorm:"NOTNULL"`
|
||||||
CreatedUnix timeutil.TimeStamp `xorm:"created"`
|
CreatedUnix timeutil.TimeStamp `xorm:"created NOTNULL"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates the required fields and formats.
|
// Validate validates the required fields and formats.
|
||||||
|
@ -35,6 +35,7 @@ const (
|
|||||||
SearchOrderByForksReverse SearchOrderBy = "num_forks DESC"
|
SearchOrderByForksReverse SearchOrderBy = "num_forks DESC"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// FindObjects represents a common function to find Objects from database according cond and ListOptions
|
||||||
func FindObjects[Object any](ctx context.Context, cond builder.Cond, opts *ListOptions, objects *[]*Object) error {
|
func FindObjects[Object any](ctx context.Context, cond builder.Cond, opts *ListOptions, objects *[]*Object) error {
|
||||||
sess := GetEngine(ctx).Where(cond)
|
sess := GetEngine(ctx).Where(cond)
|
||||||
if opts != nil && opts.PageSize > 0 {
|
if opts != nil && opts.PageSize > 0 {
|
||||||
|
@ -13,12 +13,12 @@ import (
|
|||||||
func createSecretsTable(x *xorm.Engine) error {
|
func createSecretsTable(x *xorm.Engine) error {
|
||||||
type Secret struct {
|
type Secret struct {
|
||||||
ID int64
|
ID int64
|
||||||
UserID int64 `xorm:"index"`
|
UserID int64 `xorm:"index NOTNULL"`
|
||||||
RepoID int64 `xorm:"index"`
|
RepoID int64 `xorm:"index NOTNULL"`
|
||||||
Name string
|
Name string `xorm:"NOTNULL"`
|
||||||
Data string
|
Data string `xorm:"TEXT"`
|
||||||
PullRequest bool
|
PullRequest bool `xorm:"NOTNULL"`
|
||||||
CreatedUnix timeutil.TimeStamp `xorm:"created"`
|
CreatedUnix timeutil.TimeStamp `xorm:"created NOTNULL"`
|
||||||
}
|
}
|
||||||
|
|
||||||
return x.Sync(new(Secret))
|
return x.Sync(new(Secret))
|
||||||
|
@ -70,11 +70,5 @@ func NewSecretKey() (string, error) {
|
|||||||
|
|
||||||
// NewMasterKey generate a new value intended to be used by MASTER_KEY.
|
// NewMasterKey generate a new value intended to be used by MASTER_KEY.
|
||||||
func NewMasterKey() ([]byte, error) {
|
func NewMasterKey() ([]byte, error) {
|
||||||
secretBytes := make([]byte, 32)
|
return util.CryptoRandomBytes(32)
|
||||||
_, err := io.ReadFull(rand.Reader, secretBytes)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return secretBytes, nil
|
|
||||||
}
|
}
|
||||||
|
@ -1124,7 +1124,7 @@ func DeployKeys(ctx *context.Context) {
|
|||||||
ctx.HTML(http.StatusOK, tplDeployKeys)
|
ctx.HTML(http.StatusOK, tplDeployKeys)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SecretsPost
|
// SecretsPost response for creating a new secret
|
||||||
func SecretsPost(ctx *context.Context) {
|
func SecretsPost(ctx *context.Context) {
|
||||||
form := web.GetForm(ctx).(*forms.AddKeyForm)
|
form := web.GetForm(ctx).(*forms.AddKeyForm)
|
||||||
if err := secret_service.InsertRepoSecret(ctx, ctx.Repo.Repository.ID, form.Title, form.Content, form.PullRequestRead); err != nil {
|
if err := secret_service.InsertRepoSecret(ctx, ctx.Repo.Repository.ID, form.Title, form.Content, form.PullRequestRead); err != nil {
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
// Copyright 2022 The Gitea Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package secrets
|
package secrets
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -21,14 +21,14 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="field {{if .Err_Title}}error{{end}}">
|
<div class="field {{if .Err_Title}}error{{end}}">
|
||||||
<label for="title">{{.locale.Tr "repo.settings.secret_key"}}</label>
|
<label for="title">{{.locale.Tr "repo.settings.secret_key"}}</label>
|
||||||
<input id="ssh-key-title" name="title" value="{{.title}}" autofocus required>
|
<input id="key-title" name="title" value="{{.title}}" autofocus required>
|
||||||
</div>
|
</div>
|
||||||
<div class="field {{if .Err_Content}}error{{end}}">
|
<div class="field {{if .Err_Content}}error{{end}}">
|
||||||
<label for="content">{{.locale.Tr "repo.settings.secret_content"}}</label>
|
<label for="content">{{.locale.Tr "repo.settings.secret_content"}}</label>
|
||||||
<textarea id="ssh-key-content" name="content" placeholder="{{.locale.Tr "repo.settings.secret_value_content_placeholder"}}" required>{{.content}}</textarea>
|
<textarea id="key-content" name="content" placeholder="{{.locale.Tr "repo.settings.secret_value_content_placeholder"}}" required>{{.content}}</textarea>
|
||||||
</div>
|
</div>
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<div class="ui checkbox {{if .Err_IsWritable}}error{{end}}">
|
<div class="ui checkbox {{if .Err_PullRequestRead}}error{{end}}">
|
||||||
<input id="pull_request_read" name="pull_request_read" class="hidden" type="checkbox" value="1">
|
<input id="pull_request_read" name="pull_request_read" class="hidden" type="checkbox" value="1">
|
||||||
<label for="is_writable">
|
<label for="is_writable">
|
||||||
{{.locale.Tr "repo.settings.pull_request_read"}}
|
{{.locale.Tr "repo.settings.pull_request_read"}}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user