Enhance Discord role management by adding hoist functionality
This commit introduces a new `hoist` attribute for Discord roles, allowing team roles and the registered role to be displayed in separate groups within the Discord member list. The `RoleWorker` has been updated to ensure team roles are positioned above the registered role, improving visibility and organization. Database schema changes have been made to support the new `hoist` field, and corresponding updates have been implemented in the service layer and tests to validate the new behavior.
This commit is contained in:
@@ -78,7 +78,7 @@ func (s *Store) RetryDiscordRoleSyncJob(ctx context.Context, jobID int64, messag
|
||||
}
|
||||
|
||||
func (s *Store) ListDiscordManagedRoles(ctx context.Context, eventID string) ([]application.DiscordManagedRole, error) {
|
||||
rows, err := s.pool.Query(ctx, `SELECT scope,event_id,team_id,kind,discord_role_id,role_name
|
||||
rows, err := s.pool.Query(ctx, `SELECT scope,event_id,team_id,kind,discord_role_id,role_name,hoist
|
||||
FROM discord_managed_roles
|
||||
WHERE scope='global' OR event_id=$1
|
||||
ORDER BY scope,event_id,team_id,kind`, eventID)
|
||||
@@ -89,7 +89,7 @@ func (s *Store) ListDiscordManagedRoles(ctx context.Context, eventID string) ([]
|
||||
roles := make([]application.DiscordManagedRole, 0)
|
||||
for rows.Next() {
|
||||
var role application.DiscordManagedRole
|
||||
if err = rows.Scan(&role.Scope, &role.EventID, &role.TeamID, &role.Kind, &role.DiscordRoleID, &role.RoleName); err != nil {
|
||||
if err = rows.Scan(&role.Scope, &role.EventID, &role.TeamID, &role.Kind, &role.DiscordRoleID, &role.RoleName, &role.Hoist); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
roles = append(roles, role)
|
||||
@@ -98,11 +98,11 @@ func (s *Store) ListDiscordManagedRoles(ctx context.Context, eventID string) ([]
|
||||
}
|
||||
|
||||
func (s *Store) UpsertDiscordManagedRole(ctx context.Context, role application.DiscordManagedRole) error {
|
||||
_, err := s.pool.Exec(ctx, `INSERT INTO discord_managed_roles(scope,event_id,team_id,kind,discord_role_id,role_name)
|
||||
VALUES($1,$2,$3,$4,$5,$6)
|
||||
_, err := s.pool.Exec(ctx, `INSERT INTO discord_managed_roles(scope,event_id,team_id,kind,discord_role_id,role_name,hoist)
|
||||
VALUES($1,$2,$3,$4,$5,$6,$7)
|
||||
ON CONFLICT(scope,event_id,team_id,kind) DO UPDATE
|
||||
SET discord_role_id=excluded.discord_role_id,role_name=excluded.role_name,updated_at=now()`,
|
||||
role.Scope, role.EventID, role.TeamID, role.Kind, role.DiscordRoleID, role.RoleName)
|
||||
SET discord_role_id=excluded.discord_role_id,role_name=excluded.role_name,hoist=excluded.hoist,updated_at=now()`,
|
||||
role.Scope, role.EventID, role.TeamID, role.Kind, role.DiscordRoleID, role.RoleName, role.Hoist)
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user