// DeleteUser removes a user from Influx Enterprise
488059
func (m *MetaClient) DeleteUser(ctx context.Context, name string) error {
	a := &UserAction{
		Action: "delete",
		User: &User{
			Name: name,
		},
	}

	return m.Post(ctx, "/user", a, nil)
}
389849
func (api OrganizationsAPI) DeleteUserGrant(w http.ResponseWriter, r *http.Request) {
	globalid := mux.Vars(r)["globalid"]
	userIdentifier := mux.Vars(r)["username"]
	grantString := mux.Vars(r)["grant"]

	grant := grants.Grant(grantString)

	userObj, err := SearchUser(r, userIdentifier)
	if err != nil && !db.IsNotFound(err) {
		log.Error("Failed to look up user identifier: ", err)
		http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
		return
	}
	if err != nil {
		// No user found for this identifier, since the user thus no longer has the grant requested
		// for removal, we can also return a 204 here
		w.WriteHeader(http.StatusNoContent)
		return
	}

	hasAuth, err := hasAuthorization(r, userObj.Username, globalid)
	if handleServerError(w, "checking if user has an authorization for the organization", err) {
		return
	}
	if !hasAuth {
		log.Debug("Refusing to delete grant for user without authorization")
		w.WriteHeader(http.StatusForbidden)
		w.Write([]byte("User does not have an authorization for this organzation"))
		return
	}

	grantMgr := grants.NewManager(r)
	err = grantMgr.DeleteUserGrant(userObj.Username, globalid, grant)
	if err != nil && !db.IsNotFound(err) {
		log.Error("Failed to delete user grant: ", err)
		http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
		return
	}

	w.WriteHeader(http.StatusNoContent)
}
843579
func (s *UserService) DeleteUser(ctx context.Context, id platform.ID) error {
	return s.DeleteUserFn(ctx, id)
}
1005675
func (c LoginClient) AccountDelete(ctx context.Context, sessionID int) (err error) {
	__arg := AccountDeleteArg{SessionID: sessionID}
	err = c.Cli.Call(ctx, "keybase.1.login.accountDelete", []interface{}{__arg}, nil)
	return
}
1088175
func AccountsDelete(c web.C, w http.ResponseWriter, r *http.Request) {
	// Get the account ID from the request
	id := c.URLParams["id"]

	// Right now we only support "me" as the ID
	if id != "me" {
		utils.JSONResponse(w, 501, &AccountsDeleteResponse{
			Success: false,
			Message: `Only the "me" user is implemented`,
		})
		return
	}

	// Fetch the current session from the database
	session := c.Env["token"].(*models.Token)

	// Fetch the user object from the database
	user, err := env.Accounts.GetAccount(session.Owner)
	if err != nil {
		utils.JSONResponse(w, 500, &AccountsDeleteResponse{
			Success: false,
			Message: "Unable to resolve the account",
		})
		return
	}

	// TODO: Delete contacts

	// TODO: Delete emails

	// TODO: Delete labels

	// TODO: Delete threads

	// Delete tokens
	err = env.Tokens.DeleteOwnedBy(user.ID)
	if err != nil {
		env.Log.WithFields(logrus.Fields{
			"id":    user.ID,
			"error": err.Error(),
		}).Error("Unable to remove account's tokens")

		utils.JSONResponse(w, 500, &AccountsDeleteResponse{
			Success: false,
			Message: "Internal error (code AC/DE/05)",
		})
		return
	}

	// Delete account
	err = env.Accounts.DeleteID(user.ID)
	if err != nil {
		env.Log.WithFields(logrus.Fields{
			"error": err.Error(),
		}).Error("Unable to delete an account")

		utils.JSONResponse(w, 500, &AccountsDeleteResponse{
			Success: false,
			Message: "Internal error (code AC/DE/06)",
		})
		return
	}

	utils.JSONResponse(w, 200, &AccountsDeleteResponse{
		Success: true,
		Message: "Your account has been successfully deleted",
	})
}
319899
func (e *Enforcer) DeleteRoleForUser(user string, role string) bool {
	return e.RemoveGroupingPolicy(user, role)
}
1223378
func (s *Service) AccountDelete(ctx context.Context) (*Account, error) {
	var account Account
	return &account, s.Delete(ctx, &account, fmt.Sprintf("/account"))
}
1272394
func (c *ChatDeleteCall) AsUser(asUser bool) *ChatDeleteCall {
	c.asUser = asUser
	return c
}
551680
func (s *Service) DeleteUserResourceMapping(ctx context.Context, resourceID influxdb.ID, userID influxdb.ID) error {
	return s.kv.Update(ctx, func(tx Tx) error {
		// TODO(goller): I don't think this find is needed as delete also finds.
		m, err := s.findUserResourceMapping(ctx, tx, influxdb.UserResourceMappingFilter{
			ResourceID: resourceID,
			UserID:     userID,
		})
		if err != nil {
			return err
		}

		filter := influxdb.UserResourceMappingFilter{
			ResourceID: resourceID,
			UserID:     userID,
		}
		if err := s.deleteUserResourceMapping(ctx, tx, filter); err != nil {
			return err
		}

		if m.ResourceType == influxdb.OrgsResourceType {
			return s.deleteOrgDependentMappings(ctx, tx, m)
		}

		return nil
	})
}
885618
func (r *Client) DeleteActualOrgUser(uid uint) (StatusMessage, error) {
	var (
		raw   []byte
		reply StatusMessage
		err   error
	)
	if raw, _, err = r.delete(fmt.Sprintf("api/org/users/%d", uid)); err != nil {
		return StatusMessage{}, err
	}
	err = json.Unmarshal(raw, &reply)
	return reply, err
}
831096
func (s *Service) DeleteUser(ctx context.Context, id platform.ID) error {
	if _, err := s.FindUserByID(ctx, id); err != nil {
		return &platform.Error{
			Err: err,
			Op:  OpPrefix + platform.OpDeleteUser,
		}
	}
	s.userKV.Delete(id.String())
	return nil
}
66187
func (s *AuthorizationService) DeleteAuthorization(ctx context.Context, id influxdb.ID) error {
	a, err := s.s.FindAuthorizationByID(ctx, id)
	if err != nil {
		return err
	}

	if err := authorizeWriteAuthorization(ctx, a.UserID); err != nil {
		return err
	}

	return s.s.DeleteAuthorization(ctx, id)
}
323066
func (s *inmem) DeleteUser(ctx context.Context, id platform.ID) error {
	return s.delete(ctx, id, getUser)
}
524815
func (st *State) RemoveUser(tag names.UserTag) error {
	name := strings.ToLower(tag.Name())

	u, err := st.User(tag)
	if err != nil {
		return errors.Trace(err)
	}
	if u.IsDeleted() {
		return nil
	}

	buildTxn := func(attempt int) ([]txn.Op, error) {
		if attempt > 0 {
			// If it is not our first attempt, refresh the user.
			if err := u.Refresh(); err != nil {
				return nil, errors.Trace(err)
			}
		}
		ops := []txn.Op{{
			Id:     name,
			C:      usersC,
			Assert: txn.DocExists,
			Update: bson.M{"$set": bson.M{"deleted": true}},
		}}
		return ops, nil
	}
	return st.db().Run(buildTxn)
}
494061
func (s *UserService) UpdateUser(ctx context.Context, id influxdb.ID, upd influxdb.UserUpdate) (*influxdb.User, error) {
	if err := authorizeWriteUser(ctx, id); err != nil {
		return nil, err
	}

	return s.s.UpdateUser(ctx, id, upd)
}
19878
func (a Authorizer) DeleteUser(username string) error {
	err := a.backend.DeleteUser(username)
	if err != nil && err != ErrDeleteNull {
		return mkerror(err.Error())
	}
	return err
}
1174694
func (s *UserService) NewDeleteUserParams(id string) *DeleteUserParams {
	p := &DeleteUserParams{}
	p.p = make(map[string]interface{})
	p.p["id"] = id
	return p
}