diff --git a/.travis.yml b/.travis.yml
index 888b3681..33b1f6db 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -6,14 +6,15 @@ before_install:
- sudo apt-get install gcc-mingw-w64 gcc-mingw-w64-i686 gcc-mingw-w64-x86-64 binutils-mingw-w64-i686
binutils-mingw-w64-x86-64 ansible
- go get -u github.com/tools/godep
+- go get github.com/go-playground/overalls
- go get golang.org/x/tools/cmd/cover
- go get github.com/mattn/goveralls
before_script:
- go vet
- go test -v ./...
script:
-- go test -v ./... -covermode=count -coverprofile=coverage.out
-- $HOME/gopath/bin/goveralls -coverprofile=coverage.out -service=travis-ci -repotoken $COVERALLS_TOKEN
+- overalls -project=github.com/NyaaPantsu/nyaa -covermode=count -debug
+- goveralls -coverprofile="overalls.coverprofile" -service=travis-ci -repotoken $COVERALLS_TOKEN
install:
- export GOPATH="${TRAVIS_BUILD_DIR}/vendor:$GOPATH"
- export PATH="${TRAVIS_BUILD_DIR}/Godeps/_workspace/bin:$PATH"
diff --git a/controllers/torrent/delete.go b/controllers/torrent/delete.go
index 67328e6b..ec1bc838 100644
--- a/controllers/torrent/delete.go
+++ b/controllers/torrent/delete.go
@@ -18,7 +18,7 @@ func TorrentDeleteUserPanel(c *gin.Context) {
id, _ := strconv.ParseInt(c.Query("id"), 10, 32)
currentUser := router.GetUser(c)
torrent, _ := torrents.FindByID(uint(id))
- if currentUser.CurrentOrAdmin(torrent.UploaderID) {
+ if currentUser.CurrentOrAdmin(torrent.UploaderID) && torrent.ID > 0 {
_, _, err := torrent.Delete(false)
if err == nil {
if torrent.Uploader == nil {
diff --git a/controllers/torrent/edit.go b/controllers/torrent/edit.go
index 4d7abad2..005f61c2 100644
--- a/controllers/torrent/edit.go
+++ b/controllers/torrent/edit.go
@@ -20,7 +20,7 @@ func TorrentEditUserPanel(c *gin.Context) {
id, _ := strconv.ParseInt(c.Query("id"), 10, 32)
torrent, _ := torrents.FindByID(uint(id))
currentUser := router.GetUser(c)
- if currentUser.CurrentOrAdmin(torrent.UploaderID) {
+ if currentUser.CurrentOrAdmin(torrent.UploaderID) && torrent.ID > 0 {
uploadForm := torrentValidator.TorrentRequest{}
uploadForm.Name = torrent.Name
uploadForm.Category = strconv.Itoa(torrent.Category) + "_" + strconv.Itoa(torrent.SubCategory)
diff --git a/models/user.go b/models/user.go
index 8688b19c..2a0656bc 100644
--- a/models/user.go
+++ b/models/user.go
@@ -101,7 +101,7 @@ func (u User) Size() (s int) {
6*2 + // string pointers
4*3 + //time.Time
3*2 + // arrays
- // string arrays
+ // string arrays
len(u.Username) + len(u.Password) + len(u.Email) + len(u.APIToken) + len(u.MD5) + len(u.Language) + len(u.Theme)
s *= 8
@@ -154,6 +154,9 @@ func (u *User) HasAdmin() bool {
// CurrentOrAdmin check that user has admin permission or user is the current user.
func (u *User) CurrentOrAdmin(userID uint) bool {
+ if userID == 0 {
+ return false
+ }
log.Debugf("user.ID == userID %d %d %s", u.ID, userID, u.ID == userID)
return (u.IsModerator() || u.ID == userID)
}
diff --git a/templates/layouts/partials/menu/profile.jet.html b/templates/layouts/partials/menu/profile.jet.html
index 12de4de7..3859b912 100644
--- a/templates/layouts/partials/menu/profile.jet.html
+++ b/templates/layouts/partials/menu/profile.jet.html
@@ -51,7 +51,7 @@
{{ T("my_notifications")}}
{{end}}
- {{if User.CurrentOrAdmin(UserProfile.ID) }}
+ {{if UserProfile.ID > 0 && User.CurrentOrAdmin(UserProfile.ID) }}
{{ T("settings")}}
diff --git a/templates/template.go b/templates/template.go
index 83b9ff7e..fcffc624 100644
--- a/templates/template.go
+++ b/templates/template.go
@@ -164,7 +164,7 @@ func userProfileBase(c *gin.Context, templateName string, userProfile *models.Us
query.Set("limit", "20")
c.Request.URL.RawQuery = query.Encode()
nbTorrents := 0
- if currentUser.CurrentOrAdmin(userProfile.ID) {
+ if userProfile.ID > 0 && currentUser.CurrentOrAdmin(userProfile.ID) {
_, userProfile.Torrents, nbTorrents, _ = search.ByQuery(c, 1, true, true, false, false)
} else {
_, userProfile.Torrents, nbTorrents, _ = search.ByQuery(c, 1, true, true, false, true)