예제 #1
0
파일: handler.go 프로젝트: TritonHo/meow
func updateRecordWithUserId(input interface{}, fieldNames map[string]bool, id, userId string, session *xorm.Session) (statusCode int, err error) {
	if _, err := uuid.FromString(id); err != nil {
		return http.StatusBadRequest, errUuidNotValid
	}
	if _, err := uuid.FromString(userId); err != nil {
		return http.StatusBadRequest, errUuidNotValid
	}

	//convert the fields set to array
	array := []string{}
	for k, _ := range fieldNames {
		array = append(array, k)
	}

	//update the database
	affected, err := session.Where("id = ? and user_id = ?", id, userId).Cols(array...).Update(input)
	if err != nil {
		return http.StatusInternalServerError, err
	}
	if affected == 0 {
		return http.StatusNotFound, errors.New("The record is not found.")
	}

	return http.StatusNoContent, nil
}
func (this *PuzzleActivityComponentDbModel) SetStateForTrans(sess *xorm.Session, componentId int, state int) {
	data := ContentPuzzleActivityComponent{
		State: state,
	}
	_, err := sess.Where("contentPuzzleActivityComponentId=?", componentId).Update(&data)
	if err != nil {
		panic(err)
	}
}
예제 #3
0
func GetAlertsByDashboardId2(dashboardId int64, sess *xorm.Session) ([]*m.Alert, error) {
	alerts := make([]*m.Alert, 0)
	err := sess.Where("dashboard_id = ?", dashboardId).Find(&alerts)

	if err != nil {
		return []*m.Alert{}, err
	}

	return alerts, nil
}
예제 #4
0
파일: alert.go 프로젝트: wk66/grafana
func DeleteAlertDefinition(dashboardId int64, sess *xorm.Session) error {
	alerts := make([]*m.Alert, 0)
	sess.Where("dashboard_id = ?", dashboardId).Find(&alerts)

	for _, alert := range alerts {
		deleteAlertByIdInternal(alert.Id, "Dashboard deleted", sess)
	}

	return nil
}
예제 #5
0
func DeleteAlertDefinition(dashboardId int64, sess *xorm.Session) error {
	alerts := make([]*m.Alert, 0)
	sess.Where("dashboard_id = ?", dashboardId).Find(&alerts)

	for _, alert := range alerts {
		_, err := sess.Exec("DELETE FROM alert WHERE id = ? ", alert.Id)
		if err != nil {
			return err
		}

		sqlog.Debug("Alert deleted (due to dashboard deletion)", "name", alert.Name, "id", alert.Id)
	}

	return nil
}
예제 #6
0
파일: handler.go 프로젝트: TritonHo/meow
func deleteRecordWithUserId(input interface{}, id, userId string, session *xorm.Session) (statusCode int, err error) {
	if _, err := uuid.FromString(id); err != nil {
		return http.StatusBadRequest, errUuidNotValid
	}
	if _, err := uuid.FromString(userId); err != nil {
		return http.StatusBadRequest, errUuidNotValid
	}
	affectedCount, err := session.Where("id = ? and user_id = ?", id, userId).Delete(input)

	if err != nil {
		return http.StatusInternalServerError, err
	}
	if affectedCount == 0 {
		return http.StatusNotFound, errors.New("The record is not found.")
	}

	return http.StatusNoContent, err
}
예제 #7
0
파일: org.go 프로젝트: felipelovato/gogs
func removeTeamMemberWithSess(orgId, teamId, uid int64, sess *xorm.Session) error {
	if !IsTeamMember(orgId, teamId, uid) {
		return nil
	}

	// Get team and its repositories.
	t, err := GetTeamById(teamId)
	if err != nil {
		return err
	}

	// Check if the user to delete is the last member in owner team.
	if t.IsOwnerTeam() && t.NumMembers == 1 {
		return ErrLastOrgOwner
	}

	t.NumMembers--

	if err = t.GetRepositories(); err != nil {
		return err
	}

	// Get organization.
	org, err := GetUserById(orgId)
	if err != nil {
		return err
	}

	// Get user.
	u, err := GetUserById(uid)
	if err != nil {
		return err
	}

	tu := &TeamUser{
		Uid:    uid,
		OrgId:  orgId,
		TeamId: teamId,
	}

	if _, err := sess.Delete(tu); err != nil {
		sess.Rollback()
		return err
	} else if _, err = sess.Id(t.Id).AllCols().Update(t); err != nil {
		sess.Rollback()
		return err
	}

	// Delete access to team repositories.
	for _, repo := range t.Repos {
		auth, err := GetHighestAuthorize(t.OrgId, u.Id, repo.Id, teamId)
		if err != nil {
			sess.Rollback()
			return err
		}

		access := &Access{
			UserName: u.LowerName,
			RepoName: path.Join(org.LowerName, repo.LowerName),
		}
		// Delete access if this is the last team user belongs to.
		if auth == 0 {
			if _, err = sess.Delete(access); err != nil {
				sess.Rollback()
				return fmt.Errorf("fail to delete access: %v", err)
			} else if err = WatchRepo(u.Id, repo.Id, false); err != nil {
				sess.Rollback()
				return err
			}
		} else if auth < t.Authorize {
			// Downgrade authorize level.
			if err = addAccessWithAuthorize(sess, access, AuthorizeToAccessType(auth)); err != nil {
				sess.Rollback()
				return err
			}
		}
	}

	// This must exist.
	ou := new(OrgUser)
	_, err = sess.Where("uid=?", uid).And("org_id=?", org.Id).Get(ou)
	if err != nil {
		sess.Rollback()
		return err
	}
	ou.NumTeams--
	if t.IsOwnerTeam() {
		ou.IsOwner = false
	}
	if _, err = sess.Id(ou.Id).AllCols().Update(ou); err != nil {
		sess.Rollback()
		return err
	}
	return nil
}
예제 #8
0
파일: org.go 프로젝트: nafrente/gogs
func getOwnedOrgsByUserID(sess *xorm.Session, userID int64) ([]*User, error) {
	orgs := make([]*User, 0, 10)
	return orgs, sess.Where("`org_user`.uid=?", userID).And("`org_user`.is_owner=?", true).
		Join("INNER", "`org_user`", "`org_user`.org_id=`user`.id").Find(&orgs)
}