Example #1
0
File: pkg.go Project: wuxu92/snp
/**
 * fork a package
 */
func forkPkg(name string, newName string) (models.Pkg, error) {
	// copy package
	old, err := models.GetPkgByName(name)
	if err != nil {
		return models.Pkg{}, err
	}
	// check if newName exist
	chkPkg, _ := models.GetPkgByName(newName)
	//	fmt.Println("name:", chkPkg.Name, )
	if chkPkg.Name == newName {
		return models.Pkg{}, errors.New("pkg name already exist")
	}
	return old.Copy(newName)
}
Example #2
0
File: grp.go Project: wuxu92/snp
// delete group uri : /api/grp/delete/:id?p=password&pkg=pkgName   with delete request
// todo check password
func (this *GrpController) Delete() {
	gid := this.Ctx.Input.Param(":id")
	action := this.Ctx.Input.Param(":action")
	password := this.GetString("p")
	pkgName := this.GetString("pkg")
	data := ResObj{}

	// log request
	utils.GetConsole().Info("a: %s, grp: %s, p: %s", action, gid, password)

	pkg, err := models.GetPkgByName(pkgName)
	if err != nil {
		data.SetCode(CODE_NO_SUCH_PKG)
		this.Json(data)
		return
	}

	if !bson.IsObjectIdHex(gid) {
		data.SetCode(CODE_MGO_BAD_ID)
		this.Json(data)
		return
	}
	// todo check password
	if !pkg.CheckPassword(password) {
		data.SetCode(CODE_PASSWORD_ERR)
		this.Json(data)
		return
	}

	// do delete process
	// just remove id from pkg's grp list
	deleted := pkg.RemoveGroup(gid)
	if !deleted {
		data.SetCode(CODE_NO_SUCH_GRP)
	} else {
		data.SetCode(CODE_OK)
	}

	this.Json(data)
}