MCPcopy Create free account
hub / github.com/OpenCSGs/csghub-server / Create

Method Create

user/handler/member.go:119–149  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

117// @Failure 500 {object} types.APIInternalServerError "Internal server error"
118// @Router /organization/{namespace}/members [post]
119func (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

Callers

nothing calls this directly

Calls 6

BadRequestFunction · 0.92
GetCurrentUserFunction · 0.92
ServerErrorFunction · 0.92
OKFunction · 0.92
ErrorMethod · 0.80
AddMembersMethod · 0.80

Tested by

no test coverage detected