Create godoc @Security ApiKey @Summary Create new membership between org and user @Description user will be added to org with a role @Tags Member @Accept json @Produce json @Param namespace path string true "org name" @Param current_user query string fals
(ctx *gin.Context)
| 117 | // @Failure 500 {object} types.APIInternalServerError "Internal server error" |
| 118 | // @Router /organization/{namespace}/members [post] |
| 119 | func (h *MemberHandler) Create(ctx *gin.Context) { |
| 120 | type addMemberRequest struct { |
| 121 | // name of user will be added to the org as a member |
| 122 | Users string `json:"users" binding:"required" example:"user1,user2"` |
| 123 | Role string `json:"role" binding:"required"` |
| 124 | } |
| 125 | req := new(addMemberRequest) |
| 126 | if err := ctx.ShouldBindJSON(req); err != nil { |
| 127 | httpbase.BadRequest(ctx, fmt.Errorf("failed to unmarshal request body,caused by:%w", err).Error()) |
| 128 | return |
| 129 | } |
| 130 | users := strings.Split(req.Users, ",") |
| 131 | if len(users) == 0 { |
| 132 | httpbase.BadRequest(ctx, fmt.Errorf("user name is empty").Error()) |
| 133 | return |
| 134 | } |
| 135 | currentUser := httpbase.GetCurrentUser(ctx) |
| 136 | org := ctx.Param("namespace") |
| 137 | err := h.c.AddMembers(ctx, org, users, currentUser, req.Role) |
| 138 | if err != nil { |
| 139 | slog.ErrorContext(ctx, "create member fail", slog.Any("error", err), |
| 140 | slog.Group("request", |
| 141 | slog.String("org", org), slog.String("user", req.Users), slog.String("role", req.Role), slog.String("op_user", currentUser), |
| 142 | ), |
| 143 | ) |
| 144 | httpbase.ServerError(ctx, err) |
| 145 | return |
| 146 | } |
| 147 | |
| 148 | httpbase.OK(ctx, nil) |
| 149 | } |
| 150 | |
| 151 | // Delete godoc |
| 152 | // @Security ApiKey |
nothing calls this directly
no test coverage detected