Пример #1
0
// update authority
func (self *AuthorityResource) Put(ctx *rfweb.Context) {
	res := RespData{}
	authority, err := getAuthorityFromBody(ctx.R)
	if err != nil {
		res.Error = err.Error()
	} else {
		err = auth.UpdateAuthority(authority.Id, authority)
		if err != nil {
			res.Error = err.Error()
		} else {
			res.Data = authority
			res.Success = true
			// proxy.RemoveBackendConfCache()
		}
	}
	util.WriteJson(ctx.W, res)
}
Пример #2
0
func setAdmin(email string, level int) error {
	if level != 50 && level != 99 {
		return fmt.Errorf("adminlevel must be 50 or 99")
	}
	authority, err := auth.GetAuthorityByEmail(email)
	if err != nil {
		return fmt.Errorf("query Authority for %s got error: %s",
			email, err.Error())
	}
	if authority != nil {
		authority.AdminLevel = level
		err = auth.UpdateAuthority(authority.Id, authority)
	} else {
		authority = &auth.Authority{}
		authority.Email = email
		authority.AdminLevel = level
		err = auth.InsertAuthority(authority)
	}
	return err
}