mirror of
https://github.com/semaphoreui/semaphore.git
synced 2025-01-20 15:29:28 +01:00
Fix method calls, add is null for globals
This commit is contained in:
parent
7fd87d737b
commit
8d0e39b065
@ -187,7 +187,6 @@ func Route() *mux.Router {
|
||||
projectUserAPI.Path("/webhooks").HandlerFunc(projects.AddWebhook).Methods("POST")
|
||||
|
||||
projectWebhooksAPI := projectUserAPI.PathPrefix("/webhook").Subrouter()
|
||||
projectWebhooksAPI.Use(projects.WebhookMiddleware, projects.MustBeAdmin)
|
||||
|
||||
projectWebhooksAPI.Path("/{webhook_id}").Methods("GET", "HEAD").HandlerFunc(projects.GetWebhook)
|
||||
projectWebhooksAPI.Path("/{webhook_id}").Methods("PUT").HandlerFunc(projects.UpdateWebhook)
|
||||
|
@ -1,3 +1,4 @@
|
||||
|
||||
package sql
|
||||
|
||||
import (
|
||||
@ -207,8 +208,13 @@ func (d *SqlDb) getObjectsByReferrer(referrerID int, referringObjectProps db.Obj
|
||||
var referringColumn = referringObjectProps.ReferringColumnSuffix
|
||||
|
||||
q := squirrel.Select("*").
|
||||
From(props.TableName+" pe").
|
||||
Where("pe." + referringColumn + "=?", referrerID)
|
||||
From(props.TableName+" pe")
|
||||
|
||||
if props.IsGlobal {
|
||||
q = q.Where("pe." + referringColumn + " is null")
|
||||
} else {
|
||||
q = q.Where("pe." + referringColumn + "=?", referrerID)
|
||||
}
|
||||
|
||||
orderDirection := "ASC"
|
||||
if params.SortInverted {
|
||||
@ -235,45 +241,10 @@ func (d *SqlDb) getObjectsByReferrer(referrerID int, referringObjectProps db.Obj
|
||||
return
|
||||
}
|
||||
|
||||
func (d *SqlDb) getObjects(projectID int, props db.ObjectProps, params db.RetrieveQueryParams, objects interface{}) (err error) {
|
||||
q := squirrel.Select("*").
|
||||
From(props.TableName + " pe")
|
||||
|
||||
if props.IsGlobal {
|
||||
q = q.Where("pe.project_id is null")
|
||||
} else {
|
||||
q = q.Where("pe.project_id=?", projectID)
|
||||
}
|
||||
|
||||
orderDirection := "ASC"
|
||||
|
||||
if params.SortInverted {
|
||||
orderDirection = "DESC"
|
||||
}
|
||||
|
||||
orderColumn := props.DefaultSortingColumn
|
||||
if containsStr(props.SortableColumns, params.SortBy) {
|
||||
orderColumn = params.SortBy
|
||||
}
|
||||
|
||||
if orderColumn != "" {
|
||||
q = q.OrderBy("pe." + orderColumn + " " + orderDirection)
|
||||
}
|
||||
|
||||
query, args, err := q.ToSql()
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
_, err = d.selectAll(objects, query, args...)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (d *SqlDb) getObject(projectID int, props db.ObjectProps, objectID int, objects interface{}) (err error) {
|
||||
return d.getObjectByReferrer(projectID, db.ProjectProps, props, objectID, objects)
|
||||
}
|
||||
|
||||
func (d *SqlDb) getObjects(projectID int, props db.ObjectProps, params db.RetrieveQueryParams, objects interface{}) (err error) {
|
||||
return d.getObjectsByReferrer(projectID, db.ProjectProps, props, params, objects);
|
||||
}
|
||||
|
@ -6,27 +6,6 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
var pool *mockDriver;
|
||||
|
||||
type sqlmock struct {
|
||||
ordered bool
|
||||
dsn string
|
||||
opened int
|
||||
drv *mockDriver
|
||||
converter driver.ValueConverter
|
||||
queryMatcher QueryMatcher
|
||||
monitorPings bool
|
||||
|
||||
expected []expectation
|
||||
}
|
||||
|
||||
func init() {
|
||||
pool = &mockDriver{
|
||||
conns: make(map[string]*sqlmock),
|
||||
}
|
||||
SqlDb.sql.Register("sqlmock", pool)
|
||||
}
|
||||
|
||||
func TestValidatePort(t *testing.T) {
|
||||
d := SqlDb{}
|
||||
q := d.prepareQueryWithDialect("select * from `test` where id = ?, email = ?", gorp.PostgresDialect{})
|
||||
@ -34,7 +13,3 @@ func TestValidatePort(t *testing.T) {
|
||||
t.Error("invalid postgres query")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetAllObjects(t *testing.T) {
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user