Browse Source

rename internal package xlerrors -> slerrors.

master
Gisle Aune 5 years ago
parent
commit
381cda1f8f
  1. 4
      database/drivers/mysqldriver/activities.go
  2. 4
      database/drivers/mysqldriver/issetasks.go
  3. 4
      database/drivers/mysqldriver/issues.go
  4. 4
      database/drivers/mysqldriver/issues_test.go
  5. 4
      database/drivers/mysqldriver/items.go
  6. 4
      database/drivers/mysqldriver/items_test.go
  7. 4
      database/drivers/mysqldriver/projects.go
  8. 4
      database/drivers/mysqldriver/projects_test.go
  9. 4
      database/drivers/mysqldriver/projectstatuses.go
  10. 6
      database/drivers/mysqldriver/projectstatuses_test.go
  11. 6
      database/drivers/mysqldriver/session.go
  12. 4
      database/drivers/mysqldriver/users.go
  13. 4
      database/drivers/mysqldriver/users_test.go
  14. 4
      graph/loaders/userloader.go
  15. 4
      graph/resolvers/issue.resolvers.go
  16. 4
      graph/resolvers/issuetask.resolvers.go
  17. 28
      graph/resolvers/mutation.resolvers.go
  18. 4
      graph/resolvers/project.resolvers.go
  19. 17
      graph/resolvers/query.resolvers.go
  20. 2
      internal/slerrors/notfound.go
  21. 2
      internal/slerrors/permission.go
  22. 4
      main.go
  23. 20
      services/auth.go

4
database/drivers/mysqldriver/activities.go

@ -5,7 +5,7 @@ import (
"database/sql"
"errors"
"git.aiterp.net/stufflog/server/internal/generate"
"git.aiterp.net/stufflog/server/internal/xlerrors"
"git.aiterp.net/stufflog/server/internal/slerrors"
"git.aiterp.net/stufflog/server/models"
sq "github.com/Masterminds/squirrel"
"github.com/jmoiron/sqlx"
@ -20,7 +20,7 @@ func (r *activityRepository) Find(ctx context.Context, id string) (*models.Activ
err := r.db.GetContext(ctx, &activity, "SELECT * FROM activity WHERE activity_id=?", id)
if err != nil {
if err == sql.ErrNoRows {
return nil, xlerrors.NotFound("Activity")
return nil, slerrors.NotFound("Activity")
}
return nil, err

4
database/drivers/mysqldriver/issetasks.go

@ -5,7 +5,7 @@ import (
"database/sql"
"errors"
"fmt"
"git.aiterp.net/stufflog/server/internal/xlerrors"
"git.aiterp.net/stufflog/server/internal/slerrors"
"git.aiterp.net/stufflog/server/models"
sq "github.com/Masterminds/squirrel"
"github.com/jmoiron/sqlx"
@ -21,7 +21,7 @@ func (r *issueTaskRepository) Find(ctx context.Context, id string) (*models.Issu
err := r.db.GetContext(ctx, &issueTask, "SELECT * FROM issue_task WHERE issue_task_id=?", id)
if err != nil {
if err == sql.ErrNoRows {
return nil, xlerrors.NotFound("Issue task")
return nil, slerrors.NotFound("Issue task")
}
return nil, err

4
database/drivers/mysqldriver/issues.go

@ -5,7 +5,7 @@ import (
"database/sql"
"errors"
"fmt"
"git.aiterp.net/stufflog/server/internal/xlerrors"
"git.aiterp.net/stufflog/server/internal/slerrors"
"git.aiterp.net/stufflog/server/models"
sq "github.com/Masterminds/squirrel"
"github.com/jmoiron/sqlx"
@ -24,7 +24,7 @@ func (r *issueRepository) Find(ctx context.Context, id string) (*models.Issue, e
err := r.db.GetContext(ctx, &issue, "SELECT * FROM issue WHERE issue_id=?", id)
if err != nil {
if err == sql.ErrNoRows {
return nil, xlerrors.NotFound("Issue")
return nil, slerrors.NotFound("Issue")
}
return nil, err

4
database/drivers/mysqldriver/issues_test.go

@ -2,7 +2,7 @@ package mysqldriver
import (
"context"
"git.aiterp.net/stufflog/server/internal/xlerrors"
"git.aiterp.net/stufflog/server/internal/slerrors"
"git.aiterp.net/stufflog/server/models"
"github.com/stretchr/testify/assert"
"testing"
@ -122,7 +122,7 @@ func TestIssueRepository(t *testing.T) {
result, err = issues.Find(ctx, "NONEXISTENT-666")
assert.Error(t, err)
assert.Nil(t, result)
assert.True(t, xlerrors.IsNotFound(err))
assert.True(t, slerrors.IsNotFound(err))
// LIST
results, err := issues.List(ctx, models.IssueFilter{})

4
database/drivers/mysqldriver/items.go

@ -4,7 +4,7 @@ import (
"context"
"database/sql"
"git.aiterp.net/stufflog/server/internal/generate"
"git.aiterp.net/stufflog/server/internal/xlerrors"
"git.aiterp.net/stufflog/server/internal/slerrors"
"git.aiterp.net/stufflog/server/models"
sq "github.com/Masterminds/squirrel"
"github.com/jmoiron/sqlx"
@ -19,7 +19,7 @@ func (r *itemRepository) Find(ctx context.Context, id string) (*models.Item, err
err := r.db.GetContext(ctx, &item, "SELECT * FROM item WHERE item_id=?", id)
if err != nil {
if err == sql.ErrNoRows {
return nil, xlerrors.NotFound("Project")
return nil, slerrors.NotFound("Project")
}
return nil, err

4
database/drivers/mysqldriver/items_test.go

@ -2,7 +2,7 @@ package mysqldriver
import (
"context"
"git.aiterp.net/stufflog/server/internal/xlerrors"
"git.aiterp.net/stufflog/server/internal/slerrors"
"git.aiterp.net/stufflog/server/models"
"github.com/stretchr/testify/assert"
"testing"
@ -93,7 +93,7 @@ func TestItemRepository(t *testing.T) {
// FIND't
result, err = items.Find(ctx, "Iobviouslyinvalidid")
assert.Error(t, err)
assert.True(t, xlerrors.IsNotFound(err))
assert.True(t, slerrors.IsNotFound(err))
assert.Nil(t, result)
// LIST

4
database/drivers/mysqldriver/projects.go

@ -4,7 +4,7 @@ import (
"context"
"database/sql"
"errors"
"git.aiterp.net/stufflog/server/internal/xlerrors"
"git.aiterp.net/stufflog/server/internal/slerrors"
"git.aiterp.net/stufflog/server/models"
sq "github.com/Masterminds/squirrel"
"github.com/jmoiron/sqlx"
@ -19,7 +19,7 @@ func (r *projectRepository) Find(ctx context.Context, id string) (*models.Projec
err := r.db.GetContext(ctx, &project, "SELECT * FROM project WHERE project_id=?", id)
if err != nil {
if err == sql.ErrNoRows {
return nil, xlerrors.NotFound("Project")
return nil, slerrors.NotFound("Project")
}
return nil, err

4
database/drivers/mysqldriver/projects_test.go

@ -2,7 +2,7 @@ package mysqldriver
import (
"context"
"git.aiterp.net/stufflog/server/internal/xlerrors"
"git.aiterp.net/stufflog/server/internal/slerrors"
"git.aiterp.net/stufflog/server/models"
"github.com/stretchr/testify/assert"
"testing"
@ -62,7 +62,7 @@ func TestProjectRepository(t *testing.T) {
// FIND't
result, err = projects.Find(ctx, "BLARGH")
assert.Error(t, err)
assert.True(t, xlerrors.IsNotFound(err))
assert.True(t, slerrors.IsNotFound(err))
assert.Nil(t, result)
// LIST

4
database/drivers/mysqldriver/projectstatuses.go

@ -3,7 +3,7 @@ package mysqldriver
import (
"context"
"database/sql"
"git.aiterp.net/stufflog/server/internal/xlerrors"
"git.aiterp.net/stufflog/server/internal/slerrors"
"git.aiterp.net/stufflog/server/models"
sq "github.com/Masterminds/squirrel"
"github.com/jmoiron/sqlx"
@ -18,7 +18,7 @@ func (r *projectStatusRepository) Find(ctx context.Context, projectID string, na
err := r.db.GetContext(ctx, &projectStatus, "SELECT * FROM project_status WHERE project_id=? AND name=?", projectID, name)
if err != nil {
if err == sql.ErrNoRows {
return nil, xlerrors.NotFound("Project status")
return nil, slerrors.NotFound("Project status")
}
return nil, err

6
database/drivers/mysqldriver/projectstatuses_test.go

@ -2,7 +2,7 @@ package mysqldriver
import (
"context"
"git.aiterp.net/stufflog/server/internal/xlerrors"
"git.aiterp.net/stufflog/server/internal/slerrors"
"git.aiterp.net/stufflog/server/models"
"github.com/stretchr/testify/assert"
"testing"
@ -85,11 +85,11 @@ func TestProjectStatusRepository(t *testing.T) {
// FINDn't
result, err = statuses.Find(ctx, project3.ID, projectStatus6.Name)
assert.Error(t, err)
assert.True(t, xlerrors.IsNotFound(err))
assert.True(t, slerrors.IsNotFound(err))
assert.Nil(t, result)
result, err = statuses.Find(ctx, project2.ID, "Non-existent Name")
assert.Error(t, err)
assert.True(t, xlerrors.IsNotFound(err))
assert.True(t, slerrors.IsNotFound(err))
assert.Nil(t, result)
// LIST

6
database/drivers/mysqldriver/session.go

@ -3,7 +3,7 @@ package mysqldriver
import (
"context"
"database/sql"
"git.aiterp.net/stufflog/server/internal/xlerrors"
"git.aiterp.net/stufflog/server/internal/slerrors"
"git.aiterp.net/stufflog/server/models"
"github.com/jmoiron/sqlx"
"time"
@ -18,12 +18,12 @@ func (r *sessionRepository) Find(ctx context.Context, id string) (*models.Sessio
err := r.db.GetContext(ctx, &session, "SELECT * FROM session WHERE session_id=?", id)
if err != nil {
if err == sql.ErrNoRows {
return nil, xlerrors.NotFound("Session")
return nil, slerrors.NotFound("Session")
}
return nil, err
} else if time.Now().After(session.ExpiryTime) {
return nil, xlerrors.NotFound("Session")
return nil, slerrors.NotFound("Session")
}
return &session, nil

4
database/drivers/mysqldriver/users.go

@ -4,7 +4,7 @@ import (
"context"
"database/sql"
"errors"
"git.aiterp.net/stufflog/server/internal/xlerrors"
"git.aiterp.net/stufflog/server/internal/slerrors"
"git.aiterp.net/stufflog/server/models"
sq "github.com/Masterminds/squirrel"
"github.com/jmoiron/sqlx"
@ -19,7 +19,7 @@ func (r *userRepository) Find(ctx context.Context, id string) (*models.User, err
err := r.db.GetContext(ctx, &user, "SELECT * FROM user WHERE user_id=?", id)
if err != nil {
if err == sql.ErrNoRows {
return nil, xlerrors.NotFound("User")
return nil, slerrors.NotFound("User")
}
return nil, err

4
database/drivers/mysqldriver/users_test.go

@ -2,7 +2,7 @@ package mysqldriver
import (
"context"
"git.aiterp.net/stufflog/server/internal/xlerrors"
"git.aiterp.net/stufflog/server/internal/slerrors"
"git.aiterp.net/stufflog/server/models"
"github.com/stretchr/testify/assert"
"testing"
@ -59,7 +59,7 @@ func TestUserRepository(t *testing.T) {
// FIND't
result, err = users.Find(ctx, "NonExistent")
assert.Error(t, err)
assert.True(t, xlerrors.IsNotFound(err))
assert.True(t, slerrors.IsNotFound(err))
assert.Nil(t, result)
// LIST

4
graph/loaders/userloader.go

@ -3,7 +3,7 @@ package loaders
import (
"context"
"git.aiterp.net/stufflog/server/database/repositories"
"git.aiterp.net/stufflog/server/internal/xlerrors"
"git.aiterp.net/stufflog/server/internal/slerrors"
"git.aiterp.net/stufflog/server/models"
"time"
)
@ -47,7 +47,7 @@ func NewUserLoader(ctx context.Context, userRepo repositories.UserRepository) *U
if user != nil {
results[i] = user
} else {
errors[i] = xlerrors.NotFound("User")
errors[i] = slerrors.NotFound("User")
}
}

4
graph/resolvers/issue.resolvers.go

@ -9,7 +9,7 @@ import (
"git.aiterp.net/stufflog/server/graph/graphcore"
"git.aiterp.net/stufflog/server/graph/graphutil"
"git.aiterp.net/stufflog/server/graph/loaders"
"git.aiterp.net/stufflog/server/internal/xlerrors"
"git.aiterp.net/stufflog/server/internal/slerrors"
"git.aiterp.net/stufflog/server/models"
)
@ -55,7 +55,7 @@ func (r *issueResolver) Status(ctx context.Context, obj *models.Issue) (*models.
}
status, err := r.Database.ProjectStatuses().Find(ctx, obj.ProjectID, obj.StatusName)
if xlerrors.IsNotFound(err) {
if slerrors.IsNotFound(err) {
return &models.ProjectStatus{
ProjectID: obj.ProjectID,
Stage: obj.StatusStage,

4
graph/resolvers/issuetask.resolvers.go

@ -12,7 +12,7 @@ import (
"git.aiterp.net/stufflog/server/graph/graphcore"
"git.aiterp.net/stufflog/server/graph/graphutil"
"git.aiterp.net/stufflog/server/internal/xlerrors"
"git.aiterp.net/stufflog/server/internal/slerrors"
"git.aiterp.net/stufflog/server/models"
)
@ -57,7 +57,7 @@ func (r *issueTaskResolver) Status(ctx context.Context, obj *models.IssueTask) (
// Find it in the database. TODO: DataLoader
status, err := r.Database.ProjectStatuses().Find(ctx, projectID, obj.StatusName)
if xlerrors.IsNotFound(err) {
if slerrors.IsNotFound(err) {
return &models.ProjectStatus{
ProjectID: projectID,
Stage: obj.StatusStage,

28
graph/resolvers/mutation.resolvers.go

@ -10,14 +10,14 @@ import (
"time"
"git.aiterp.net/stufflog/server/graph/graphcore"
"git.aiterp.net/stufflog/server/internal/xlerrors"
"git.aiterp.net/stufflog/server/internal/slerrors"
"git.aiterp.net/stufflog/server/models"
)
func (r *mutationResolver) CreateProject(ctx context.Context, input graphcore.ProjectCreateInput) (*models.Project, error) {
user := r.Auth.UserFromContext(ctx)
if user == nil {
return nil, xlerrors.PermissionDenied
return nil, slerrors.PermissionDenied
}
project := &models.Project{
@ -50,7 +50,7 @@ func (r *mutationResolver) CreateProject(ctx context.Context, input graphcore.Pr
func (r *mutationResolver) CreateActivity(ctx context.Context, input graphcore.ActivityCreateInput) (*models.Activity, error) {
user := r.Auth.UserFromContext(ctx)
if user == nil {
return nil, xlerrors.PermissionDenied
return nil, slerrors.PermissionDenied
}
project, err := r.Database.Projects().Find(ctx, input.ProjectID)
@ -58,7 +58,7 @@ func (r *mutationResolver) CreateActivity(ctx context.Context, input graphcore.A
return nil, err
}
if perm, err := r.Auth.ProjectPermission(ctx, *project); err != nil || !perm.CanManageActivities() {
return nil, xlerrors.PermissionDenied
return nil, slerrors.PermissionDenied
}
activity := &models.Activity{
@ -87,7 +87,7 @@ func (r *mutationResolver) CreateActivity(ctx context.Context, input graphcore.A
func (r *mutationResolver) EditActivity(ctx context.Context, input graphcore.ActivityEditInput) (*models.Activity, error) {
user := r.Auth.UserFromContext(ctx)
if user == nil {
return nil, xlerrors.PermissionDenied
return nil, slerrors.PermissionDenied
}
activity, err := r.Database.Activities().Find(ctx, input.ActivityID)
@ -100,7 +100,7 @@ func (r *mutationResolver) EditActivity(ctx context.Context, input graphcore.Act
return nil, err
}
if perm, err := r.Auth.ProjectPermission(ctx, *project); err != nil || !perm.CanManageActivities() {
return nil, xlerrors.PermissionDenied
return nil, slerrors.PermissionDenied
}
if input.SetName != nil {
@ -127,7 +127,7 @@ func (r *mutationResolver) EditActivity(ctx context.Context, input graphcore.Act
func (r *mutationResolver) CreateItem(ctx context.Context, input *graphcore.ItemCreateInput) (*models.Item, error) {
user := r.Auth.UserFromContext(ctx)
if user == nil {
return nil, xlerrors.PermissionDenied
return nil, slerrors.PermissionDenied
}
if input.Name == "" {
@ -162,7 +162,7 @@ func (r *mutationResolver) EditItem(ctx context.Context, input *graphcore.ItemEd
func (r *mutationResolver) CreateIssue(ctx context.Context, input graphcore.IssueCreateInput) (*models.Issue, error) {
user := r.Auth.UserFromContext(ctx)
if user == nil {
return nil, xlerrors.PermissionDenied
return nil, slerrors.PermissionDenied
}
project, err := r.Database.Projects().Find(ctx, input.ProjectID)
@ -170,7 +170,7 @@ func (r *mutationResolver) CreateIssue(ctx context.Context, input graphcore.Issu
return nil, err
}
if perm, err := r.Auth.ProjectPermission(ctx, *project); err != nil || !perm.CanManageOwnIssue() {
return nil, xlerrors.PermissionDenied
return nil, slerrors.PermissionDenied
}
status, err := r.Database.ProjectStatuses().Find(ctx, project.ID, input.StatusName)
@ -209,7 +209,7 @@ func (r *mutationResolver) CreateIssue(ctx context.Context, input graphcore.Issu
func (r *mutationResolver) CreateIssueTask(ctx context.Context, input graphcore.IssueTaskCreateInput) (*models.IssueTask, error) {
user := r.Auth.UserFromContext(ctx)
if user == nil {
return nil, xlerrors.PermissionDenied
return nil, slerrors.PermissionDenied
}
issue, err := r.Database.Issues().Find(ctx, input.IssueID)
@ -217,7 +217,7 @@ func (r *mutationResolver) CreateIssueTask(ctx context.Context, input graphcore.
return nil, err
}
if perm, err := r.Auth.IssuePermission(ctx, *issue); err != nil || !perm.CanManageOwnIssue() {
return nil, xlerrors.PermissionDenied
return nil, slerrors.PermissionDenied
}
status, err := r.Database.ProjectStatuses().Find(ctx, issue.ProjectID, input.StatusName)
@ -229,7 +229,7 @@ func (r *mutationResolver) CreateIssueTask(ctx context.Context, input graphcore.
if err != nil {
return nil, err
} else if activity.ProjectID != issue.ProjectID {
return nil, xlerrors.NotFound("Activity")
return nil, slerrors.NotFound("Activity")
}
issueTask := &models.IssueTask{
@ -261,7 +261,7 @@ func (r *mutationResolver) CreateIssueTask(ctx context.Context, input graphcore.
func (r *mutationResolver) EditIssueTask(ctx context.Context, input graphcore.IssueTaskEditInput) (*models.IssueTask, error) {
user := r.Auth.UserFromContext(ctx)
if user == nil {
return nil, xlerrors.PermissionDenied
return nil, slerrors.PermissionDenied
}
task, err := r.Database.IssueTasks().Find(ctx, input.IssueTaskID)
@ -274,7 +274,7 @@ func (r *mutationResolver) EditIssueTask(ctx context.Context, input graphcore.Is
return nil, err
}
if perm, err := r.Auth.IssuePermission(ctx, *issue); err != nil || !perm.CanManageOwnIssue() {
return nil, xlerrors.PermissionDenied
return nil, slerrors.PermissionDenied
}
if input.SetName != nil {

4
graph/resolvers/project.resolvers.go

@ -8,7 +8,7 @@ import (
"git.aiterp.net/stufflog/server/graph/graphcore"
"git.aiterp.net/stufflog/server/graph/loaders"
"git.aiterp.net/stufflog/server/internal/xlerrors"
"git.aiterp.net/stufflog/server/internal/slerrors"
"git.aiterp.net/stufflog/server/models"
)
@ -29,7 +29,7 @@ func (r *projectResolver) Issues(ctx context.Context, obj *models.Project, filte
func (r *projectResolver) Permissions(ctx context.Context, obj *models.Project) ([]*models.ProjectPermission, error) {
if perm, err := r.Auth.ProjectPermission(ctx, *obj); err != nil || !perm.CanManagePermissions() {
return nil, xlerrors.PermissionDenied
return nil, slerrors.PermissionDenied
}
return r.Database.Projects().ListPermissions(ctx, *obj)

17
graph/resolvers/query.resolvers.go

@ -6,15 +6,16 @@ package resolvers
import (
"context"
"errors"
"git.aiterp.net/stufflog/server/graph/graphcore"
"git.aiterp.net/stufflog/server/internal/xlerrors"
"git.aiterp.net/stufflog/server/internal/slerrors"
"git.aiterp.net/stufflog/server/models"
)
func (r *queryResolver) Issue(ctx context.Context, id string) (*models.Issue, error) {
user := r.Auth.UserFromContext(ctx)
if user == nil {
return nil, xlerrors.PermissionDenied
return nil, slerrors.PermissionDenied
}
issue, err := r.Database.Issues().Find(ctx, id)
@ -32,7 +33,7 @@ func (r *queryResolver) Issue(ctx context.Context, id string) (*models.Issue, er
func (r *queryResolver) Issues(ctx context.Context, filter *models.IssueFilter) ([]*models.Issue, error) {
user := r.Auth.UserFromContext(ctx)
if user == nil {
return nil, xlerrors.PermissionDenied
return nil, slerrors.PermissionDenied
}
if filter == nil {
@ -60,7 +61,7 @@ func (r *queryResolver) Issues(ctx context.Context, filter *models.IssueFilter)
func (r *queryResolver) Item(ctx context.Context, id string) (*models.Item, error) {
user := r.Auth.UserFromContext(ctx)
if user == nil {
return nil, xlerrors.PermissionDenied
return nil, slerrors.PermissionDenied
}
return r.Database.Items().Find(ctx, id)
@ -69,7 +70,7 @@ func (r *queryResolver) Item(ctx context.Context, id string) (*models.Item, erro
func (r *queryResolver) Items(ctx context.Context, filter *models.ItemFilter) ([]*models.Item, error) {
user := r.Auth.UserFromContext(ctx)
if user == nil {
return nil, xlerrors.PermissionDenied
return nil, slerrors.PermissionDenied
}
if filter == nil {
@ -82,7 +83,7 @@ func (r *queryResolver) Items(ctx context.Context, filter *models.ItemFilter) ([
func (r *queryResolver) ItemTags(ctx context.Context) ([]string, error) {
user := r.Auth.UserFromContext(ctx)
if user == nil {
return nil, xlerrors.PermissionDenied
return nil, slerrors.PermissionDenied
}
return r.Database.Items().GetTags(ctx)
@ -91,7 +92,7 @@ func (r *queryResolver) ItemTags(ctx context.Context) ([]string, error) {
func (r *queryResolver) Project(ctx context.Context, id string) (*models.Project, error) {
user := r.Auth.UserFromContext(ctx)
if user == nil {
return nil, xlerrors.PermissionDenied
return nil, slerrors.PermissionDenied
}
project, err := r.Database.Projects().Find(ctx, id)
@ -109,7 +110,7 @@ func (r *queryResolver) Project(ctx context.Context, id string) (*models.Project
func (r *queryResolver) Projects(ctx context.Context, filter *models.ProjectFilter) ([]*models.Project, error) {
user := r.Auth.UserFromContext(ctx)
if user == nil {
return nil, xlerrors.PermissionDenied
return nil, slerrors.PermissionDenied
}
skipCheck := false

2
internal/xlerrors/notfound.go → internal/slerrors/notfound.go

@ -1,4 +1,4 @@
package xlerrors
package slerrors
type notFoundError struct {
Subject string

2
internal/xlerrors/permission.go → internal/slerrors/permission.go

@ -1,4 +1,4 @@
package xlerrors
package slerrors
import "errors"

4
main.go

@ -5,7 +5,7 @@ import (
"git.aiterp.net/stufflog/server/database"
"git.aiterp.net/stufflog/server/graph"
"git.aiterp.net/stufflog/server/internal/generate"
"git.aiterp.net/stufflog/server/internal/xlerrors"
"git.aiterp.net/stufflog/server/internal/slerrors"
"git.aiterp.net/stufflog/server/models"
"git.aiterp.net/stufflog/server/services"
"github.com/99designs/gqlgen/graphql/playground"
@ -61,7 +61,7 @@ func main() {
newPass := generate.Generate(20, "")
admin, err := db.Users().Find(timeout, "Admin")
if xlerrors.IsNotFound(err) {
if slerrors.IsNotFound(err) {
admin = &models.User{
ID: "Admin",
Name: "Administrator",

20
services/auth.go

@ -5,7 +5,7 @@ import (
"errors"
"git.aiterp.net/stufflog/server/database/repositories"
"git.aiterp.net/stufflog/server/internal/generate"
"git.aiterp.net/stufflog/server/internal/xlerrors"
"git.aiterp.net/stufflog/server/internal/slerrors"
"git.aiterp.net/stufflog/server/models"
"github.com/gin-gonic/gin"
"math/rand"
@ -68,7 +68,7 @@ func (auth *Auth) Login(ctx context.Context, username, password string) (*models
func (auth *Auth) Logout(ctx context.Context) (*models.User, error) {
user := auth.UserFromContext(ctx)
if user == nil {
return nil, xlerrors.PermissionDenied
return nil, slerrors.PermissionDenied
}
c, ok := ctx.Value(ginCtxKey).(*gin.Context)
@ -84,7 +84,7 @@ func (auth *Auth) Logout(ctx context.Context) (*models.User, error) {
func (auth *Auth) CreateUser(ctx context.Context, username, password, name string, active, admin bool) (*models.User, error) {
loggedInUser := auth.UserFromContext(ctx)
if loggedInUser == nil || !loggedInUser.Admin {
return nil, xlerrors.PermissionDenied
return nil, slerrors.PermissionDenied
}
user := &models.User{
@ -114,7 +114,7 @@ func (auth *Auth) UserFromContext(ctx context.Context) *models.User {
func (auth *Auth) ProjectPermission(ctx context.Context, project models.Project) (*models.ProjectPermission, error) {
user := auth.UserFromContext(ctx)
if user == nil || !user.Active {
return nil, xlerrors.PermissionDenied
return nil, slerrors.PermissionDenied
}
permission, err := auth.projects.GetPermission(ctx, project, *user)
@ -122,7 +122,7 @@ func (auth *Auth) ProjectPermission(ctx context.Context, project models.Project)
return nil, ErrInternalPermissionFailure
}
if permission.Level == models.ProjectPermissionLevelNoAccess {
return nil, xlerrors.PermissionDenied
return nil, slerrors.PermissionDenied
}
return permission, nil
@ -131,7 +131,7 @@ func (auth *Auth) ProjectPermission(ctx context.Context, project models.Project)
func (auth *Auth) IssuePermission(ctx context.Context, issue models.Issue) (*models.ProjectPermission, error) {
user := auth.UserFromContext(ctx)
if user == nil || !user.Active {
return nil, xlerrors.PermissionDenied
return nil, slerrors.PermissionDenied
}
isOwnedOrAssigned := issue.AssigneeID == user.ID || issue.OwnerID == user.ID
@ -141,10 +141,10 @@ func (auth *Auth) IssuePermission(ctx context.Context, issue models.Issue) (*mod
return nil, ErrInternalPermissionFailure
}
if permission.Level == models.ProjectPermissionLevelNoAccess {
return nil, xlerrors.PermissionDenied
return nil, slerrors.PermissionDenied
}
if !(permission.CanViewAnyIssue() || (permission.CanViewOwnIssue() && isOwnedOrAssigned)) {
return nil, xlerrors.PermissionDenied
return nil, slerrors.PermissionDenied
}
return permission, nil
@ -184,7 +184,7 @@ func (auth *Auth) CheckGinSession(c *gin.Context) {
func (auth *Auth) EditUser(ctx context.Context, username string, setName *string, currentPassword *string, newPassword *string) (*models.User, error) {
loggedInUser := auth.UserFromContext(ctx)
if loggedInUser == nil {
return nil, xlerrors.PermissionDenied
return nil, slerrors.PermissionDenied
}
user, err := auth.users.Find(ctx, username)
@ -193,7 +193,7 @@ func (auth *Auth) EditUser(ctx context.Context, username string, setName *string
}
if user.ID != loggedInUser.ID && !loggedInUser.Admin {
return nil, xlerrors.PermissionDenied
return nil, slerrors.PermissionDenied
}
if newPassword != nil {

Loading…
Cancel
Save