func deleteIssueLabel(e *xorm.Session, issue *Issue, label *Label) (err error) { if _, err = e.Delete(&IssueLabel{ IssueID: issue.ID, LabelID: label.ID, }); err != nil { return err } label.NumIssues-- if issue.IsClosed { label.NumClosedIssues-- } return updateLabel(e, label) }
func SaveDeposit(ss []entity.Deposit, session *xorm.Session) error { _, err := session.Delete(&entity.Deposit{Year: ss[0].Year, Month: ss[0].Month}) if err != nil { return err } for _, s := range ss { _, err = session.Insert(&s) if err != nil { return err } } if err != nil { return err } return nil }
func SaveRoom(ks []entity.Room, session *xorm.Session) error { _, err := session.Delete(&entity.Room{Year: ks[0].Year, Month: ks[0].Month}) if err != nil { return err } for _, k := range ks { _, err = session.Insert(&k) if err != nil { return err } } if err != nil { return err } return nil }
func SaveExpense(ps []entity.Expense, session *xorm.Session) error { _, err := session.Delete(&entity.Expense{Year: ps[0].Year, Month: ps[0].Month}) if err != nil { return err } for _, p := range ps { _, err = session.Insert(&p) if err != nil { return err } } if err != nil { return err } return nil }
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 }