AtCoderNoviSteps icon indicating copy to clipboard operation
AtCoderNoviSteps copied to clipboard

copy pages for administrators

Open prettyhappycatty opened this issue 1 year ago • 2 comments

Resolves #1346

主な対応

  • 管理者向けのコピーページの作成
  • 管理者メニューからの「ユーザーデータコピー」リンクの作成
  • コピーページのロジックの実装
スクリーンショット 2024-10-13 0 05 21

追加仕様

  • source/destination usernameのどちらかが空の場合は何も起こりません。
  • source/destination usernameが入力されているけれども、ユーザー名として存在しない場合、エラーメッセージが出てコピーは中止されます。
  • source usernameが持ってるtaskResultsが空の場合は、エラーメッセージがでてコピーは中止されます。
  • destination usernameが持ってるtaskResultsがすでにある場合は、エラーメッセージが出てコピーは中止されます。
  • (sourceとdestinationに同じIDを入れた場合は、少なくとも上記のどちらかで失敗する)
  • コピー成功、終了メッセージは10秒で消えます。

Summary by CodeRabbit

  • New Features

    • Introduced a new page for copying user data with the title "ユーザーデータコピー."
    • Added functionality for admins to copy task results between users.
    • Implemented a user interface for the copy operation, displaying status messages.
  • Bug Fixes

    • Enhanced user authentication checks to ensure only admins can access the copy functionality.
  • Documentation

    • Updated interface to provide structured feedback on the copy operation's success or failure.

prettyhappycatty avatar Oct 12 '24 14:10 prettyhappycatty

Walkthrough

The changes in this pull request introduce new constants and functionalities related to user account management. Two constants for navigation are added, and a new function copyTaskResults is implemented to facilitate copying task results between users. Additionally, a new Svelte component for account transfers is created, which includes form handling and user feedback. The changes also introduce a new interface for managing floating messages related to these operations.

Changes

File Change Summary
src/lib/constants/navbar-links.ts Added constants DATA_COPY_PAGE and ACCOUNT_TRANSFER_PAGE, and updated navbarDashboardLinks.
src/lib/services/task_results.ts Introduced copyTaskResults function and several helper functions for user validation and data copying.
src/lib/types/floating_message.ts Added new interface FloatingMessage and type alias FloatingMessages.
src/routes/(admin)/account_transfer/+page.server.ts Added a server-side page with a load function for session validation and account transfer handling.
src/routes/(admin)/account_transfer/+page.svelte Created a Svelte component for account transfers with form handling and message display.
src/lib/zod/schema.ts Added accountTransferSchema for validating account transfer inputs and improved error messages.
src/lib/utils/account_transfer.ts Introduced functions for user validation and answer checking related to account transfers.
src/test/lib/zod/account_transfer_schema.test.ts Added unit tests for accountTransferSchema to validate user input scenarios.

Assessment against linked issues

Objective Addressed Explanation
Admin can set old and new IDs to copy response data (taskAnswer)
The operation only copies data if the destination's response data is empty
Success and failure notifications are provided to the admin

🐇 In the fields of data, we hop and play,
With new paths for users, come what may.
Copying answers, swift and neat,
Admins rejoice, this task's complete!
A leap for the lost, a joyful cheer,
For every new ID, we bring good cheer! 🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

coderabbitai[bot] avatar Oct 12 '24 15:10 coderabbitai[bot]

早速、機能を実装していただき、ありがとうございます。 拝見いたします。

KATO-Hiro avatar Oct 13 '24 01:10 KATO-Hiro

@prettyhappycatty

大変遅くなりましたが、プルリクエストの修正していただいた点を拝見いたしました。 コピー処理の実装本体に関しては、LGTMです。

coderabbitai による数多くのレビューを受け、妥当と思われるものを取り入れました。 主な変更点は以下の通りです。

  • SuperformsとZodによるフォームバリデーションの導入、および、フォーム送信時にコピーボタンを非活性に
    • バリデーション周りの実装がシンプルになります
    • 型チェックもしてくれます
    • これらのメリットからフォームの処理は、ライブラリを使って実装していきたいと考えています(オススメのライブラリがございましたら差し替えることも検討しています)
  • UIの改善: tailwindcssでスタイルを調整
    • レスポンシブデザインとなるように既存のコンポーネントを導入
    • ダークモードの際は、文字を灰色に変更
  • リファクタリング
    • コピー処理を複数の関数に分割し、utilsフォルダに移動
    • リネーム、定数の利用、アクセシビリティへの配慮 など
  • 単体テストの追加
    • Zodのスキーマのテスト: ほぼ完了
    • コピー処理の汎用関数: 未着手 → テストを追加 → コードレビューツールの指摘事項のうち必要だと判断した内容を修正
  • 保留中
    • 国際化対応

自動テストのうち、着手しやすい単体テストから少しずつ取り組んでいます。

また、既存のテストに対して、書き方の改善点や追加すべきテストケースなどがあれば、教えていただけると幸いです。 よろしくお願いいたします。

KATO-Hiro avatar Oct 20 '24 13:10 KATO-Hiro

@prettyhappycatty

コピー処理の汎用関数に関する単体テストを追加しました。 コードレビューツールの指摘事項のうち、必要だと判断したものを修正する予定です。

KATO-Hiro avatar Oct 21 '24 13:10 KATO-Hiro

ご対応ありがとうございます。 今日の夜はできると思うので、コメントいただいたもの等々対応します!

prettyhappycatty avatar Oct 21 '24 23:10 prettyhappycatty

@prettyhappycatty

コードレビューツールの指摘事項のうち、以下の内容を修正しました。

修正済み

  • テストとテストケース、汎用関数を分離
  • 汎用関数や注意事項をドキュメント化

対応予定

  • xssライブラリを利用したHTMLのサニタイズ

KATO-Hiro avatar Oct 22 '24 13:10 KATO-Hiro

@KATO-Hiro

対応予定

https://github.com/AtCoder-NoviSteps/AtCoderNoviSteps/pull/1371#discussion_r1807974250

prettyhappycatty avatar Oct 22 '24 13:10 prettyhappycatty

@prettyhappycatty

実装を試みていただき、ありがとうございます。 コピー機能が動作しているか、手作業と目視で確認したいと思います。

storeの実装を保留にする点ついても承知しました。

KATO-Hiro avatar Oct 22 '24 21:10 KATO-Hiro

coderabbitの指摘で残ってるもののうち、どれを対応しなきゃいけないかが、あまり判断つかないのですが、 どのように判断していますか?

あ、でもほとんどもうクローズしていただいていますかね?ありがとうございます!

prettyhappycatty avatar Oct 23 '24 15:10 prettyhappycatty

ありがとうございます。

coderabbitの指摘に関して、より理解しやすくなるようなリファクタリング(変数名のリネーム、メソッドの抽出や再構成など)、型・テストケースの追加、エラーハンドリングなどは対応するようにしています。 ただ、無条件で受け入れるわけではなく、内容が分からないときは調べるようにしており、テストが通らないような修正案は反映させないようにしています。

KATO-Hiro avatar Oct 23 '24 21:10 KATO-Hiro

判断基準について教えていただきありがとうございます!

prettyhappycatty avatar Oct 23 '24 23:10 prettyhappycatty

@coderabbitai review

KATO-Hiro avatar Oct 24 '24 13:10 KATO-Hiro

:white_check_mark: Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

coderabbitai[bot] avatar Oct 24 '24 13:10 coderabbitai[bot]