Exemplo n.º 1
0
func (app *App) GetMaxRevisionByBundleVersion(txn gorp.SqlExecutor, bundleVersion string) (int, error) {
	revision, err := txn.SelectInt(
		"SELECT IFNULL(MAX(revision), 0) FROM bundle WHERE app_id = ? AND bundle_version = ?",
		app.Id,
		bundleVersion,
	)
	return int(revision), err
}
// intercepts more than two requests to ignore list add.
func MoreThanTwoRequestByIp(db gorp.SqlExecutor, entity *models.Ignore_List) bool {

	sql := SQL_COUNT_MULTIPLE_IGNOREME_REQUESTS

	total, err := db.SelectInt(sql, entity.Ip)
	checkErr(err, "COUNT ERROR")

	return total >= 2

}
Exemplo n.º 3
0
func (app *App) HasAuthorityForEmail(txn gorp.SqlExecutor, email string) (bool, error) {
	count, err := txn.SelectInt("SELECT COUNT(id) FROM authority WHERE app_id = ? AND email = ?", app.Id, email)
	if err != nil {
		return false, err
	}
	if count > 0 {
		return true, nil
	}
	return false, nil
}
Exemplo n.º 4
0
func IsExistAuthorityForEmail(txn gorp.SqlExecutor, email string) (bool, error) {
	count, err := txn.SelectInt("SELECT COUNT(id) FROM authority WHERE email = ?", email)
	if err != nil {
		return false, err
	}
	if count > 0 {
		return true, nil
	}
	return false, nil
}
Exemplo n.º 5
0
func isWarnSentLimitByIpOver(warning *models.Warning, db gorp.SqlExecutor) bool {

	exists, err := db.SelectInt(BuildCountWarningsSql("ip"), map[string]interface{}{
		"id_contact_type": warning.Id_contact_type,
		"sent":            true,
		"interval":        24,
		"ip":              warning.Ip,
	})
	checkErr(err, "SELECT isWarnSentLimitByIpOver ERROR")

	return exists > 3
}
Exemplo n.º 6
0
// count warnings according to the param sent(true or false) and the specific type of contact
func countWarnings(sent bool, db gorp.SqlExecutor) (string, error) {

	total, err := db.SelectInt(SQL_WARNING_COUNT, map[string]interface{}{
		"sent": sent,
	})
	checkErr(err, "COUNT SENT WARNINGS ERROR")

	if err != nil {
		return "", err
	}

	return strconv.FormatInt(total, 10), nil
}
Exemplo n.º 7
0
// return true if a warn, with same message and different ip, attempts to be sent more than twice, if so respond back to interface denying the service;
func isSameWarnSentTwiceOrMoreDifferentIp(warning *models.Warning, db gorp.SqlExecutor) bool {
	fmt.Println("isSameWarnSentTwiceOrMoreDifferentIp")

	exists, err := db.SelectInt(BuildCountWarningsSql("same_message"), map[string]interface{}{
		"sent":       true,
		"contact":    warning.Contact,
		"interval":   2,
		"id_message": warning.Id_message,
		"ip":         warning.Ip,
	})
	checkErr(err, "SELECT isSameWarnSentTwiceOrMoreDifferentIp ERROR")

	return exists >= 2
}
Exemplo n.º 8
0
Arquivo: client.go Projeto: Aaah/erosd
func (this *ClientRegionStats) UpdateDivisionRank(ex gorp.SqlExecutor) error {
	this.DivisionRank = 0

	if this.DivisionId != nil {
		if *this.DivisionId > 0 {
			result, err := ex.SelectInt("SELECT COUNT(*) from client_region_stats WHERE division_id=? AND region=? AND ladder_points > (SELECT ladder_points FROM client_region_stats WHERE client_id=? AND region=?);", *this.DivisionId, this.Region, *this.ClientId, this.Region)
			if err != nil {
				log.Println(err)
				return nil
			}

			this.DivisionRank = result + 1 //Zero indexed.
		}
	}

	return nil
}
Exemplo n.º 9
0
func (app *App) BundlesWithPager(txn gorp.SqlExecutor, page, limit int) (Bundles, int, error) {
	if page < 1 {
		page = 1
	}

	count, err := txn.SelectInt("SELECT COUNT(*) FROM bundle WHERE app_id = ?", app.Id)
	if err != nil {
		return nil, 0, err
	}

	offset := (page - 1) * limit
	if int(count) <= offset {
		// 空であることが明らかなのでそのまま返す
		return Bundles([]*Bundle{}), int(count), nil
	}

	var bundles []*Bundle
	_, err = txn.Select(&bundles, "SELECT * FROM bundle WHERE app_id = ? ORDER BY id DESC LIMIT ? OFFSET ?", app.Id, limit, offset)
	if err != nil {
		return nil, 0, err
	}

	return Bundles(bundles), int(count), nil
}