Skip to content

feat(backend): let an account be edited instead of deleted and recreated (#100) - #105

Merged
matbrgz merged 1 commit into
masterfrom
feat/100-edit-user
Sep 13, 2026
Merged

matbrgz merged 1 commit into
masterfrom
feat/100-edit-user

Conversation

@matbrgz

@matbrgz matbrgz commented Sep 13, 2026

Copy link
Copy Markdown
Member

Fecha a #100.

O UserController tinha index(), store() e destroy() e nada entre eles. Qualquer erro num cadastro só se corrigia apagando a conta — o que arrasta runs, scores, tarefas e logs por cascadeOnDelete, sem desfazer. Nome, e-mail, usuário, tipo, sede, is_enabled e icpc_id eram todos incorrigíveis depois de salvos.

O último era concreto: a #92 adicionou o icpc_id ao formulário de criação, então conta que já existia não tinha como receber o dela — e é exatamente a coluna que o contest:icpc-report precisa preenchida em todas as equipes. O comando lista quem está sem justamente para o organizador preencher, e não havia onde.

O que muda

Editar mantém a linha, então tudo que aponta para ela sobrevive. Senha em branco significa "deixa como está", não "põe senha vazia". A competição acompanha a sede escolhida, igual na criação.

Duas guardas, no editar e no excluir

Porque não existe uma segunda tela para desfazer nenhum dos dois:

  • Você não pode desabilitar nem excluir a própria conta.
  • O último admin não pode ser rebaixado nem excluído.

O destroy() não tinha guarda nenhuma antes disto: apagar o único administrador estava a um diálogo de confirmação de distância.

Um bug que apareceu no caminho

icpc_id nunca esteve no $fillable do User. Existe desde 2025_11_25_000007 e um update() do Eloquent o descartava em silêncio. O caminho de criação escreve pelo query builder, que é por isso que a #92 funcionou e a edição não funcionaria.

Testes

13, incluindo os dois erros que passariam por uma revisão desatenta: salvar um usuário sem mudar o nome de usuário não pode colidir com o próprio registro, e o nome de usuário de outra conta continua recusado.

Suíte: 788 verdes.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Pvf2R8xtgbWQm1wRvjBqQY

…ted (#100)

Closes #100.

UserController had index(), store() and destroy() and nothing in between.
Any mistake in a registration could only be fixed by deleting the account
-- which cascades to its runs, scores, tasks and logs, with no undo. Name,
email, username, user_type, site, is_enabled and icpc_id were all
uncorrectable once saved.

The last one was concrete: #92 added icpc_id to the create form, so an
account that already existed had no way to receive one, and that is the
exact column contest:icpc-report needs filled on every team. The command
lists who is missing it precisely so an organiser can fill them in, and
there was nowhere to do it.

Editing keeps the row, so everything pointing at it survives. A blank
password means "leave it alone" rather than "set an empty password", and
the contest follows the chosen site exactly as it does on create.

Two guards, on both edit and delete, because there is no second screen to
undo either from:

  - You cannot disable or delete your own account.
  - The last admin cannot be demoted or deleted. destroy() had no guard at
    all before this: deleting the only admin was one confirm dialog away.

Also makes icpc_id fillable on the User model. It has existed since
2025_11_25_000007 and was never in $fillable, so an Eloquent update
dropped it silently -- the create path writes through the query builder,
which is why #92 worked and this did not until now.

Thirteen tests, including the two mistakes that would otherwise pass
review: saving a user without changing their username must not collide
with their own record, and another account's username must still be
refused.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01Pvf2R8xtgbWQm1wRvjBqQY
@matbrgz
matbrgz merged commit eba4107 into master Sep 13, 2026
3 checks passed
@matbrgz
matbrgz deleted the feat/100-edit-user branch September 13, 2026 19:54
matbrgz added a commit that referenced this pull request Sep 13, 2026
…ads (#99) (#111)

Closes #99.

/backend/teams sat in the main admin sidebar and read `DB::table('teams')`,
the Helium table from 2017 -- team_id, teamName, score. The contest's
actual teams are rows in `users` with user_type='team', which is what
SubmitController, Leaderboard, Score, BocaWebcastZipBuilder and the ICPC
report all use.

After #107 removed the other two readers, the audit was unambiguous:
`exercises` has no reader or writer left anywhere, and `teams` had exactly
one consumer -- this screen, which read, wrote and deleted its own table
while nothing else ever looked at what it wrote. Not a screen that had
fallen out of date; a closed loop that was never connected to anything.

Both reference implementations model this the same way, and neither the
way this screen did:

  BOCA has one usertable and one admin/user.php; a team is a user with
  type='team'. There is no teams table and no teams screen.

  CD-MOJ's source of truth is contests/<id>/users/<login>/, one directory
  per account. It does have a "Times" screen, but read what it is:
  "Identidade de cada conta no placar: nome do time, país/bandeira, sede,
  universidade, brasão e foto" -- presentation metadata hanging off
  accounts, with the roster in a separate "Inscrições" screen.

So the menu slot is worth having eventually; what occupied it was not it.
#105 gave account editing a real home in /backend/users, and /site/teams
already lists a site's real teams.

The four legacy tables (teams, exercises, exercise_team, team_user) are
deliberately left in place. Dropping them is irreversible and I cannot
verify from here whether anything outside this repository reads that
database -- an old report, an operations script. The screen is the part
that was actively misleading, and removing it changes no data.


Claude-Session: https://claude.ai/code/session_01Pvf2R8xtgbWQm1wRvjBqQY

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant