MCPcopy Create free account
hub / github.com/dolthub/doltgresql / RowIter

Method RowIter

server/node/drop_role.go:53–90  ·  view source on GitHub ↗

RowIter implements the interface sql.ExecSourceRel.

(ctx *sql.Context, r sql.Row)

Source from the content-addressed store, hash-verified

51
52// RowIter implements the interface sql.ExecSourceRel.
53func (c *DropRole) RowIter(ctx *sql.Context, r sql.Row) (sql.RowIter, error) {
54 // TODO: disallow dropping the role if it owns anything
55 // First we'll loop over all of the names to check that they all exist
56 var userRole auth.Role
57 var roles []auth.Role
58 var err error
59 auth.LockRead(func() {
60 userRole = auth.GetRole(ctx.Client().User)
61 for _, roleName := range c.Names {
62 role := auth.GetRole(roleName)
63 if role.IsValid() {
64 roles = append(roles, role)
65 } else if !c.IfExists {
66 err = errors.Errorf(`role "%s" does not exist`, roleName)
67 break
68 }
69 if !userRole.IsSuperUser && (role.IsSuperUser || !userRole.CanCreateRoles) {
70 // TODO: grab the actual error message
71 err = errors.Errorf(`role "%s" does not have permission to drop role "%s"`, userRole.Name, role.Name)
72 break
73 }
74 }
75 })
76 if err != nil {
77 return nil, err
78 }
79 // Then we'll loop again, dropping all of the users
80 auth.LockWrite(func() {
81 for _, role := range roles {
82 auth.DropRole(role.Name)
83 }
84 err = auth.PersistChanges()
85 })
86 if err != nil {
87 return nil, err
88 }
89 return sql.RowsToRowIter(), nil
90}
91
92// Schema implements the interface sql.ExecSourceRel.
93func (c *DropRole) Schema(ctx *sql.Context) sql.Schema {

Callers

nothing calls this directly

Calls 7

LockReadFunction · 0.92
GetRoleFunction · 0.92
LockWriteFunction · 0.92
DropRoleFunction · 0.92
PersistChangesFunction · 0.92
ErrorfMethod · 0.65
IsValidMethod · 0.45

Tested by

no test coverage detected