Esempio n. 1
0
// https://github.com/gigforks/go-gogs-client/wiki/Administration-Users#create-a-new-user
func CreateUser(ctx *context.APIContext, form api.CreateUserOption) {
	u := &models.User{
		Name:      form.Username,
		Email:     form.Email,
		Passwd:    form.Password,
		IsActive:  true,
		LoginType: models.LOGIN_PLAIN,
	}

	parseLoginSource(ctx, u, form.SourceID, form.LoginName)
	if ctx.Written() {
		return
	}

	if err := models.CreateUser(u); err != nil {
		if models.IsErrUserAlreadyExist(err) ||
			models.IsErrEmailAlreadyUsed(err) ||
			models.IsErrNameReserved(err) ||
			models.IsErrNamePatternNotAllowed(err) {
			ctx.Error(422, "", err)
		} else {
			ctx.Error(500, "CreateUser", err)
		}
		return
	}
	log.Trace("Account created by admin (%s): %s", ctx.User.Name, u.Name)

	// Send e-mail notification.
	if form.SendNotify && setting.MailService != nil {
		mailer.SendRegisterNotifyMail(ctx.Context.Context, u)
	}

	ctx.JSON(201, convert.ToUser(u))
}
Esempio n. 2
0
File: org.go Progetto: gigforks/gogs
// https://github.com/gigforks/go-gogs-client/wiki/Administration-Organizations#create-a-new-organization
func CreateOrg(ctx *context.APIContext, form api.CreateOrgOption) {
	u := user.GetUserByParams(ctx)
	if ctx.Written() {
		return
	}

	org := &models.User{
		Name:        form.UserName,
		FullName:    form.FullName,
		Description: form.Description,
		Website:     form.Website,
		Location:    form.Location,
		IsActive:    true,
		Type:        models.USER_TYPE_ORGANIZATION,
	}
	if err := models.CreateOrganization(org, u); err != nil {
		if models.IsErrUserAlreadyExist(err) ||
			models.IsErrNameReserved(err) ||
			models.IsErrNamePatternNotAllowed(err) {
			ctx.Error(422, "", err)
		} else {
			ctx.Error(500, "CreateOrganization", err)
		}
		return
	}

	ctx.JSON(201, convert.ToOrganization(org))
}
Esempio n. 3
0
// https://github.com/gigforks/go-gogs-client/wiki/Users-Followers#list-users-followed-by-another-user
func ListFollowing(ctx *context.APIContext) {
	u := GetUserByParams(ctx)
	if ctx.Written() {
		return
	}
	listUserFollowing(ctx, u)
}
Esempio n. 4
0
// https://github.com/gigforks/go-gogs-client/wiki/Users-Followers#check-if-you-are-following-a-user
func CheckMyFollowing(ctx *context.APIContext) {
	target := GetUserByParams(ctx)
	if ctx.Written() {
		return
	}
	checkUserFollowing(ctx, ctx.User, target.Id)
}
Esempio n. 5
0
func RemoveUserAccess(ctx *context.APIContext) {
	owner, repo := parseOwnerAndRepo(ctx)

	if ctx.Written() {
		return
	}

	repo.Owner = owner

	u, err := models.GetUserByName(ctx.Params(":user"))

	if err != nil {
		ctx.Error(404, "user does not exist", err)
		return
	}

	err = repo.DeleteCollaboration(u.Id)

	if err != nil {
		ctx.Error(500, "delete collab", err)
		return
	}

	ctx.Status(204)

}
Esempio n. 6
0
File: org.go Progetto: gigforks/gogs
// https://github.com/gigforks/go-gogs-client/wiki/Organizations#list-user-organizations
func ListUserOrgs(ctx *context.APIContext) {
	u := user.GetUserByParams(ctx)
	if ctx.Written() {
		return
	}
	listUserOrgs(ctx, u, false)
}
Esempio n. 7
0
// https://github.com/gigforks/go-gogs-client/wiki/Administration-Users#create-a-public-key-for-user
func CreatePublicKey(ctx *context.APIContext, form api.CreateKeyOption) {
	u := user.GetUserByParams(ctx)
	if ctx.Written() {
		return
	}
	user.CreateUserPublicKey(ctx, form, u.Id)
}
Esempio n. 8
0
File: key.go Progetto: gigforks/gogs
// https://github.com/gigforks/go-gogs-client/wiki/Users-Public-Keys#list-public-keys-for-a-user
func ListPublicKeys(ctx *context.APIContext) {
	user := GetUserByParams(ctx)
	if ctx.Written() {
		return
	}
	listPublicKeys(ctx, user.Id)
}
Esempio n. 9
0
// https://github.com/gigforks/go-gogs-client/wiki/Repositories#get
func Get(ctx *context.APIContext) {
	owner, repo := parseOwnerAndRepo(ctx)
	if ctx.Written() {
		return
	}

	ctx.JSON(200, convert.ToRepository(owner, repo, api.Permission{true, true, true}))
}
Esempio n. 10
0
// https://github.com/gigforks/go-gogs-client/wiki/Administration-Repositories#create-a-new-repository
func CreateRepo(ctx *context.APIContext, form api.CreateRepoOption) {
	owner := user.GetUserByParams(ctx)
	if ctx.Written() {
		return
	}

	repo.CreateUserRepo(ctx, owner, form)
}
Esempio n. 11
0
// https://github.com/gigforks/go-gogs-client/wiki/Users-Followers#follow-a-user
func Follow(ctx *context.APIContext) {
	target := GetUserByParams(ctx)
	if ctx.Written() {
		return
	}
	if err := models.FollowUser(ctx.User.Id, target.Id); err != nil {
		ctx.Error(500, "FollowUser", err)
		return
	}
	ctx.Status(204)
}
Esempio n. 12
0
// https://github.com/gigforks/go-gogs-client/wiki/Users-Followers#check-if-one-user-follows-another
func CheckFollowing(ctx *context.APIContext) {
	u := GetUserByParams(ctx)
	if ctx.Written() {
		return
	}
	target := GetUserByParamsName(ctx, ":target")
	if ctx.Written() {
		return
	}
	checkUserFollowing(ctx, u, target.Id)
}
Esempio n. 13
0
func AddTeamMember(ctx *context.APIContext) {
	u := user.GetUserByParams(ctx)
	if ctx.Written() {
		return
	}
	if err := ctx.Org.Team.AddMember(u.Id); err != nil {
		ctx.Error(500, "AddMember", err)
		return
	}

	ctx.Status(204)
}
Esempio n. 14
0
func RemoveTeamRepository(ctx *context.APIContext) {
	repo := GetRepositoryByParams(ctx)
	if ctx.Written() {
		return
	}
	if err := ctx.Org.Team.RemoveRepository(repo.ID); err != nil {
		ctx.Error(500, "RemoveRepository", err)
		return
	}

	ctx.Status(204)
}
Esempio n. 15
0
File: org.go Progetto: gigforks/gogs
func DeleteOrg(ctx *context.APIContext) {
	org := user.GetUserByParamsName(ctx, ":orgname")

	if ctx.Written() {
		return
	}

	err := models.DeleteOrganization(org)

	if err != nil {
		ctx.Error(500, "", err)
	}
	ctx.Status(204)
}
Esempio n. 16
0
// https://github.com/gigforks/go-gogs-client/wiki/Administration-Users#edit-an-existing-user
func EditUser(ctx *context.APIContext, form api.EditUserOption) {
	u := user.GetUserByParams(ctx)
	if ctx.Written() {
		return
	}

	parseLoginSource(ctx, u, form.SourceID, form.LoginName)
	if ctx.Written() {
		return
	}

	if len(form.Password) > 0 {
		u.Passwd = form.Password
		u.Salt = models.GetUserSalt()
		u.EncodePasswd()
	}

	u.LoginName = form.LoginName
	u.FullName = form.FullName
	u.Email = form.Email
	u.Website = form.Website
	u.Location = form.Location
	if form.Active != nil {
		u.IsActive = *form.Active
	}
	if form.Admin != nil {
		u.IsAdmin = *form.Admin
	}
	if form.AllowGitHook != nil {
		u.AllowGitHook = *form.AllowGitHook
	}
	if form.AllowImportLocal != nil {
		u.AllowImportLocal = *form.AllowImportLocal
	}

	if err := models.UpdateUser(u); err != nil {
		if models.IsErrEmailAlreadyUsed(err) {
			ctx.Error(422, "", err)
		} else {
			ctx.Error(500, "UpdateUser", err)
		}
		return
	}
	log.Trace("Account profile updated by admin (%s): %s", ctx.User.Name, u.Name)

	ctx.JSON(200, convert.ToUser(u))
}
Esempio n. 17
0
func AddOrganizationUser(ctx *context.APIContext, form api.AddUserOption) {
	u, err := models.GetUserByName(form.UserName)

	if err != nil {
		ctx.Error(404, "user does not exist", err)
		return
	}

	org := user.GetUserByParamsName(ctx, ":orgname")
	err = models.AddOrgUser(org.Id, u.Id)

	if ctx.Written() {
		return
	}
	if err != nil {
		ctx.Error(500, "", err)
	}
	ctx.Status(201)
}
Esempio n. 18
0
// https://github.com/gigforks/go-gogs-client/wiki/Repositories#delete
func Delete(ctx *context.APIContext) {
	owner, repo := parseOwnerAndRepo(ctx)
	if ctx.Written() {
		return
	}

	if owner.IsOrganization() && !owner.IsOwnedBy(ctx.User.Id) {
		ctx.Error(403, "", "Given user is not owner of organization.")
		return
	}

	if err := models.DeleteRepository(owner.Id, repo.ID); err != nil {
		ctx.Error(500, "DeleteRepository", err)
		return
	}

	log.Trace("Repository deleted: %s/%s", owner.Name, repo.Name)
	ctx.Status(204)
}
Esempio n. 19
0
// https://github.com/gigforks/go-gogs-client/wiki/Administration-Users#delete-a-user
func DeleteUser(ctx *context.APIContext) {
	u := user.GetUserByParams(ctx)
	if ctx.Written() {
		return
	}

	if err := models.DeleteUser(u); err != nil {
		if models.IsErrUserOwnRepos(err) ||
			models.IsErrUserHasOrgs(err) {
			ctx.Error(422, "", err)
		} else {
			ctx.Error(500, "DeleteUser", err)
		}
		return
	}
	log.Trace("Account deleted by admin(%s): %s", ctx.User.Name, u.Name)

	ctx.Status(204)
}
Esempio n. 20
0
func ListUserAccess(ctx *context.APIContext) {
	_, repo := parseOwnerAndRepo(ctx)
	if ctx.Written() {
		return
	}

	users, err := repo.GetCollaborators()

	if err != nil {
		ctx.Error(500, "internal server error", err)
		return
	}

	apiUsers := make([]*api.User, 0)

	for _, u := range users {
		apiUsers = append(apiUsers, convert.ToUser(u.User))
	}

	ctx.JSON(200, apiUsers)
}
Esempio n. 21
0
func RemoveOrganizationUser(ctx *context.APIContext) {

	u := user.GetUserByParamsName(ctx, ":user")

	if ctx.Written() {
		return
	}

	org := user.GetUserByParamsName(ctx, ":orgname")

	if ctx.Written() {
		return
	}

	err := models.RemoveOrgUser(org.Id, u.Id)

	if err != nil {
		ctx.Error(500, "", err)
	}
	ctx.Status(204)
}
Esempio n. 22
0
func GiveUserAccess(ctx *context.APIContext, form auth.CreateAccessOption) {
	user, repo := parseOwnerAndRepo(ctx)

	repo.Owner = user
	if ctx.Written() {
		return
	}

	u, err := models.GetUserByName(form.Username)
	// fmt.Println("this is the user ::::::%v", u)
	if err != nil {
		ctx.Error(404, "user does not exist", err)
		return
	}
	err = repo.AddCollaborator(u)

	if err != nil {
		ctx.Error(500, "Add Collaberator", err)
		return
	}

	ListUserAccess(ctx)

}