Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
eec17845
Commit
eec17845
authored
Jan 20, 2015
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Validation check for not removing the last account admin
parent
4ea5d800
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
28 additions
and
3 deletions
+28
-3
pkg/api/account_users.go
+4
-0
pkg/models/account_user.go
+2
-1
pkg/services/sqlstore/account_test.go
+6
-0
pkg/services/sqlstore/account_users.go
+14
-0
pkg/services/sqlstore/migrations_test.go
+2
-2
No files found.
pkg/api/account_users.go
View file @
eec17845
...
@@ -54,6 +54,10 @@ func RemoveAccountUser(c *middleware.Context) {
...
@@ -54,6 +54,10 @@ func RemoveAccountUser(c *middleware.Context) {
cmd
:=
m
.
RemoveAccountUserCommand
{
AccountId
:
c
.
AccountId
,
UserId
:
userId
}
cmd
:=
m
.
RemoveAccountUserCommand
{
AccountId
:
c
.
AccountId
,
UserId
:
userId
}
if
err
:=
bus
.
Dispatch
(
&
cmd
);
err
!=
nil
{
if
err
:=
bus
.
Dispatch
(
&
cmd
);
err
!=
nil
{
if
err
==
m
.
ErrLastAccountAdmin
{
c
.
JsonApiErr
(
400
,
"Cannot remove last account admin"
,
nil
)
return
}
c
.
JsonApiErr
(
500
,
"Failed to remove user from account"
,
err
)
c
.
JsonApiErr
(
500
,
"Failed to remove user from account"
,
err
)
}
}
...
...
pkg/models/account_user.go
View file @
eec17845
...
@@ -7,7 +7,8 @@ import (
...
@@ -7,7 +7,8 @@ import (
// Typed errors
// Typed errors
var
(
var
(
ErrInvalidRoleType
=
errors
.
New
(
"Invalid role type"
)
ErrInvalidRoleType
=
errors
.
New
(
"Invalid role type"
)
ErrLastAccountAdmin
=
errors
.
New
(
"Cannot remove last account admin"
)
)
)
type
RoleType
string
type
RoleType
string
...
...
pkg/services/sqlstore/account_test.go
View file @
eec17845
...
@@ -103,6 +103,12 @@ func TestAccountDataAccess(t *testing.T) {
...
@@ -103,6 +103,12 @@ func TestAccountDataAccess(t *testing.T) {
So
(
query
.
Result
.
AccountRole
,
ShouldEqual
,
"Viewer"
)
So
(
query
.
Result
.
AccountRole
,
ShouldEqual
,
"Viewer"
)
})
})
})
})
Convey
(
"Cannot delete last admin account user"
,
func
()
{
cmd
:=
m
.
RemoveAccountUserCommand
{
AccountId
:
ac1
.
AccountId
,
UserId
:
ac1
.
Id
}
err
:=
RemoveAccountUser
(
&
cmd
)
So
(
err
,
ShouldEqual
,
m
.
ErrLastAccountAdmin
)
})
})
})
})
})
})
})
...
...
pkg/services/sqlstore/account_users.go
View file @
eec17845
...
@@ -47,6 +47,20 @@ func RemoveAccountUser(cmd *m.RemoveAccountUserCommand) error {
...
@@ -47,6 +47,20 @@ func RemoveAccountUser(cmd *m.RemoveAccountUserCommand) error {
return
inTransaction
(
func
(
sess
*
xorm
.
Session
)
error
{
return
inTransaction
(
func
(
sess
*
xorm
.
Session
)
error
{
var
rawSql
=
"DELETE FROM account_user WHERE account_id=? and user_id=?"
var
rawSql
=
"DELETE FROM account_user WHERE account_id=? and user_id=?"
_
,
err
:=
sess
.
Exec
(
rawSql
,
cmd
.
AccountId
,
cmd
.
UserId
)
_
,
err
:=
sess
.
Exec
(
rawSql
,
cmd
.
AccountId
,
cmd
.
UserId
)
if
err
!=
nil
{
return
err
}
// validate that there is an admin user left
res
,
err
:=
sess
.
Query
(
"SELECT 1 from account_user WHERE account_id=? and role='Admin'"
,
cmd
.
AccountId
)
if
err
!=
nil
{
return
err
}
if
len
(
res
)
==
0
{
return
m
.
ErrLastAccountAdmin
}
return
err
return
err
})
})
}
}
pkg/services/sqlstore/migrations_test.go
View file @
eec17845
...
@@ -20,8 +20,8 @@ func TestMigrations(t *testing.T) {
...
@@ -20,8 +20,8 @@ func TestMigrations(t *testing.T) {
testDBs
:=
[]
sqlutil
.
TestDB
{
testDBs
:=
[]
sqlutil
.
TestDB
{
sqlutil
.
TestDB_Sqlite3
,
sqlutil
.
TestDB_Sqlite3
,
sqlutil
.
TestDB_Mysql
,
//
sqlutil.TestDB_Mysql,
sqlutil
.
TestDB_Postgres
,
//
sqlutil.TestDB_Postgres,
}
}
for
_
,
testDB
:=
range
testDBs
{
for
_
,
testDB
:=
range
testDBs
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment