This commit is contained in:
@@ -6,5 +6,6 @@ type Permission struct {
|
|||||||
ReadOnly bool `db:"ReadOnly"`
|
ReadOnly bool `db:"ReadOnly"`
|
||||||
RoleId int `db:"RoleId"`
|
RoleId int `db:"RoleId"`
|
||||||
SafeId int `db:"SafeId"`
|
SafeId int `db:"SafeId"`
|
||||||
|
UserId int `db:"UserId"`
|
||||||
GroupId int `db:"GroupId"`
|
GroupId int `db:"GroupId"`
|
||||||
}
|
}
|
||||||
|
@@ -26,10 +26,11 @@ type Secret struct {
|
|||||||
|
|
||||||
// Used for querying all secrets the user has access to
|
// Used for querying all secrets the user has access to
|
||||||
type UserSecret struct {
|
type UserSecret struct {
|
||||||
User
|
UserId int `db:"UserId" json:"userId"`
|
||||||
|
GroupId int `db:"GroupId" json:"groupId"`
|
||||||
Group
|
Group
|
||||||
Permission
|
Permission
|
||||||
Safe
|
SafeName string `db:"SafeName"`
|
||||||
Secret
|
Secret
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,7 +72,7 @@ func SecretsGetAllowed(s *Secret, userId int) ([]UserSecret, error) {
|
|||||||
|
|
||||||
// Query for group access
|
// Query for group access
|
||||||
queryArgs := []interface{}{}
|
queryArgs := []interface{}{}
|
||||||
query := `SELECT *
|
query := `SELECT users.UserId, users.GroupId, permissions.ReadOnly, safes.SafeName, secrets.*
|
||||||
FROM users
|
FROM users
|
||||||
INNER JOIN groups ON users.GroupId = groups.GroupId
|
INNER JOIN groups ON users.GroupId = groups.GroupId
|
||||||
INNER JOIN permissions ON groups.GroupId = permissions.GroupId
|
INNER JOIN permissions ON groups.GroupId = permissions.GroupId
|
||||||
@@ -125,7 +126,7 @@ func SecretsGetAllowed(s *Secret, userId int) ([]UserSecret, error) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// Execute the query
|
// Execute the query
|
||||||
log.Printf("SecretsGetAllowedForGroup query string : '%s'\nArguments: %+v\n", query, queryArgs)
|
log.Printf("SecretsGetAllowedForGroup query string : '%s'\nArguments:%+v\n", query, queryArgs)
|
||||||
rows, err := db.Queryx(query, queryArgs...)
|
rows, err := db.Queryx(query, queryArgs...)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@@ -65,11 +65,9 @@ const createPermissions = `
|
|||||||
Description VARCHAR DEFAULT '',
|
Description VARCHAR DEFAULT '',
|
||||||
ReadOnly BOOLEAN DEFAULT 0,
|
ReadOnly BOOLEAN DEFAULT 0,
|
||||||
SafeId INTEGER,
|
SafeId INTEGER,
|
||||||
UserId INTEGER,
|
UserId INTEGER DEFAULT 0,
|
||||||
GroupId INTEGER,
|
GroupId INTEGER DEFAULT 0,
|
||||||
FOREIGN KEY (SafeId) REFERENCES safes(SafeId),
|
FOREIGN KEY (SafeId) REFERENCES safes(SafeId)
|
||||||
FOREIGN KEY (UserId) REFERENCES users(UserId),
|
|
||||||
FOREIGN KEY (GroupId) REFERENCES groups(GroupId)
|
|
||||||
);
|
);
|
||||||
`
|
`
|
||||||
|
|
||||||
@@ -367,15 +365,15 @@ func CreateTables() {
|
|||||||
Description VARCHAR DEFAULT '',
|
Description VARCHAR DEFAULT '',
|
||||||
ReadOnly BOOLEAN DEFAULT 0,
|
ReadOnly BOOLEAN DEFAULT 0,
|
||||||
SafeId INTEGER,
|
SafeId INTEGER,
|
||||||
UserId INTEGER,
|
UserId INTEGER DEFAULT 0,
|
||||||
GroupId INTEGER,
|
GroupId INTEGER DEFAULT 0,
|
||||||
FOREIGN KEY (SafeId) REFERENCES safes(SafeId),
|
FOREIGN KEY (SafeId) REFERENCES safes(SafeId)
|
||||||
FOREIGN KEY (UserId) REFERENCES users(UserId),
|
|
||||||
FOREIGN KEY (GroupId) REFERENCES groups(GroupId)
|
|
||||||
);
|
);
|
||||||
INSERT INTO permissions SELECT PermissionId, SafeId, UserId, GroupId, '' AS Description, 0 as ReadOnly FROM _permissions_old;
|
INSERT INTO permissions SELECT PermissionId, SafeId, UserId, GroupId, '' AS Description, 0 as ReadOnly FROM _permissions_old;
|
||||||
UPDATE permissions SET ReadOnly = 0 WHERE ReadOnly is null;
|
UPDATE permissions SET ReadOnly = 0 WHERE ReadOnly is null;
|
||||||
UPDATE permissions SET Description = '' WHERE Description is null;
|
UPDATE permissions SET Description = '' WHERE Description is null;
|
||||||
|
UPDATE permissions SET UserId = 0 WHERE UserId is null;
|
||||||
|
UPDATE permissions SET GroupId = 0 WHERE GroupId is null;
|
||||||
COMMIT;
|
COMMIT;
|
||||||
PRAGMA foreign_keys=on;
|
PRAGMA foreign_keys=on;
|
||||||
DROP TABLE _permissions_old;
|
DROP TABLE _permissions_old;
|
||||||
|
Reference in New Issue
Block a user