MCPcopy
hub / github.com/dgraph-io/dgraph / userOrGroupDel

Function userOrGroupDel

acl/acl.go:190–234  ·  view source on GitHub ↗
(conf *viper.Viper, userOrGroupId string,
	queryFn func(context.Context, *dgo.Txn, string) (AclEntity, error))

Source from the content-addressed store, hash-verified

188}
189
190func userOrGroupDel(conf *viper.Viper, userOrGroupId string,
191 queryFn func(context.Context, *dgo.Txn, string) (AclEntity, error)) error {
192 dc, cancel, err := getClientWithAdminCtx(conf)
193 if err != nil {
194 return fmt.Errorf("unable to get admin context: %w", err)
195 }
196 defer cancel()
197
198 ctx, ctxCancel := context.WithTimeout(context.Background(), 10*time.Second)
199 defer ctxCancel()
200 txn := dc.NewTxn()
201 defer func() {
202 if err := txn.Discard(ctx); err != nil {
203 glog.Errorf("Unable to discard transaction:%v", err)
204 }
205 }()
206
207 entity, err := queryFn(ctx, txn, userOrGroupId)
208 if err != nil {
209 return err
210 }
211 if len(entity.GetUid()) == 0 {
212 return fmt.Errorf("unable to delete %q since it does not exist",
213 userOrGroupId)
214 }
215
216 deleteNQuads := []*api.NQuad{
217 {
218 Subject: entity.GetUid(),
219 Predicate: x.Star,
220 ObjectValue: &api.Value{Val: &api.Value_DefaultVal{DefaultVal: x.Star}},
221 }}
222
223 mu := &api.Mutation{
224 CommitNow: true,
225 Del: deleteNQuads,
226 }
227
228 if _, err = txn.Mutate(ctx, mu); err != nil {
229 return fmt.Errorf("unable to delete %q: %w", userOrGroupId, err)
230 }
231
232 fmt.Printf("Successfully deleted %q\n", userOrGroupId)
233 return nil
234}
235
236func mod(conf *viper.Viper) error {
237 userId, _, err := getUserAndGroup(conf)

Callers 1

delFunction · 0.85

Calls 4

getClientWithAdminCtxFunction · 0.85
GetUidMethod · 0.65
MutateMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected