Manage teams and team members within Gitea organizations
Teams are groups of organization members with specific access permissions to repositories. Teams provide fine-grained control over who can read, write, or administer repositories within an organization.
// NewTeam creates a record of new team.func NewTeam(ctx context.Context, t *organization.Team) (err error) { if len(t.Name) == 0 { return util.NewInvalidArgumentErrorf("empty team name") } if err = organization.IsUsableTeamName(t.Name); err != nil { return err } t.LowerName = strings.ToLower(t.Name) has, err := db.Exist[organization.Team](ctx, builder.Eq{ "org_id": t.OrgID, "lower_name": t.LowerName, }) if err != nil { return err } if has { return organization.ErrTeamAlreadyExist{OrgID: t.OrgID, Name: t.LowerName} } return db.WithTx(ctx, func(ctx context.Context) error { if err = db.Insert(ctx, t); err != nil { return err } // insert units for team if len(t.Units) > 0 { for _, unit := range t.Units { unit.TeamID = t.ID } if err = db.Insert(ctx, &t.Units); err != nil { return err } } // Add all repositories to the team if it has access to all of them if t.IncludesAllRepositories { err = repo_service.AddAllRepositoriesToTeam(ctx, t) if err != nil { return fmt.Errorf("addAllRepositories: %w", err) } } // Update organization number of teams _, err = db.Exec(ctx, "UPDATE `user` SET num_teams=num_teams+1 WHERE id = ?", t.OrgID) return err })}
Enable IncludesAllRepositories to automatically grant the team access to all current and future repositories:
type Team struct { ID int64 `xorm:"pk autoincr"` OrgID int64 `xorm:"INDEX"` Name string Description string AccessMode perm.AccessMode `xorm:"'authorize'"` Members []*user_model.User `xorm:"-"` NumRepos int NumMembers int Units []*TeamUnit `xorm:"-"` IncludesAllRepositories bool `xorm:"NOT NULL DEFAULT false"` CanCreateOrgRepo bool `xorm:"NOT NULL DEFAULT false"`}
// AddTeamMember adds new membership of given team to given organization,// the user will have membership to given organization automatically when needed.func AddTeamMember(ctx context.Context, team *organization.Team, user *user_model.User) error { if user_model.IsUserBlockedBy(ctx, user, team.OrgID) { return user_model.ErrBlockedUser } isAlreadyMember, err := organization.IsTeamMember(ctx, team.OrgID, team.ID, user.ID) if err != nil || isAlreadyMember { return err } // Add user to organization if not already a member if err := organization.AddOrgUser(ctx, team.OrgID, user.ID); err != nil { return err } return db.WithTx(ctx, func(ctx context.Context) error { sess := db.GetEngine(ctx) if err := db.Insert(ctx, &organization.TeamUser{ UID: user.ID, OrgID: team.OrgID, TeamID: team.ID, }); err != nil { return err } _, err := sess.Incr("num_members").ID(team.ID).Update(new(organization.Team)) return err })}
Yes, users can be members of multiple teams within the same organization. Their effective permissions for a repository are the highest permission granted by any team they belong to.
What happens when team permissions conflict?
Users always receive the highest permission level granted by any team they belong to. For example, if a user is in Team A (read access) and Team B (write access), they will have write access.
Can teams have different permissions for different repositories?
Yes, when a team has access to multiple specific repositories, the same unit-level permissions apply to all of them. To have different permissions for different repositories, create separate teams.
What is the 'Can Create Org Repo' permission?
This permission allows team members to create new repositories within the organization. By default, only owners can create repositories, but you can grant this to other teams.
Can I rename a team?
Yes, organization owners can rename teams at any time. The team’s permissions and members remain unchanged.
What's the difference between Admin and Owner?
Admin teams have administrative access to repositories but cannot manage the organization itself
Owner teams (specifically the Owners team) can manage all organization settings, teams, and members