MCPcopy Create free account
hub / github.com/PostHog/duckgres / deleteOperator

Method deleteOperator

controlplane/admin/operators_api.go:119–158  ·  view source on GitHub ↗
(c *gin.Context)

Source from the content-addressed store, hash-verified

117 if id := IdentityFromContext(c); id != nil {
118 addedBy = id.Email
119 }
120 if err := h.store.UpsertOperator(email, role, addedBy); err != nil {
121 if errors.Is(err, configstore.ErrInvalidOperatorRole) {
122 c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
123 return
124 }
125 c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
126 return
127 }
128 c.JSON(http.StatusOK, configstore.Operator{Email: email, Role: role, AddedBy: addedBy})
129}
130
131func (h *operatorsHandler) deleteOperator(c *gin.Context) {
132 email := strings.ToLower(strings.TrimSpace(c.Param("email")))
133 if email == "" {
134 c.JSON(http.StatusBadRequest, gin.H{"error": "email is required"})
135 return
136 }
137
138 // Last-admin guard: refuse to delete the final remaining admin (see the
139 // upsert guard for the pre-check + op rationale).
140 role, err := h.store.OperatorRole(email)
141 if err != nil {
142 c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
143 return
144 }
145 if role == string(RoleAdmin) {
146 admins, err := h.store.CountAdmins()
147 if err != nil {
148 c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
149 return
150 }
151 if admins <= 1 {
152 c.JSON(http.StatusConflict, gin.H{"error": "cannot remove the last remaining admin"})
153 return
154 }
155 }
156 if role != "" {
157 setAuditDetail(c, "removed "+role+" operator")
158 }
159
160 deleted, err := h.store.DeleteOperator(email)
161 if err != nil {

Callers 1

useDeleteOperatorFunction · 0.80

Calls 5

setAuditDetailFunction · 0.85
OperatorRoleMethod · 0.80
CountAdminsMethod · 0.80
DeleteOperatorMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected