Add Golangci Lint (#676)
Increase golangci timeout Fix installing golangci-lint in ci Remove mage targets replaced by golangci Run golint in ci Add goheader linter Enable & fix more linters Fix lint issues Add mage target to automagically fix issues found by golangci golangci-lint run --fix Add golangci config Add golangci mage target Co-authored-by: kolaente <k@knt.li> Reviewed-on: https://kolaente.dev/vikunja/api/pulls/676 Co-Authored-By: konrad <konrad@kola-entertainments.de> Co-Committed-By: konrad <konrad@kola-entertainments.de>
This commit is contained in:
parent
d56a611be7
commit
699d3d6060
143 changed files with 630 additions and 426 deletions
11
.drone1.yml
11
.drone1.yml
|
@ -83,16 +83,9 @@ steps:
|
||||||
depends_on: [ build ]
|
depends_on: [ build ]
|
||||||
commands:
|
commands:
|
||||||
- ./mage-static build:generate
|
- ./mage-static build:generate
|
||||||
- ./mage-static check:lint
|
|
||||||
- ./mage-static check:fmt
|
|
||||||
- ./mage-static check:got-swag
|
- ./mage-static check:got-swag
|
||||||
- ./mage-static check:ineffassign
|
- wget -O - -q https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.31.0
|
||||||
- ./mage-static check:misspell
|
- ./mage-static check:golangci
|
||||||
- ./mage-static check:goconst
|
|
||||||
- ./mage-static check:gocyclo
|
|
||||||
- ./mage-static check:static
|
|
||||||
- wget -O - -q https://raw.githubusercontent.com/securego/gosec/master/install.sh | sh -s -- -b $GOPATH/bin v2.2.0 # Need to manually install as it does not support being installed via go modules like the rest.
|
|
||||||
- ./mage-static check:gosec
|
|
||||||
when:
|
when:
|
||||||
event: [ push, tag, pull_request ]
|
event: [ push, tag, pull_request ]
|
||||||
|
|
||||||
|
|
73
.golangci.yml
Normal file
73
.golangci.yml
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
run:
|
||||||
|
timeout: 5m
|
||||||
|
tests: true
|
||||||
|
|
||||||
|
linters:
|
||||||
|
enable:
|
||||||
|
- megacheck
|
||||||
|
- govet
|
||||||
|
- goconst
|
||||||
|
- gocritic
|
||||||
|
- gocyclo
|
||||||
|
- goerr113
|
||||||
|
- goheader
|
||||||
|
- gofmt
|
||||||
|
- goimports
|
||||||
|
- golint
|
||||||
|
- misspell
|
||||||
|
disable:
|
||||||
|
- scopelint # Obsolete, using exportloopref instead
|
||||||
|
presets:
|
||||||
|
- bugs
|
||||||
|
- unused
|
||||||
|
fast: false
|
||||||
|
|
||||||
|
linter-settings:
|
||||||
|
nestif:
|
||||||
|
min-complexity: 6
|
||||||
|
goheader:
|
||||||
|
template-path: code-hesader-template.txt
|
||||||
|
|
||||||
|
issues:
|
||||||
|
exclude-rules:
|
||||||
|
# Exclude some linters from running on tests files.
|
||||||
|
- path: _test\.go
|
||||||
|
linters:
|
||||||
|
- gocyclo
|
||||||
|
- deadcode
|
||||||
|
- path: pkg/integrations/*
|
||||||
|
linters:
|
||||||
|
- gocyclo
|
||||||
|
- deadcode
|
||||||
|
- varcheck
|
||||||
|
- unparam
|
||||||
|
- bodyclose
|
||||||
|
- path: pkg/integrations/*
|
||||||
|
text: "unlambda"
|
||||||
|
linters:
|
||||||
|
- gocritic
|
||||||
|
- path: pkg/modules/background/unsplash/unsplash\.go
|
||||||
|
linters:
|
||||||
|
- bodyclose
|
||||||
|
- path: pkg/migration/*
|
||||||
|
linters:
|
||||||
|
- exhaustive
|
||||||
|
- goconst
|
||||||
|
- goerr113
|
||||||
|
- path: pkg/models/task_collection_filter\.go
|
||||||
|
linters:
|
||||||
|
- exhaustive
|
||||||
|
- path: pkg/utils/random_string\.go
|
||||||
|
text: "G404:" # We don't care about cryptographically secure randomness when we're using that utility function.
|
||||||
|
linters:
|
||||||
|
- gosec
|
||||||
|
- path: pkg/modules/dump/*
|
||||||
|
linters:
|
||||||
|
- goerr113
|
||||||
|
- path: pkg/
|
||||||
|
text: "err113: do not define dynamic errors, use wrapped static errors instead:"
|
||||||
|
linters:
|
||||||
|
- goerr113
|
||||||
|
- text: "commentFormatting: put a space between `//` and comment text"
|
||||||
|
linters:
|
||||||
|
- gocritic
|
15
code-header-template.txt
Normal file
15
code-header-template.txt
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
Vikunja is a to-do list application to facilitate your life.
|
||||||
|
Copyright 2018-2020 Vikunja and contributors. All rights reserved.
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
1
go.mod
1
go.mod
|
@ -33,6 +33,7 @@ require (
|
||||||
github.com/fzipp/gocyclo v0.0.0-20150627053110-6acd4345c835
|
github.com/fzipp/gocyclo v0.0.0-20150627053110-6acd4345c835
|
||||||
github.com/gabriel-vasile/mimetype v1.1.1
|
github.com/gabriel-vasile/mimetype v1.1.1
|
||||||
github.com/getsentry/sentry-go v0.7.0
|
github.com/getsentry/sentry-go v0.7.0
|
||||||
|
github.com/go-errors/errors v1.0.1
|
||||||
github.com/go-redis/redis/v7 v7.4.0
|
github.com/go-redis/redis/v7 v7.4.0
|
||||||
github.com/go-sql-driver/mysql v1.5.0
|
github.com/go-sql-driver/mysql v1.5.0
|
||||||
github.com/go-testfixtures/testfixtures/v3 v3.4.0
|
github.com/go-testfixtures/testfixtures/v3 v3.4.0
|
||||||
|
|
89
magefile.go
89
magefile.go
|
@ -59,7 +59,6 @@ var (
|
||||||
Aliases = map[string]interface{}{
|
Aliases = map[string]interface{}{
|
||||||
"build": Build.Build,
|
"build": Build.Build,
|
||||||
"do-the-swag": DoTheSwag,
|
"do-the-swag": DoTheSwag,
|
||||||
"check:go-sec": Check.GoSec,
|
|
||||||
"check:got-swag": Check.GotSwag,
|
"check:got-swag": Check.GotSwag,
|
||||||
"release:os-package": Release.OsPackage,
|
"release:os-package": Release.OsPackage,
|
||||||
"dev:create-migration": Dev.CreateMigration,
|
"dev:create-migration": Dev.CreateMigration,
|
||||||
|
@ -330,34 +329,6 @@ func (Test) Integration() {
|
||||||
|
|
||||||
type Check mg.Namespace
|
type Check mg.Namespace
|
||||||
|
|
||||||
// Checks if the code is properly formatted with go fmt
|
|
||||||
func (Check) Fmt() error {
|
|
||||||
mg.Deps(initVars)
|
|
||||||
args := append([]string{"-s", "-d"}, GoFiles...)
|
|
||||||
c := exec.Command("gofmt", args...)
|
|
||||||
out, err := c.Output()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(out) > 0 {
|
|
||||||
fmt.Println("Code is not properly gofmt'ed.")
|
|
||||||
fmt.Println("Please run 'mage fmt' and commit the result:")
|
|
||||||
fmt.Print(string(out))
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Runs golint on all packages
|
|
||||||
func (Check) Lint() {
|
|
||||||
mg.Deps(initVars)
|
|
||||||
checkAndInstallGoTool("golint", "golang.org/x/lint/golint")
|
|
||||||
args := append([]string{"-set_exit_status"}, ApiPackages...)
|
|
||||||
runAndStreamOutput("golint", args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Checks if the swagger docs need to be re-generated from the code annotations
|
// Checks if the swagger docs need to be re-generated from the code annotations
|
||||||
func (Check) GotSwag() {
|
func (Check) GotSwag() {
|
||||||
mg.Deps(initVars)
|
mg.Deps(initVars)
|
||||||
|
@ -388,65 +359,31 @@ func (Check) GotSwag() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Checks the source code for misspellings
|
func checkGolangCiLintInstalled() {
|
||||||
func (Check) Misspell() {
|
|
||||||
mg.Deps(initVars)
|
mg.Deps(initVars)
|
||||||
checkAndInstallGoTool("misspell", "github.com/client9/misspell/cmd/misspell")
|
if err := exec.Command("golangci-lint").Run(); err != nil && strings.Contains(err.Error(), "executable file not found") {
|
||||||
runAndStreamOutput("misspell", append([]string{"-error"}, GoFiles...)...)
|
fmt.Println("Please manually install golangci-lint by running")
|
||||||
}
|
fmt.Println("curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.31.0")
|
||||||
|
|
||||||
// Checks the source code for ineffectual assigns
|
|
||||||
func (Check) Ineffassign() {
|
|
||||||
mg.Deps(initVars)
|
|
||||||
checkAndInstallGoTool("ineffassign", "github.com/gordonklaus/ineffassign")
|
|
||||||
runAndStreamOutput("ineffassign", GoFiles...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Checks for the cyclomatic complexity of the source code
|
|
||||||
func (Check) Gocyclo() {
|
|
||||||
mg.Deps(initVars)
|
|
||||||
checkAndInstallGoTool("gocyclo", "github.com/fzipp/gocyclo")
|
|
||||||
runAndStreamOutput("gocyclo", append([]string{"-over", "49"}, GoFiles...)...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Statically analyzes the source code about a range of different problems
|
|
||||||
func (Check) Static() {
|
|
||||||
mg.Deps(initVars)
|
|
||||||
checkAndInstallGoTool("staticcheck", "honnef.co/go/tools/cmd/staticcheck")
|
|
||||||
runAndStreamOutput("staticcheck", ApiPackages...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Checks the source code for potential security issues
|
|
||||||
func (Check) GoSec() {
|
|
||||||
mg.Deps(initVars)
|
|
||||||
if err := exec.Command("gosec").Run(); err != nil && strings.Contains(err.Error(), "executable file not found") {
|
|
||||||
fmt.Println("Please manually install gosec by running")
|
|
||||||
fmt.Println("curl -sfL https://raw.githubusercontent.com/securego/gosec/master/install.sh | bash -s -- -b $GOPATH/bin v2.2.0")
|
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
runAndStreamOutput("gosec", "./...")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Checks for repeated strings that could be replaced by a constant
|
func (Check) Golangci() {
|
||||||
func (Check) Goconst() {
|
checkGolangCiLintInstalled()
|
||||||
mg.Deps(initVars)
|
runAndStreamOutput("golangci-lint", "run")
|
||||||
checkAndInstallGoTool("goconst", "github.com/jgautheron/goconst/cmd/goconst")
|
}
|
||||||
runAndStreamOutput("goconst", ApiPackages...)
|
|
||||||
|
func (Check) GolangciFix() {
|
||||||
|
checkGolangCiLintInstalled()
|
||||||
|
runAndStreamOutput("golangci-lint", "run", "--fix")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Runs fmt-check, lint, got-swag, misspell-check, ineffasign-check, gocyclo-check, static-check, gosec-check, goconst-check all in parallel
|
// Runs fmt-check, lint, got-swag, misspell-check, ineffasign-check, gocyclo-check, static-check, gosec-check, goconst-check all in parallel
|
||||||
func (Check) All() {
|
func (Check) All() {
|
||||||
mg.Deps(initVars)
|
mg.Deps(initVars)
|
||||||
mg.Deps(
|
mg.Deps(
|
||||||
Check.Fmt,
|
Check.Golangci,
|
||||||
Check.Lint,
|
|
||||||
Check.GotSwag,
|
Check.GotSwag,
|
||||||
Check.Misspell,
|
|
||||||
Check.Ineffassign,
|
|
||||||
Check.Gocyclo,
|
|
||||||
Check.Static,
|
|
||||||
Check.GoSec,
|
|
||||||
Check.Goconst,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,13 +17,14 @@
|
||||||
package caldav
|
package caldav
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"code.vikunja.io/api/pkg/config"
|
|
||||||
"code.vikunja.io/api/pkg/user"
|
|
||||||
"code.vikunja.io/api/pkg/utils"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"code.vikunja.io/api/pkg/config"
|
||||||
|
"code.vikunja.io/api/pkg/user"
|
||||||
|
"code.vikunja.io/api/pkg/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
// DateFormat ist the caldav date format
|
// DateFormat ist the caldav date format
|
||||||
|
|
|
@ -17,10 +17,11 @@
|
||||||
package caldav
|
package caldav
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"code.vikunja.io/api/pkg/config"
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"code.vikunja.io/api/pkg/config"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestParseEvents(t *testing.T) {
|
func TestParseEvents(t *testing.T) {
|
||||||
|
|
|
@ -18,8 +18,9 @@ package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/spf13/cobra"
|
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
var rootCmd = &cobra.Command{
|
var rootCmd = &cobra.Command{
|
||||||
|
|
|
@ -17,11 +17,12 @@
|
||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
"code.vikunja.io/api/pkg/initialize"
|
"code.vikunja.io/api/pkg/initialize"
|
||||||
"code.vikunja.io/api/pkg/log"
|
"code.vikunja.io/api/pkg/log"
|
||||||
"code.vikunja.io/api/pkg/modules/dump"
|
"code.vikunja.io/api/pkg/modules/dump"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
|
@ -18,17 +18,18 @@
|
||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"code.vikunja.io/api/pkg/initialize"
|
|
||||||
"code.vikunja.io/api/pkg/log"
|
|
||||||
"code.vikunja.io/api/pkg/user"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/olekukonko/tablewriter"
|
|
||||||
"github.com/spf13/cobra"
|
|
||||||
"golang.org/x/crypto/ssh/terminal"
|
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"code.vikunja.io/api/pkg/initialize"
|
||||||
|
"code.vikunja.io/api/pkg/log"
|
||||||
|
"code.vikunja.io/api/pkg/user"
|
||||||
|
"github.com/olekukonko/tablewriter"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
"golang.org/x/crypto/ssh/terminal"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
|
@ -17,10 +17,11 @@
|
||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"code.vikunja.io/api/pkg/version"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/spf13/cobra"
|
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
|
"code.vikunja.io/api/pkg/version"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
|
@ -17,17 +17,18 @@
|
||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
"os"
|
||||||
|
"os/signal"
|
||||||
|
"time"
|
||||||
|
|
||||||
"code.vikunja.io/api/pkg/config"
|
"code.vikunja.io/api/pkg/config"
|
||||||
"code.vikunja.io/api/pkg/initialize"
|
"code.vikunja.io/api/pkg/initialize"
|
||||||
"code.vikunja.io/api/pkg/log"
|
"code.vikunja.io/api/pkg/log"
|
||||||
"code.vikunja.io/api/pkg/routes"
|
"code.vikunja.io/api/pkg/routes"
|
||||||
"code.vikunja.io/api/pkg/swagger"
|
"code.vikunja.io/api/pkg/swagger"
|
||||||
"code.vikunja.io/api/pkg/version"
|
"code.vikunja.io/api/pkg/version"
|
||||||
"context"
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"os"
|
|
||||||
"os/signal"
|
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
16
pkg/db/db.go
16
pkg/db/db.go
|
@ -17,16 +17,17 @@
|
||||||
package db
|
package db
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"code.vikunja.io/api/pkg/config"
|
|
||||||
"code.vikunja.io/api/pkg/log"
|
|
||||||
"encoding/gob"
|
"encoding/gob"
|
||||||
"fmt"
|
"fmt"
|
||||||
xrc "gitea.com/xorm/xorm-redis-cache"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"code.vikunja.io/api/pkg/config"
|
||||||
|
"code.vikunja.io/api/pkg/log"
|
||||||
|
xrc "gitea.com/xorm/xorm-redis-cache"
|
||||||
"xorm.io/core"
|
"xorm.io/core"
|
||||||
"xorm.io/xorm"
|
"xorm.io/xorm"
|
||||||
"xorm.io/xorm/caches"
|
"xorm.io/xorm/caches"
|
||||||
|
@ -52,23 +53,24 @@ func CreateDBEngine() (engine *xorm.Engine, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use Mysql if set
|
// Use Mysql if set
|
||||||
if config.DatabaseType.GetString() == "mysql" {
|
switch config.DatabaseType.GetString() {
|
||||||
|
case "mysql":
|
||||||
engine, err = initMysqlEngine()
|
engine, err = initMysqlEngine()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else if config.DatabaseType.GetString() == "postgres" {
|
case "postgres":
|
||||||
engine, err = initPostgresEngine()
|
engine, err = initPostgresEngine()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else if config.DatabaseType.GetString() == "sqlite" {
|
case "sqlite":
|
||||||
// Otherwise use sqlite
|
// Otherwise use sqlite
|
||||||
engine, err = initSqliteEngine()
|
engine, err = initSqliteEngine()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else {
|
default:
|
||||||
log.Fatalf("Unknown database type %s", config.DatabaseType.GetString())
|
log.Fatalf("Unknown database type %s", config.DatabaseType.GetString())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,12 +18,13 @@
|
||||||
package db
|
package db
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"code.vikunja.io/api/pkg/config"
|
|
||||||
"code.vikunja.io/api/pkg/log"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"code.vikunja.io/api/pkg/config"
|
||||||
|
"code.vikunja.io/api/pkg/log"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
"xorm.io/core"
|
"xorm.io/core"
|
||||||
"xorm.io/xorm"
|
"xorm.io/xorm"
|
||||||
)
|
)
|
||||||
|
|
|
@ -18,12 +18,13 @@
|
||||||
package db
|
package db
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"code.vikunja.io/api/pkg/config"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/go-testfixtures/testfixtures/v3"
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"code.vikunja.io/api/pkg/config"
|
||||||
|
"github.com/go-testfixtures/testfixtures/v3"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
"xorm.io/xorm/schemas"
|
"xorm.io/xorm/schemas"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ func (err ErrFileDoesNotExist) Error() string {
|
||||||
return fmt.Sprintf("file %d does not exist", err.FileID)
|
return fmt.Sprintf("file %d does not exist", err.FileID)
|
||||||
}
|
}
|
||||||
|
|
||||||
//IsErrFileDoesNotExist checks if an error is ErrFileDoesNotExist
|
// IsErrFileDoesNotExist checks if an error is ErrFileDoesNotExist
|
||||||
func IsErrFileDoesNotExist(err error) bool {
|
func IsErrFileDoesNotExist(err error) bool {
|
||||||
_, ok := err.(ErrFileDoesNotExist)
|
_, ok := err.(ErrFileDoesNotExist)
|
||||||
return ok
|
return ok
|
||||||
|
@ -45,7 +45,7 @@ func (err ErrFileIsTooLarge) Error() string {
|
||||||
return fmt.Sprintf("file is too large [Size: %d]", err.Size)
|
return fmt.Sprintf("file is too large [Size: %d]", err.Size)
|
||||||
}
|
}
|
||||||
|
|
||||||
//IsErrFileIsTooLarge checks if an error is ErrFileIsTooLarge
|
// IsErrFileIsTooLarge checks if an error is ErrFileIsTooLarge
|
||||||
func IsErrFileIsTooLarge(err error) bool {
|
func IsErrFileIsTooLarge(err error) bool {
|
||||||
_, ok := err.(ErrFileIsTooLarge)
|
_, ok := err.(ErrFileIsTooLarge)
|
||||||
return ok
|
return ok
|
||||||
|
@ -62,7 +62,7 @@ func (err ErrFileIsNotUnsplashFile) Error() string {
|
||||||
return fmt.Sprintf("file was not downloaded from unsplash [FileID: %d]", err.FileID)
|
return fmt.Sprintf("file was not downloaded from unsplash [FileID: %d]", err.FileID)
|
||||||
}
|
}
|
||||||
|
|
||||||
//IsErrFileIsNotUnsplashFile checks if an error is ErrFileIsNotUnsplashFile
|
// IsErrFileIsNotUnsplashFile checks if an error is ErrFileIsNotUnsplashFile
|
||||||
func IsErrFileIsNotUnsplashFile(err error) bool {
|
func IsErrFileIsNotUnsplashFile(err error) bool {
|
||||||
_, ok := err.(ErrFileIsNotUnsplashFile)
|
_, ok := err.(ErrFileIsNotUnsplashFile)
|
||||||
return ok
|
return ok
|
||||||
|
|
|
@ -17,13 +17,14 @@
|
||||||
package files
|
package files
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
|
||||||
"code.vikunja.io/api/pkg/config"
|
"code.vikunja.io/api/pkg/config"
|
||||||
"code.vikunja.io/api/pkg/db"
|
"code.vikunja.io/api/pkg/db"
|
||||||
"code.vikunja.io/api/pkg/log"
|
"code.vikunja.io/api/pkg/log"
|
||||||
"github.com/spf13/afero"
|
"github.com/spf13/afero"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"os"
|
|
||||||
"testing"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// This file handles storing and retrieving a file for different backends
|
// This file handles storing and retrieving a file for different backends
|
||||||
|
@ -49,7 +50,7 @@ func initFixtures(t *testing.T) {
|
||||||
InitTestFileFixtures(t)
|
InitTestFileFixtures(t)
|
||||||
}
|
}
|
||||||
|
|
||||||
//InitTestFileFixtures initializes file fixtures
|
// InitTestFileFixtures initializes file fixtures
|
||||||
func InitTestFileFixtures(t *testing.T) {
|
func InitTestFileFixtures(t *testing.T) {
|
||||||
// Init fixture files
|
// Init fixture files
|
||||||
filename := config.FilesBasePath.GetString() + "/1"
|
filename := config.FilesBasePath.GetString() + "/1"
|
||||||
|
|
|
@ -17,13 +17,14 @@
|
||||||
package files
|
package files
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io"
|
||||||
|
"strconv"
|
||||||
|
"time"
|
||||||
|
|
||||||
"code.vikunja.io/api/pkg/config"
|
"code.vikunja.io/api/pkg/config"
|
||||||
"code.vikunja.io/web"
|
"code.vikunja.io/web"
|
||||||
"github.com/c2h5oh/datasize"
|
"github.com/c2h5oh/datasize"
|
||||||
"github.com/spf13/afero"
|
"github.com/spf13/afero"
|
||||||
"io"
|
|
||||||
"strconv"
|
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// File holds all information about a file
|
// File holds all information about a file
|
||||||
|
|
|
@ -18,10 +18,11 @@
|
||||||
package files
|
package files
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
type testfile struct {
|
type testfile struct {
|
||||||
|
|
|
@ -18,11 +18,12 @@
|
||||||
package integrations
|
package integrations
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net/url"
|
||||||
|
"testing"
|
||||||
|
|
||||||
"code.vikunja.io/api/pkg/models"
|
"code.vikunja.io/api/pkg/models"
|
||||||
"code.vikunja.io/web/handler"
|
"code.vikunja.io/web/handler"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"net/url"
|
|
||||||
"testing"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// This tests the following behaviour:
|
// This tests the following behaviour:
|
||||||
|
|
|
@ -17,6 +17,13 @@
|
||||||
package integrations
|
package integrations
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
|
"net/url"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
"code.vikunja.io/api/pkg/config"
|
"code.vikunja.io/api/pkg/config"
|
||||||
"code.vikunja.io/api/pkg/db"
|
"code.vikunja.io/api/pkg/db"
|
||||||
"code.vikunja.io/api/pkg/files"
|
"code.vikunja.io/api/pkg/files"
|
||||||
|
@ -29,12 +36,6 @@ import (
|
||||||
"github.com/dgrijalva/jwt-go"
|
"github.com/dgrijalva/jwt-go"
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"net/http"
|
|
||||||
"net/http/httptest"
|
|
||||||
"net/url"
|
|
||||||
"os"
|
|
||||||
"strings"
|
|
||||||
"testing"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// These are the test users, the same way they are in the test database
|
// These are the test users, the same way they are in the test database
|
||||||
|
|
|
@ -17,11 +17,12 @@
|
||||||
package integrations
|
package integrations
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
"code.vikunja.io/api/pkg/models"
|
"code.vikunja.io/api/pkg/models"
|
||||||
"code.vikunja.io/web/handler"
|
"code.vikunja.io/web/handler"
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"testing"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestBucket(t *testing.T) {
|
func TestBucket(t *testing.T) {
|
||||||
|
|
|
@ -17,12 +17,13 @@
|
||||||
package integrations
|
package integrations
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net/url"
|
||||||
|
"testing"
|
||||||
|
|
||||||
"code.vikunja.io/api/pkg/models"
|
"code.vikunja.io/api/pkg/models"
|
||||||
"code.vikunja.io/web/handler"
|
"code.vikunja.io/web/handler"
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"net/url"
|
|
||||||
"testing"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestLinkSharing(t *testing.T) {
|
func TestLinkSharing(t *testing.T) {
|
||||||
|
|
|
@ -17,12 +17,13 @@
|
||||||
package integrations
|
package integrations
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net/url"
|
||||||
|
"testing"
|
||||||
|
|
||||||
"code.vikunja.io/api/pkg/models"
|
"code.vikunja.io/api/pkg/models"
|
||||||
"code.vikunja.io/web/handler"
|
"code.vikunja.io/web/handler"
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"net/url"
|
|
||||||
"testing"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestList(t *testing.T) {
|
func TestList(t *testing.T) {
|
||||||
|
|
|
@ -17,11 +17,12 @@
|
||||||
package integrations
|
package integrations
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net/http"
|
||||||
|
"testing"
|
||||||
|
|
||||||
apiv1 "code.vikunja.io/api/pkg/routes/api/v1"
|
apiv1 "code.vikunja.io/api/pkg/routes/api/v1"
|
||||||
"code.vikunja.io/api/pkg/user"
|
"code.vikunja.io/api/pkg/user"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"net/http"
|
|
||||||
"testing"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestLogin(t *testing.T) {
|
func TestLogin(t *testing.T) {
|
||||||
|
|
|
@ -17,11 +17,12 @@
|
||||||
package integrations
|
package integrations
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net/http"
|
||||||
|
"testing"
|
||||||
|
|
||||||
apiv1 "code.vikunja.io/api/pkg/routes/api/v1"
|
apiv1 "code.vikunja.io/api/pkg/routes/api/v1"
|
||||||
"code.vikunja.io/api/pkg/user"
|
"code.vikunja.io/api/pkg/user"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"net/http"
|
|
||||||
"testing"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestRegister(t *testing.T) {
|
func TestRegister(t *testing.T) {
|
||||||
|
|
|
@ -18,11 +18,12 @@
|
||||||
package integrations
|
package integrations
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net/url"
|
||||||
|
"testing"
|
||||||
|
|
||||||
"code.vikunja.io/api/pkg/models"
|
"code.vikunja.io/api/pkg/models"
|
||||||
"code.vikunja.io/web/handler"
|
"code.vikunja.io/web/handler"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"net/url"
|
|
||||||
"testing"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestTaskCollection(t *testing.T) {
|
func TestTaskCollection(t *testing.T) {
|
||||||
|
|
|
@ -17,11 +17,12 @@
|
||||||
package integrations
|
package integrations
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
"code.vikunja.io/api/pkg/models"
|
"code.vikunja.io/api/pkg/models"
|
||||||
"code.vikunja.io/web/handler"
|
"code.vikunja.io/web/handler"
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"testing"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestTaskComments(t *testing.T) {
|
func TestTaskComments(t *testing.T) {
|
||||||
|
|
|
@ -17,11 +17,12 @@
|
||||||
package integrations
|
package integrations
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
"code.vikunja.io/api/pkg/models"
|
"code.vikunja.io/api/pkg/models"
|
||||||
"code.vikunja.io/web/handler"
|
"code.vikunja.io/web/handler"
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"testing"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestTask(t *testing.T) {
|
func TestTask(t *testing.T) {
|
||||||
|
|
|
@ -17,10 +17,11 @@
|
||||||
package integrations
|
package integrations
|
||||||
|
|
||||||
import (
|
import (
|
||||||
apiv1 "code.vikunja.io/api/pkg/routes/api/v1"
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
apiv1 "code.vikunja.io/api/pkg/routes/api/v1"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCheckToken(t *testing.T) {
|
func TestCheckToken(t *testing.T) {
|
||||||
|
|
|
@ -17,11 +17,12 @@
|
||||||
package integrations
|
package integrations
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net/http"
|
||||||
|
"testing"
|
||||||
|
|
||||||
apiv1 "code.vikunja.io/api/pkg/routes/api/v1"
|
apiv1 "code.vikunja.io/api/pkg/routes/api/v1"
|
||||||
"code.vikunja.io/api/pkg/user"
|
"code.vikunja.io/api/pkg/user"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"net/http"
|
|
||||||
"testing"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestUserChangePassword(t *testing.T) {
|
func TestUserChangePassword(t *testing.T) {
|
||||||
|
|
|
@ -17,12 +17,13 @@
|
||||||
package integrations
|
package integrations
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net/http"
|
||||||
|
"testing"
|
||||||
|
|
||||||
apiv1 "code.vikunja.io/api/pkg/routes/api/v1"
|
apiv1 "code.vikunja.io/api/pkg/routes/api/v1"
|
||||||
"code.vikunja.io/api/pkg/user"
|
"code.vikunja.io/api/pkg/user"
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"net/http"
|
|
||||||
"testing"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestUserConfirmEmail(t *testing.T) {
|
func TestUserConfirmEmail(t *testing.T) {
|
||||||
|
|
|
@ -17,10 +17,11 @@
|
||||||
package integrations
|
package integrations
|
||||||
|
|
||||||
import (
|
import (
|
||||||
apiv1 "code.vikunja.io/api/pkg/routes/api/v1"
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
apiv1 "code.vikunja.io/api/pkg/routes/api/v1"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestUserList(t *testing.T) {
|
func TestUserList(t *testing.T) {
|
||||||
|
|
|
@ -17,12 +17,13 @@
|
||||||
package integrations
|
package integrations
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net/http"
|
||||||
|
"testing"
|
||||||
|
|
||||||
apiv1 "code.vikunja.io/api/pkg/routes/api/v1"
|
apiv1 "code.vikunja.io/api/pkg/routes/api/v1"
|
||||||
"code.vikunja.io/api/pkg/user"
|
"code.vikunja.io/api/pkg/user"
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"net/http"
|
|
||||||
"testing"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestUserRequestResetPasswordToken(t *testing.T) {
|
func TestUserRequestResetPasswordToken(t *testing.T) {
|
||||||
|
|
|
@ -17,12 +17,13 @@
|
||||||
package integrations
|
package integrations
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net/http"
|
||||||
|
"testing"
|
||||||
|
|
||||||
apiv1 "code.vikunja.io/api/pkg/routes/api/v1"
|
apiv1 "code.vikunja.io/api/pkg/routes/api/v1"
|
||||||
"code.vikunja.io/api/pkg/user"
|
"code.vikunja.io/api/pkg/user"
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"net/http"
|
|
||||||
"testing"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestUserPasswordReset(t *testing.T) {
|
func TestUserPasswordReset(t *testing.T) {
|
||||||
|
|
|
@ -17,10 +17,11 @@
|
||||||
package integrations
|
package integrations
|
||||||
|
|
||||||
import (
|
import (
|
||||||
apiv1 "code.vikunja.io/api/pkg/routes/api/v1"
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
apiv1 "code.vikunja.io/api/pkg/routes/api/v1"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestUserShow(t *testing.T) {
|
func TestUserShow(t *testing.T) {
|
||||||
|
|
|
@ -17,13 +17,14 @@
|
||||||
package log
|
package log
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"code.vikunja.io/api/pkg/config"
|
|
||||||
"github.com/op/go-logging"
|
|
||||||
"github.com/spf13/viper"
|
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"code.vikunja.io/api/pkg/config"
|
||||||
|
"github.com/op/go-logging"
|
||||||
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ErrFmt holds the format for all the console logging
|
// ErrFmt holds the format for all the console logging
|
||||||
|
@ -105,7 +106,6 @@ func GetLogger() *logging.Logger {
|
||||||
return logInstance
|
return logInstance
|
||||||
}
|
}
|
||||||
|
|
||||||
/////
|
|
||||||
// The following functions are to be used as an "eye-candy", so one can just write log.Error() instead of log.Log.Error()
|
// The following functions are to be used as an "eye-candy", so one can just write log.Error() instead of log.Log.Error()
|
||||||
|
|
||||||
// Debug is for debug messages
|
// Debug is for debug messages
|
||||||
|
|
|
@ -17,10 +17,11 @@
|
||||||
package log
|
package log
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"code.vikunja.io/api/pkg/config"
|
|
||||||
"github.com/op/go-logging"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"code.vikunja.io/api/pkg/config"
|
||||||
|
"github.com/op/go-logging"
|
||||||
"xorm.io/xorm/log"
|
"xorm.io/xorm/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -17,11 +17,12 @@
|
||||||
package mail
|
package mail
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/tls"
|
||||||
|
"time"
|
||||||
|
|
||||||
"code.vikunja.io/api/pkg/config"
|
"code.vikunja.io/api/pkg/config"
|
||||||
"code.vikunja.io/api/pkg/log"
|
"code.vikunja.io/api/pkg/log"
|
||||||
"crypto/tls"
|
|
||||||
"gopkg.in/gomail.v2"
|
"gopkg.in/gomail.v2"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Queue is the mail queue
|
// Queue is the mail queue
|
||||||
|
|
|
@ -18,13 +18,14 @@ package mail
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"html/template"
|
||||||
|
|
||||||
"code.vikunja.io/api/pkg/config"
|
"code.vikunja.io/api/pkg/config"
|
||||||
"code.vikunja.io/api/pkg/log"
|
"code.vikunja.io/api/pkg/log"
|
||||||
"code.vikunja.io/api/pkg/static"
|
"code.vikunja.io/api/pkg/static"
|
||||||
"code.vikunja.io/api/pkg/utils"
|
"code.vikunja.io/api/pkg/utils"
|
||||||
"github.com/shurcooL/httpfs/html/vfstemplate"
|
"github.com/shurcooL/httpfs/html/vfstemplate"
|
||||||
"gopkg.in/gomail.v2"
|
"gopkg.in/gomail.v2"
|
||||||
"html/template"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Opts holds infos for a mail
|
// Opts holds infos for a mail
|
||||||
|
|
|
@ -17,13 +17,14 @@
|
||||||
package metrics
|
package metrics
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
"code.vikunja.io/api/pkg/log"
|
"code.vikunja.io/api/pkg/log"
|
||||||
"code.vikunja.io/api/pkg/modules/keyvalue"
|
"code.vikunja.io/api/pkg/modules/keyvalue"
|
||||||
"code.vikunja.io/web"
|
"code.vikunja.io/web"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
"github.com/prometheus/client_golang/prometheus/promauto"
|
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||||
"sync"
|
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// SecondsUntilInactive defines the seconds until a user is considered inactive
|
// SecondsUntilInactive defines the seconds until a user is considered inactive
|
||||||
|
|
|
@ -18,6 +18,7 @@ package migration
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math"
|
"math"
|
||||||
|
|
||||||
"src.techknowlogick.com/xormigrate"
|
"src.techknowlogick.com/xormigrate"
|
||||||
"xorm.io/xorm"
|
"xorm.io/xorm"
|
||||||
)
|
)
|
||||||
|
|
|
@ -17,8 +17,9 @@
|
||||||
package migration
|
package migration
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"src.techknowlogick.com/xormigrate"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"src.techknowlogick.com/xormigrate"
|
||||||
"xorm.io/xorm"
|
"xorm.io/xorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -55,7 +56,7 @@ func init() {
|
||||||
// The general idea here is to take the title and slice it into pieces, until we found a unique piece.
|
// The general idea here is to take the title and slice it into pieces, until we found a unique piece.
|
||||||
|
|
||||||
var exists = true
|
var exists = true
|
||||||
titleSlug := []rune(strings.Replace(strings.ToUpper(l.Title), " ", "", -1))
|
titleSlug := []rune(strings.ReplaceAll(strings.ToUpper(l.Title), " ", ""))
|
||||||
|
|
||||||
// We can save at most 10 characters in the db, so we need to ensure it has at most 10 characters
|
// We can save at most 10 characters in the db, so we need to ensure it has at most 10 characters
|
||||||
if len(titleSlug) > 10 {
|
if len(titleSlug) > 10 {
|
||||||
|
|
|
@ -18,8 +18,9 @@ package migration
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"src.techknowlogick.com/xormigrate"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"src.techknowlogick.com/xormigrate"
|
||||||
"xorm.io/xorm"
|
"xorm.io/xorm"
|
||||||
"xorm.io/xorm/schemas"
|
"xorm.io/xorm/schemas"
|
||||||
)
|
)
|
||||||
|
@ -654,7 +655,7 @@ create unique index UQE_users_namespace_id
|
||||||
// The statement is probably useless anyway since its only purpose is to clean up old tables
|
// The statement is probably useless anyway since its only purpose is to clean up old tables
|
||||||
// which may be leftovers from a previously failed migration. However, since the whole thing
|
// which may be leftovers from a previously failed migration. However, since the whole thing
|
||||||
// is wrapped in sessions, this is extremely unlikely to happen anyway.
|
// is wrapped in sessions, this is extremely unlikely to happen anyway.
|
||||||
//"ALTER TABLE " + table + " DROP COLUMN IF EXISTS " + colTmp + ";",
|
// "ALTER TABLE " + table + " DROP COLUMN IF EXISTS " + colTmp + ";",
|
||||||
"ALTER TABLE " + table + " ADD COLUMN " + colTmp + " DATETIME NULL;",
|
"ALTER TABLE " + table + " ADD COLUMN " + colTmp + " DATETIME NULL;",
|
||||||
// #nosec
|
// #nosec
|
||||||
"UPDATE " + table + " SET " + colTmp + " = IF(" + colOld + " = 0, NULL, FROM_UNIXTIME(" + colOld + "));",
|
"UPDATE " + table + " SET " + colTmp + " = IF(" + colOld + " = 0, NULL, FROM_UNIXTIME(" + colOld + "));",
|
||||||
|
|
|
@ -17,9 +17,10 @@
|
||||||
package migration
|
package migration
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
"code.vikunja.io/api/pkg/models"
|
"code.vikunja.io/api/pkg/models"
|
||||||
"src.techknowlogick.com/xormigrate"
|
"src.techknowlogick.com/xormigrate"
|
||||||
"time"
|
|
||||||
"xorm.io/xorm"
|
"xorm.io/xorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,9 @@
|
||||||
package migration
|
package migration
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
|
"sort"
|
||||||
|
|
||||||
"code.vikunja.io/api/pkg/config"
|
"code.vikunja.io/api/pkg/config"
|
||||||
"code.vikunja.io/api/pkg/db"
|
"code.vikunja.io/api/pkg/db"
|
||||||
"code.vikunja.io/api/pkg/files"
|
"code.vikunja.io/api/pkg/files"
|
||||||
|
@ -25,8 +28,6 @@ import (
|
||||||
"code.vikunja.io/api/pkg/modules/migration"
|
"code.vikunja.io/api/pkg/modules/migration"
|
||||||
"code.vikunja.io/api/pkg/user"
|
"code.vikunja.io/api/pkg/user"
|
||||||
"github.com/olekukonko/tablewriter"
|
"github.com/olekukonko/tablewriter"
|
||||||
"os"
|
|
||||||
"sort"
|
|
||||||
"src.techknowlogick.com/xormigrate"
|
"src.techknowlogick.com/xormigrate"
|
||||||
"xorm.io/xorm"
|
"xorm.io/xorm"
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
"code.vikunja.io/api/pkg/db"
|
"code.vikunja.io/api/pkg/db"
|
||||||
"code.vikunja.io/api/pkg/user"
|
"code.vikunja.io/api/pkg/user"
|
||||||
"testing"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestBulkTask_Update(t *testing.T) {
|
func TestBulkTask_Update(t *testing.T) {
|
||||||
|
|
|
@ -17,10 +17,11 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"code.vikunja.io/api/pkg/config"
|
|
||||||
"code.vikunja.io/web"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"code.vikunja.io/api/pkg/config"
|
||||||
|
"code.vikunja.io/web"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Generic
|
// Generic
|
||||||
|
|
|
@ -17,10 +17,11 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
"code.vikunja.io/api/pkg/log"
|
"code.vikunja.io/api/pkg/log"
|
||||||
"code.vikunja.io/api/pkg/user"
|
"code.vikunja.io/api/pkg/user"
|
||||||
"code.vikunja.io/web"
|
"code.vikunja.io/web"
|
||||||
"time"
|
|
||||||
"xorm.io/xorm"
|
"xorm.io/xorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -17,10 +17,11 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
"code.vikunja.io/api/pkg/db"
|
"code.vikunja.io/api/pkg/db"
|
||||||
"code.vikunja.io/api/pkg/user"
|
"code.vikunja.io/api/pkg/user"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"testing"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestBucket_ReadAll(t *testing.T) {
|
func TestBucket_ReadAll(t *testing.T) {
|
||||||
|
|
|
@ -17,9 +17,10 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
"code.vikunja.io/api/pkg/user"
|
"code.vikunja.io/api/pkg/user"
|
||||||
"code.vikunja.io/web"
|
"code.vikunja.io/web"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Label represents a label
|
// Label represents a label
|
||||||
|
|
|
@ -17,9 +17,10 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
"code.vikunja.io/api/pkg/user"
|
"code.vikunja.io/api/pkg/user"
|
||||||
"code.vikunja.io/web"
|
"code.vikunja.io/web"
|
||||||
"time"
|
|
||||||
"xorm.io/builder"
|
"xorm.io/builder"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,15 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"code.vikunja.io/api/pkg/db"
|
|
||||||
"code.vikunja.io/api/pkg/user"
|
|
||||||
"gopkg.in/d4l3k/messagediff.v1"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
"runtime"
|
"runtime"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"code.vikunja.io/api/pkg/db"
|
||||||
|
"code.vikunja.io/api/pkg/user"
|
||||||
|
"gopkg.in/d4l3k/messagediff.v1"
|
||||||
|
|
||||||
"code.vikunja.io/web"
|
"code.vikunja.io/web"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -17,14 +17,15 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"code.vikunja.io/api/pkg/db"
|
|
||||||
"code.vikunja.io/api/pkg/user"
|
|
||||||
"gopkg.in/d4l3k/messagediff.v1"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
"runtime"
|
"runtime"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"code.vikunja.io/api/pkg/db"
|
||||||
|
"code.vikunja.io/api/pkg/user"
|
||||||
|
"gopkg.in/d4l3k/messagediff.v1"
|
||||||
|
|
||||||
"code.vikunja.io/web"
|
"code.vikunja.io/web"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -18,11 +18,12 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
"code.vikunja.io/api/pkg/user"
|
"code.vikunja.io/api/pkg/user"
|
||||||
"code.vikunja.io/api/pkg/utils"
|
"code.vikunja.io/api/pkg/utils"
|
||||||
"code.vikunja.io/web"
|
"code.vikunja.io/web"
|
||||||
"github.com/dgrijalva/jwt-go"
|
"github.com/dgrijalva/jwt-go"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// SharingType holds the sharing type
|
// SharingType holds the sharing type
|
||||||
|
|
|
@ -17,12 +17,13 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"code.vikunja.io/api/pkg/files"
|
"code.vikunja.io/api/pkg/files"
|
||||||
"code.vikunja.io/api/pkg/metrics"
|
"code.vikunja.io/api/pkg/metrics"
|
||||||
"code.vikunja.io/api/pkg/user"
|
"code.vikunja.io/api/pkg/user"
|
||||||
"code.vikunja.io/web"
|
"code.vikunja.io/web"
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
"xorm.io/builder"
|
"xorm.io/builder"
|
||||||
"xorm.io/xorm"
|
"xorm.io/xorm"
|
||||||
)
|
)
|
||||||
|
@ -450,7 +451,7 @@ func GenerateListIdentifier(l *List, sess *xorm.Engine) (err error) {
|
||||||
// The general idea here is to take the title and slice it into pieces, until we found a unique piece.
|
// The general idea here is to take the title and slice it into pieces, until we found a unique piece.
|
||||||
|
|
||||||
var exists = true
|
var exists = true
|
||||||
titleSlug := []rune(strings.Replace(strings.ToUpper(l.Title), " ", "", -1))
|
titleSlug := []rune(strings.ReplaceAll(strings.ToUpper(l.Title), " ", ""))
|
||||||
|
|
||||||
// We can save at most 10 characters in the db, so we need to ensure it has at most 10 characters
|
// We can save at most 10 characters in the db, so we need to ensure it has at most 10 characters
|
||||||
if len(titleSlug) > 10 {
|
if len(titleSlug) > 10 {
|
||||||
|
|
|
@ -65,6 +65,7 @@ func (ld *ListDuplicate) CanCreate(a web.Auth) (canCreate bool, err error) {
|
||||||
// @Failure 403 {object} web.HTTPError "The user does not have access to the list or namespace"
|
// @Failure 403 {object} web.HTTPError "The user does not have access to the list or namespace"
|
||||||
// @Failure 500 {object} models.Message "Internal error"
|
// @Failure 500 {object} models.Message "Internal error"
|
||||||
// @Router /lists/{listID}/duplicate [put]
|
// @Router /lists/{listID}/duplicate [put]
|
||||||
|
//nolint:gocyclo
|
||||||
func (ld *ListDuplicate) Create(a web.Auth) (err error) {
|
func (ld *ListDuplicate) Create(a web.Auth) (err error) {
|
||||||
|
|
||||||
log.Debugf("Duplicating list %d", ld.ListID)
|
log.Debugf("Duplicating list %d", ld.ListID)
|
||||||
|
|
|
@ -17,11 +17,12 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
"code.vikunja.io/api/pkg/db"
|
"code.vikunja.io/api/pkg/db"
|
||||||
"code.vikunja.io/api/pkg/files"
|
"code.vikunja.io/api/pkg/files"
|
||||||
"code.vikunja.io/api/pkg/user"
|
"code.vikunja.io/api/pkg/user"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"testing"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestListDuplicate(t *testing.T) {
|
func TestListDuplicate(t *testing.T) {
|
||||||
|
|
|
@ -17,8 +17,9 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"code.vikunja.io/web"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"code.vikunja.io/web"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TeamList defines the relation between a team and a list
|
// TeamList defines the relation between a team and a list
|
||||||
|
|
|
@ -17,14 +17,15 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"code.vikunja.io/api/pkg/db"
|
|
||||||
"code.vikunja.io/api/pkg/user"
|
|
||||||
"code.vikunja.io/web"
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
"runtime"
|
"runtime"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"code.vikunja.io/api/pkg/db"
|
||||||
|
"code.vikunja.io/api/pkg/user"
|
||||||
|
"code.vikunja.io/web"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestTeamList_ReadAll(t *testing.T) {
|
func TestTeamList_ReadAll(t *testing.T) {
|
||||||
|
|
|
@ -17,11 +17,12 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"reflect"
|
||||||
|
"testing"
|
||||||
|
|
||||||
"code.vikunja.io/api/pkg/db"
|
"code.vikunja.io/api/pkg/db"
|
||||||
"code.vikunja.io/api/pkg/user"
|
"code.vikunja.io/api/pkg/user"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"reflect"
|
|
||||||
"testing"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestList_CreateOrUpdate(t *testing.T) {
|
func TestList_CreateOrUpdate(t *testing.T) {
|
||||||
|
|
|
@ -17,9 +17,10 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
"code.vikunja.io/api/pkg/user"
|
"code.vikunja.io/api/pkg/user"
|
||||||
"code.vikunja.io/web"
|
"code.vikunja.io/web"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// ListUser represents a list <-> user relation
|
// ListUser represents a list <-> user relation
|
||||||
|
|
|
@ -17,11 +17,12 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"code.vikunja.io/api/pkg/db"
|
|
||||||
"code.vikunja.io/api/pkg/user"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"code.vikunja.io/api/pkg/db"
|
||||||
|
"code.vikunja.io/api/pkg/user"
|
||||||
|
|
||||||
"code.vikunja.io/web"
|
"code.vikunja.io/web"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -17,14 +17,15 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"code.vikunja.io/api/pkg/db"
|
|
||||||
"code.vikunja.io/api/pkg/user"
|
|
||||||
"gopkg.in/d4l3k/messagediff.v1"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
"runtime"
|
"runtime"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"code.vikunja.io/api/pkg/db"
|
||||||
|
"code.vikunja.io/api/pkg/user"
|
||||||
|
"gopkg.in/d4l3k/messagediff.v1"
|
||||||
|
|
||||||
"code.vikunja.io/web"
|
"code.vikunja.io/web"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -17,13 +17,14 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"code.vikunja.io/api/pkg/config"
|
|
||||||
"code.vikunja.io/api/pkg/files"
|
|
||||||
"code.vikunja.io/api/pkg/user"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"code.vikunja.io/api/pkg/config"
|
||||||
|
"code.vikunja.io/api/pkg/files"
|
||||||
|
"code.vikunja.io/api/pkg/user"
|
||||||
)
|
)
|
||||||
|
|
||||||
func setupTime() {
|
func setupTime() {
|
||||||
|
|
|
@ -17,12 +17,13 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
"code.vikunja.io/api/pkg/config"
|
"code.vikunja.io/api/pkg/config"
|
||||||
"code.vikunja.io/api/pkg/db"
|
"code.vikunja.io/api/pkg/db"
|
||||||
"code.vikunja.io/api/pkg/log"
|
"code.vikunja.io/api/pkg/log"
|
||||||
_ "github.com/go-sql-driver/mysql" // Because.
|
_ "github.com/go-sql-driver/mysql" // Because.
|
||||||
_ "github.com/lib/pq" // Because.
|
_ "github.com/lib/pq" // Because.
|
||||||
"time"
|
|
||||||
"xorm.io/xorm"
|
"xorm.io/xorm"
|
||||||
|
|
||||||
_ "github.com/mattn/go-sqlite3" // Because.
|
_ "github.com/mattn/go-sqlite3" // Because.
|
||||||
|
|
|
@ -17,12 +17,13 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"sort"
|
||||||
|
"time"
|
||||||
|
|
||||||
"code.vikunja.io/api/pkg/metrics"
|
"code.vikunja.io/api/pkg/metrics"
|
||||||
"code.vikunja.io/api/pkg/user"
|
"code.vikunja.io/api/pkg/user"
|
||||||
"code.vikunja.io/web"
|
"code.vikunja.io/web"
|
||||||
"github.com/imdario/mergo"
|
"github.com/imdario/mergo"
|
||||||
"sort"
|
|
||||||
"time"
|
|
||||||
"xorm.io/builder"
|
"xorm.io/builder"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -17,8 +17,9 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"code.vikunja.io/web"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"code.vikunja.io/web"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TeamNamespace defines the relationship between a Team and a Namespace
|
// TeamNamespace defines the relationship between a Team and a Namespace
|
||||||
|
|
|
@ -17,11 +17,12 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"code.vikunja.io/api/pkg/db"
|
|
||||||
"code.vikunja.io/api/pkg/user"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"code.vikunja.io/api/pkg/db"
|
||||||
|
"code.vikunja.io/api/pkg/user"
|
||||||
|
|
||||||
"code.vikunja.io/web"
|
"code.vikunja.io/web"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -17,14 +17,15 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"code.vikunja.io/api/pkg/db"
|
|
||||||
"code.vikunja.io/api/pkg/user"
|
|
||||||
"code.vikunja.io/web"
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
"runtime"
|
"runtime"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"code.vikunja.io/api/pkg/db"
|
||||||
|
"code.vikunja.io/api/pkg/user"
|
||||||
|
"code.vikunja.io/web"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestTeamNamespace_ReadAll(t *testing.T) {
|
func TestTeamNamespace_ReadAll(t *testing.T) {
|
||||||
|
|
|
@ -17,10 +17,11 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
"code.vikunja.io/api/pkg/db"
|
"code.vikunja.io/api/pkg/db"
|
||||||
"code.vikunja.io/api/pkg/user"
|
"code.vikunja.io/api/pkg/user"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"testing"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNamespace_Create(t *testing.T) {
|
func TestNamespace_Create(t *testing.T) {
|
||||||
|
|
|
@ -17,9 +17,10 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
user2 "code.vikunja.io/api/pkg/user"
|
user2 "code.vikunja.io/api/pkg/user"
|
||||||
"code.vikunja.io/web"
|
"code.vikunja.io/web"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// NamespaceUser represents a namespace <-> user relation
|
// NamespaceUser represents a namespace <-> user relation
|
||||||
|
|
|
@ -17,11 +17,12 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"code.vikunja.io/api/pkg/db"
|
|
||||||
"code.vikunja.io/api/pkg/user"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"code.vikunja.io/api/pkg/db"
|
||||||
|
"code.vikunja.io/api/pkg/user"
|
||||||
|
|
||||||
"code.vikunja.io/web"
|
"code.vikunja.io/web"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -17,14 +17,15 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"code.vikunja.io/api/pkg/db"
|
|
||||||
"code.vikunja.io/api/pkg/user"
|
|
||||||
"code.vikunja.io/web"
|
|
||||||
"gopkg.in/d4l3k/messagediff.v1"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
"runtime"
|
"runtime"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"code.vikunja.io/api/pkg/db"
|
||||||
|
"code.vikunja.io/api/pkg/user"
|
||||||
|
"code.vikunja.io/web"
|
||||||
|
"gopkg.in/d4l3k/messagediff.v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNamespaceUser_Create(t *testing.T) {
|
func TestNamespaceUser_Create(t *testing.T) {
|
||||||
|
|
|
@ -17,9 +17,10 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
"code.vikunja.io/api/pkg/user"
|
"code.vikunja.io/api/pkg/user"
|
||||||
"code.vikunja.io/web"
|
"code.vikunja.io/web"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// SavedFilter represents a saved bunch of filters
|
// SavedFilter represents a saved bunch of filters
|
||||||
|
|
|
@ -17,10 +17,11 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
"code.vikunja.io/api/pkg/db"
|
"code.vikunja.io/api/pkg/db"
|
||||||
"code.vikunja.io/api/pkg/user"
|
"code.vikunja.io/api/pkg/user"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"testing"
|
|
||||||
"xorm.io/xorm/schemas"
|
"xorm.io/xorm/schemas"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -17,9 +17,10 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
"code.vikunja.io/api/pkg/user"
|
"code.vikunja.io/api/pkg/user"
|
||||||
"code.vikunja.io/web"
|
"code.vikunja.io/web"
|
||||||
"time"
|
|
||||||
"xorm.io/xorm"
|
"xorm.io/xorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -17,11 +17,12 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io"
|
||||||
|
"time"
|
||||||
|
|
||||||
"code.vikunja.io/api/pkg/files"
|
"code.vikunja.io/api/pkg/files"
|
||||||
"code.vikunja.io/api/pkg/user"
|
"code.vikunja.io/api/pkg/user"
|
||||||
"code.vikunja.io/web"
|
"code.vikunja.io/web"
|
||||||
"io"
|
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// TaskAttachment is the definition of a task attachment
|
// TaskAttachment is the definition of a task attachment
|
||||||
|
|
|
@ -18,15 +18,16 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
"testing"
|
||||||
|
|
||||||
"code.vikunja.io/api/pkg/config"
|
"code.vikunja.io/api/pkg/config"
|
||||||
"code.vikunja.io/api/pkg/db"
|
"code.vikunja.io/api/pkg/db"
|
||||||
"code.vikunja.io/api/pkg/files"
|
"code.vikunja.io/api/pkg/files"
|
||||||
"code.vikunja.io/api/pkg/user"
|
"code.vikunja.io/api/pkg/user"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"io"
|
|
||||||
"os"
|
|
||||||
"strconv"
|
|
||||||
"testing"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestTaskAttachment_ReadOne(t *testing.T) {
|
func TestTaskAttachment_ReadOne(t *testing.T) {
|
||||||
|
|
|
@ -18,12 +18,13 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"code.vikunja.io/api/pkg/config"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/iancoleman/strcase"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"code.vikunja.io/api/pkg/config"
|
||||||
|
"github.com/iancoleman/strcase"
|
||||||
"xorm.io/xorm/schemas"
|
"xorm.io/xorm/schemas"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -112,6 +113,8 @@ func validateTaskFieldComparator(comparator taskFilterComparator) error {
|
||||||
taskFilterComparatorLessEquals,
|
taskFilterComparatorLessEquals,
|
||||||
taskFilterComparatorNotEquals:
|
taskFilterComparatorNotEquals:
|
||||||
return nil
|
return nil
|
||||||
|
case taskFilterComparatorInvalid:
|
||||||
|
fallthrough
|
||||||
default:
|
default:
|
||||||
return ErrInvalidTaskFilterComparator{Comparator: comparator}
|
return ErrInvalidTaskFilterComparator{Comparator: comparator}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,8 +17,9 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSortParamValidation(t *testing.T) {
|
func TestSortParamValidation(t *testing.T) {
|
||||||
|
|
|
@ -17,14 +17,15 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"code.vikunja.io/api/pkg/config"
|
"code.vikunja.io/api/pkg/config"
|
||||||
"code.vikunja.io/api/pkg/db"
|
"code.vikunja.io/api/pkg/db"
|
||||||
"code.vikunja.io/api/pkg/files"
|
"code.vikunja.io/api/pkg/files"
|
||||||
"code.vikunja.io/api/pkg/user"
|
"code.vikunja.io/api/pkg/user"
|
||||||
"code.vikunja.io/web"
|
"code.vikunja.io/web"
|
||||||
"gopkg.in/d4l3k/messagediff.v1"
|
"gopkg.in/d4l3k/messagediff.v1"
|
||||||
"testing"
|
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestTaskCollection_ReadAll(t *testing.T) {
|
func TestTaskCollection_ReadAll(t *testing.T) {
|
||||||
|
|
|
@ -18,9 +18,10 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
"code.vikunja.io/api/pkg/user"
|
"code.vikunja.io/api/pkg/user"
|
||||||
"code.vikunja.io/web"
|
"code.vikunja.io/web"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// TaskComment represents a task comment
|
// TaskComment represents a task comment
|
||||||
|
|
|
@ -17,10 +17,11 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
"code.vikunja.io/api/pkg/db"
|
"code.vikunja.io/api/pkg/db"
|
||||||
"code.vikunja.io/api/pkg/user"
|
"code.vikunja.io/api/pkg/user"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"testing"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestTaskComment_Create(t *testing.T) {
|
func TestTaskComment_Create(t *testing.T) {
|
||||||
|
|
|
@ -18,9 +18,10 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
"code.vikunja.io/api/pkg/user"
|
"code.vikunja.io/api/pkg/user"
|
||||||
"code.vikunja.io/web"
|
"code.vikunja.io/web"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// RelationKind represents a kind of relation between to tasks
|
// RelationKind represents a kind of relation between to tasks
|
||||||
|
@ -174,6 +175,8 @@ func (rel *TaskRelation) Create(a web.Auth) error {
|
||||||
otherRelation.RelationKind = RelationKindCopiedTo
|
otherRelation.RelationKind = RelationKindCopiedTo
|
||||||
case RelationKindCopiedTo:
|
case RelationKindCopiedTo:
|
||||||
otherRelation.RelationKind = RelationKindCopiedFrom
|
otherRelation.RelationKind = RelationKindCopiedFrom
|
||||||
|
case RelationKindUnknown:
|
||||||
|
// Nothing to do
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finally insert everything
|
// Finally insert everything
|
||||||
|
|
|
@ -18,10 +18,11 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
"code.vikunja.io/api/pkg/db"
|
"code.vikunja.io/api/pkg/db"
|
||||||
"code.vikunja.io/api/pkg/user"
|
"code.vikunja.io/api/pkg/user"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"testing"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestTaskRelation_Create(t *testing.T) {
|
func TestTaskRelation_Create(t *testing.T) {
|
||||||
|
|
|
@ -17,16 +17,17 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"math"
|
||||||
|
"sort"
|
||||||
|
"strconv"
|
||||||
|
"time"
|
||||||
|
|
||||||
"code.vikunja.io/api/pkg/config"
|
"code.vikunja.io/api/pkg/config"
|
||||||
"code.vikunja.io/api/pkg/metrics"
|
"code.vikunja.io/api/pkg/metrics"
|
||||||
"code.vikunja.io/api/pkg/user"
|
"code.vikunja.io/api/pkg/user"
|
||||||
"code.vikunja.io/api/pkg/utils"
|
"code.vikunja.io/api/pkg/utils"
|
||||||
"code.vikunja.io/web"
|
"code.vikunja.io/web"
|
||||||
"github.com/imdario/mergo"
|
"github.com/imdario/mergo"
|
||||||
"math"
|
|
||||||
"sort"
|
|
||||||
"strconv"
|
|
||||||
"time"
|
|
||||||
"xorm.io/builder"
|
"xorm.io/builder"
|
||||||
"xorm.io/xorm"
|
"xorm.io/xorm"
|
||||||
"xorm.io/xorm/schemas"
|
"xorm.io/xorm/schemas"
|
||||||
|
@ -168,6 +169,7 @@ func (t *Task) ReadAll(a web.Auth, search string, page int, perPage int) (result
|
||||||
return nil, 0, 0, nil
|
return nil, 0, 0, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//nolint:gocyclo
|
||||||
func getRawTasksForLists(lists []*List, a web.Auth, opts *taskOptions) (tasks []*Task, resultCount int, totalItems int64, err error) {
|
func getRawTasksForLists(lists []*List, a web.Auth, opts *taskOptions) (tasks []*Task, resultCount int, totalItems int64, err error) {
|
||||||
|
|
||||||
// If the user does not have any lists, don't try to get any tasks
|
// If the user does not have any lists, don't try to get any tasks
|
||||||
|
@ -258,6 +260,8 @@ func getRawTasksForLists(lists []*List, a web.Auth, opts *taskOptions) (tasks []
|
||||||
} else {
|
} else {
|
||||||
filters = append(filters, &builder.Lte{f.field: f.value})
|
filters = append(filters, &builder.Lte{f.field: f.value})
|
||||||
}
|
}
|
||||||
|
case taskFilterComparatorInvalid:
|
||||||
|
// Nothing to do
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -728,6 +732,7 @@ func createTask(s *xorm.Session, t *Task, a web.Auth, updateAssignees bool) (err
|
||||||
// @Failure 403 {object} web.HTTPError "The user does not have access to the task (aka its list)"
|
// @Failure 403 {object} web.HTTPError "The user does not have access to the task (aka its list)"
|
||||||
// @Failure 500 {object} models.Message "Internal error"
|
// @Failure 500 {object} models.Message "Internal error"
|
||||||
// @Router /tasks/{id} [post]
|
// @Router /tasks/{id} [post]
|
||||||
|
//nolint:gocyclo
|
||||||
func (t *Task) Update() (err error) {
|
func (t *Task) Update() (err error) {
|
||||||
|
|
||||||
s := x.NewSession()
|
s := x.NewSession()
|
||||||
|
@ -836,12 +841,12 @@ func (t *Task) Update() (err error) {
|
||||||
// a lot of existing code which we'll then need to refactor.
|
// a lot of existing code which we'll then need to refactor.
|
||||||
// This is why.
|
// This is why.
|
||||||
//
|
//
|
||||||
//if err := ot.updateTaskLabels(t.Labels); err != nil {
|
// if err := ot.updateTaskLabels(t.Labels); err != nil {
|
||||||
// return err
|
// return err
|
||||||
//}
|
// }
|
||||||
// set the labels to ot.Labels because our updateTaskLabels function puts the full label objects in it pretty nicely
|
// set the labels to ot.Labels because our updateTaskLabels function puts the full label objects in it pretty nicely
|
||||||
// We also set this here to prevent it being overwritten later on.
|
// We also set this here to prevent it being overwritten later on.
|
||||||
//t.Labels = ot.Labels
|
// t.Labels = ot.Labels
|
||||||
|
|
||||||
// For whatever reason, xorm dont detect if done is updated, so we need to update this every time by hand
|
// For whatever reason, xorm dont detect if done is updated, so we need to update this every time by hand
|
||||||
// Which is why we merge the actual task struct with the one we got from the db
|
// Which is why we merge the actual task struct with the one we got from the db
|
||||||
|
|
|
@ -39,7 +39,6 @@ func (t *Task) CanCreate(a web.Auth) (bool, error) {
|
||||||
|
|
||||||
// CanRead determines if a user can read a task
|
// CanRead determines if a user can read a task
|
||||||
func (t *Task) CanRead(a web.Auth) (canRead bool, maxRight int, err error) {
|
func (t *Task) CanRead(a web.Auth) (canRead bool, maxRight int, err error) {
|
||||||
//return t.canDoTask(a)
|
|
||||||
// Get the task, error out if it doesn't exist
|
// Get the task, error out if it doesn't exist
|
||||||
*t, err = GetTaskByIDSimple(t.ID)
|
*t, err = GetTaskByIDSimple(t.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -17,11 +17,12 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"code.vikunja.io/api/pkg/db"
|
"code.vikunja.io/api/pkg/db"
|
||||||
"code.vikunja.io/api/pkg/user"
|
"code.vikunja.io/api/pkg/user"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"testing"
|
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestTask_Create(t *testing.T) {
|
func TestTask_Create(t *testing.T) {
|
||||||
|
|
|
@ -17,10 +17,11 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
"code.vikunja.io/api/pkg/db"
|
"code.vikunja.io/api/pkg/db"
|
||||||
"code.vikunja.io/api/pkg/user"
|
"code.vikunja.io/api/pkg/user"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"testing"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestTeamMember_Create(t *testing.T) {
|
func TestTeamMember_Create(t *testing.T) {
|
||||||
|
|
|
@ -17,10 +17,11 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
"code.vikunja.io/api/pkg/metrics"
|
"code.vikunja.io/api/pkg/metrics"
|
||||||
"code.vikunja.io/api/pkg/user"
|
"code.vikunja.io/api/pkg/user"
|
||||||
"code.vikunja.io/web"
|
"code.vikunja.io/web"
|
||||||
"time"
|
|
||||||
"xorm.io/builder"
|
"xorm.io/builder"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -17,11 +17,12 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"code.vikunja.io/api/pkg/db"
|
|
||||||
"code.vikunja.io/api/pkg/user"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"code.vikunja.io/api/pkg/db"
|
||||||
|
"code.vikunja.io/api/pkg/user"
|
||||||
|
|
||||||
"code.vikunja.io/web"
|
"code.vikunja.io/web"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -17,11 +17,12 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"reflect"
|
||||||
|
"testing"
|
||||||
|
|
||||||
"code.vikunja.io/api/pkg/db"
|
"code.vikunja.io/api/pkg/db"
|
||||||
"code.vikunja.io/api/pkg/user"
|
"code.vikunja.io/api/pkg/user"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"reflect"
|
|
||||||
"testing"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestTeam_Create(t *testing.T) {
|
func TestTeam_Create(t *testing.T) {
|
||||||
|
|
|
@ -18,10 +18,11 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
"code.vikunja.io/api/pkg/db"
|
"code.vikunja.io/api/pkg/db"
|
||||||
"code.vikunja.io/api/pkg/user"
|
"code.vikunja.io/api/pkg/user"
|
||||||
"gopkg.in/d4l3k/messagediff.v1"
|
"gopkg.in/d4l3k/messagediff.v1"
|
||||||
"testing"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestListUsersFromList(t *testing.T) {
|
func TestListUsersFromList(t *testing.T) {
|
||||||
|
|
|
@ -17,14 +17,16 @@
|
||||||
package gravatar
|
package gravatar
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"code.vikunja.io/api/pkg/config"
|
"context"
|
||||||
"code.vikunja.io/api/pkg/log"
|
|
||||||
"code.vikunja.io/api/pkg/user"
|
|
||||||
"code.vikunja.io/api/pkg/utils"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"code.vikunja.io/api/pkg/config"
|
||||||
|
"code.vikunja.io/api/pkg/log"
|
||||||
|
"code.vikunja.io/api/pkg/user"
|
||||||
|
"code.vikunja.io/api/pkg/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type avatar struct {
|
type avatar struct {
|
||||||
|
@ -62,10 +64,15 @@ func (g *Provider) GetAvatar(user *user.User, size int64) ([]byte, string, error
|
||||||
}
|
}
|
||||||
if !exists || needsRefetch {
|
if !exists || needsRefetch {
|
||||||
log.Debugf("Gravatar for user %d with size %d not cached, requesting from gravatar...", user.ID, size)
|
log.Debugf("Gravatar for user %d with size %d not cached, requesting from gravatar...", user.ID, size)
|
||||||
resp, err := http.Get("https://www.gravatar.com/avatar/" + utils.Md5String(user.Email) + "?s=" + sizeString + "&d=mp")
|
req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, "https://www.gravatar.com/avatar/"+utils.Md5String(user.Email)+"?s="+sizeString+"&d=mp", nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, "", err
|
return nil, "", err
|
||||||
}
|
}
|
||||||
|
resp, err := http.DefaultClient.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, "", err
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
avatarContent, err := ioutil.ReadAll(resp.Body)
|
avatarContent, err := ioutil.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, "", err
|
return nil, "", err
|
||||||
|
|
|
@ -18,6 +18,13 @@ package initials
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"image"
|
||||||
|
"image/color"
|
||||||
|
"image/draw"
|
||||||
|
"image/png"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"code.vikunja.io/api/pkg/log"
|
"code.vikunja.io/api/pkg/log"
|
||||||
"code.vikunja.io/api/pkg/modules/keyvalue"
|
"code.vikunja.io/api/pkg/modules/keyvalue"
|
||||||
e "code.vikunja.io/api/pkg/modules/keyvalue/error"
|
e "code.vikunja.io/api/pkg/modules/keyvalue/error"
|
||||||
|
@ -27,12 +34,6 @@ import (
|
||||||
"golang.org/x/image/font"
|
"golang.org/x/image/font"
|
||||||
"golang.org/x/image/font/gofont/goregular"
|
"golang.org/x/image/font/gofont/goregular"
|
||||||
"golang.org/x/image/math/fixed"
|
"golang.org/x/image/math/fixed"
|
||||||
"image"
|
|
||||||
"image/color"
|
|
||||||
"image/draw"
|
|
||||||
"image/png"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Provider represents the provider implementation of the initials provider
|
// Provider represents the provider implementation of the initials provider
|
||||||
|
@ -41,15 +42,15 @@ type Provider struct {
|
||||||
|
|
||||||
var (
|
var (
|
||||||
avatarBgColors = []*color.RGBA{
|
avatarBgColors = []*color.RGBA{
|
||||||
{69, 189, 243, 255},
|
{R: 69, G: 189, B: 243, A: 255},
|
||||||
{224, 143, 112, 255},
|
{R: 224, G: 143, B: 112, A: 255},
|
||||||
{77, 182, 172, 255},
|
{R: 77, G: 182, B: 172, A: 255},
|
||||||
{149, 117, 205, 255},
|
{R: 149, G: 117, B: 205, A: 255},
|
||||||
{176, 133, 94, 255},
|
{R: 176, G: 133, B: 94, A: 255},
|
||||||
{240, 98, 146, 255},
|
{R: 240, G: 98, B: 146, A: 255},
|
||||||
{163, 211, 108, 255},
|
{R: 163, G: 211, B: 108, A: 255},
|
||||||
{121, 134, 203, 255},
|
{R: 121, G: 134, B: 203, A: 255},
|
||||||
{241, 185, 29, 255},
|
{R: 241, G: 185, B: 29, A: 255},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -18,16 +18,17 @@ package upload
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"image"
|
||||||
|
"image/png"
|
||||||
|
"io/ioutil"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"code.vikunja.io/api/pkg/files"
|
"code.vikunja.io/api/pkg/files"
|
||||||
"code.vikunja.io/api/pkg/log"
|
"code.vikunja.io/api/pkg/log"
|
||||||
"code.vikunja.io/api/pkg/modules/keyvalue"
|
"code.vikunja.io/api/pkg/modules/keyvalue"
|
||||||
e "code.vikunja.io/api/pkg/modules/keyvalue/error"
|
e "code.vikunja.io/api/pkg/modules/keyvalue/error"
|
||||||
"code.vikunja.io/api/pkg/user"
|
"code.vikunja.io/api/pkg/user"
|
||||||
"github.com/disintegration/imaging"
|
"github.com/disintegration/imaging"
|
||||||
"image"
|
|
||||||
"image/png"
|
|
||||||
"io/ioutil"
|
|
||||||
"strconv"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Provider represents the upload avatar provider
|
// Provider represents the upload avatar provider
|
||||||
|
|
|
@ -17,6 +17,11 @@
|
||||||
package handler
|
package handler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"code.vikunja.io/api/pkg/files"
|
"code.vikunja.io/api/pkg/files"
|
||||||
"code.vikunja.io/api/pkg/log"
|
"code.vikunja.io/api/pkg/log"
|
||||||
"code.vikunja.io/api/pkg/models"
|
"code.vikunja.io/api/pkg/models"
|
||||||
|
@ -27,10 +32,6 @@ import (
|
||||||
"code.vikunja.io/web/handler"
|
"code.vikunja.io/web/handler"
|
||||||
"github.com/gabriel-vasile/mimetype"
|
"github.com/gabriel-vasile/mimetype"
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
"io"
|
|
||||||
"net/http"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// BackgroundProvider represents a thing which holds a background provider
|
// BackgroundProvider represents a thing which holds a background provider
|
||||||
|
|
|
@ -17,18 +17,25 @@
|
||||||
package unsplash
|
package unsplash
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"code.vikunja.io/web/handler"
|
"context"
|
||||||
"github.com/labstack/echo/v4"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"code.vikunja.io/web/handler"
|
||||||
|
"github.com/labstack/echo/v4"
|
||||||
)
|
)
|
||||||
|
|
||||||
func unsplashImage(url string, c echo.Context) error {
|
func unsplashImage(url string, c echo.Context) error {
|
||||||
// Replacing and appending the url for security reasons
|
// Replacing and appending the url for security reasons
|
||||||
resp, err := http.Get("https://images.unsplash.com/" + strings.Replace(url, "https://images.unsplash.com/", "", 1))
|
req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, "https://images.unsplash.com/"+strings.Replace(url, "https://images.unsplash.com/", "", 1), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
resp, err := http.DefaultClient.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
if resp.StatusCode > 399 {
|
if resp.StatusCode > 399 {
|
||||||
return echo.ErrNotFound
|
return echo.ErrNotFound
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,14 @@ package unsplash
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"code.vikunja.io/api/pkg/config"
|
"code.vikunja.io/api/pkg/config"
|
||||||
"code.vikunja.io/api/pkg/files"
|
"code.vikunja.io/api/pkg/files"
|
||||||
"code.vikunja.io/api/pkg/log"
|
"code.vikunja.io/api/pkg/log"
|
||||||
|
@ -26,12 +34,6 @@ import (
|
||||||
"code.vikunja.io/api/pkg/modules/keyvalue"
|
"code.vikunja.io/api/pkg/modules/keyvalue"
|
||||||
e "code.vikunja.io/api/pkg/modules/keyvalue/error"
|
e "code.vikunja.io/api/pkg/modules/keyvalue/error"
|
||||||
"code.vikunja.io/web"
|
"code.vikunja.io/web"
|
||||||
"encoding/json"
|
|
||||||
"net/http"
|
|
||||||
"net/url"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -89,7 +91,7 @@ type initialCollection struct {
|
||||||
var emptySearchResult *initialCollection
|
var emptySearchResult *initialCollection
|
||||||
|
|
||||||
func doGet(url string, result ...interface{}) (err error) {
|
func doGet(url string, result ...interface{}) (err error) {
|
||||||
req, err := http.NewRequest("GET", unsplashAPIURL+url, nil)
|
req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, unsplashAPIURL+url, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -100,6 +102,7 @@ func doGet(url string, result ...interface{}) (err error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
if len(result) > 0 {
|
if len(result) > 0 {
|
||||||
return json.NewDecoder(resp.Body).Decode(result[0])
|
return json.NewDecoder(resp.Body).Decode(result[0])
|
||||||
|
@ -250,10 +253,14 @@ func (p *Provider) Set(image *background.Image, list *models.List, auth web.Auth
|
||||||
|
|
||||||
// Download the photo from unsplash
|
// Download the photo from unsplash
|
||||||
// The parameters crop the image to a max width of 2560 and a max height of 2048 to save bandwidth and storage.
|
// The parameters crop the image to a max width of 2560 and a max height of 2048 to save bandwidth and storage.
|
||||||
resp, err := http.Get(photo.Urls.Raw + "&w=2560&h=2048&q=90")
|
req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, photo.Urls.Raw+"&w=2560&h=2048&q=90", nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
resp, err := http.DefaultClient.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
if resp.StatusCode > 399 {
|
if resp.StatusCode > 399 {
|
||||||
|
@ -327,9 +334,13 @@ func Pingback(f *files.File) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func pingbackByPhotoID(photoID string) {
|
func pingbackByPhotoID(photoID string) {
|
||||||
if _, err := http.Get("https://views.unsplash.com/v?app_id=" + config.BackgroundsUnsplashApplicationID.GetString() + "&photo_id=" + photoID); err != nil {
|
req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, "https://views.unsplash.com/v?app_id="+config.BackgroundsUnsplashApplicationID.GetString()+"&photo_id="+photoID, nil)
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("Unsplash Pingback Failed: %s", err.Error())
|
||||||
|
}
|
||||||
|
_, err = http.DefaultClient.Do(req)
|
||||||
|
if err != nil {
|
||||||
log.Errorf("Unsplash Pingback Failed: %s", err.Error())
|
log.Errorf("Unsplash Pingback Failed: %s", err.Error())
|
||||||
}
|
}
|
||||||
log.Debugf("Pinged unsplash for photo %s", photoID)
|
log.Debugf("Pinged unsplash for photo %s", photoID)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue