Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RequestProjectRole API #353

Merged
merged 12 commits into from
Mar 6, 2024
Merged

Add RequestProjectRole API #353

merged 12 commits into from
Mar 6, 2024

Conversation

senk8
Copy link
Contributor

@senk8 senk8 commented Feb 21, 2024

背景

https://github.com/ca-risken/internal-community/issues/673

概要

アクセス権をリクエストするAPIを追加します。ユーザーが403画面からプロジェクト管理者ユーザーにアクセス許可をリクエストするために使用します。

APIの説明

  • ユーザーが403画面を開いた場合、ボタンを押すことでこのAPIにリクエストを送信します。
  • このAPIはリクエストを受け取ると、誰が・どのプロジェクトにの情報を含め、Slackへと通知を行います。
  • 通知が行われるチャンネルはアラートの通知先と同じもので、かつIDを昇順に並べた時に先頭にあるチャンネルとなります。

なお、proto以下のディレクトリに差分が発生していますが、proto/alert/service.proto以外はバージョンアップによる差分です。

観点

このPRのコメントに追加してあります。

参考

https://github.com/ca-risken/internal-community/issues/673
ca-risken/web#360

Copy link

セキュリティレビューを実施しました。
特に問題は見つかりませんでした👏

By RISKEN review

@senk8 senk8 changed the title add api Add Request Authorization API Feb 27, 2024
proto/alert/service.proto Outdated Show resolved Hide resolved
proto/alert/service.proto Outdated Show resolved Hide resolved
@senk8 senk8 marked this pull request as ready for review February 27, 2024 09:41
pkg/server/alert/alert_notification.go Outdated Show resolved Hide resolved
return nil, err
}
default:
a.logger.Warnf(ctx, "This notification_type is unimprement. type: %v", notification.Type)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

エラーを返しても良いかもです。
通知されてないのに、正常系のレスポンスになってしまいそうなので

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

すごい細かいですが、unimprement -> unimplement のtypoがありそうです。
ここで使うならunimplementedの方が適切かもと思いました。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

通知されてないのに、正常系のレスポンスになってしまいそうなので
すごい細かいですが、unimprement -> unimplement のtypoがありそうです。ここで使うならunimplementedの方が適切かもと思いました。

こちらについては自分も同感なので、修正します。
また、こちらはTestNotificationのほぼコピペとなっていたので、TestNotificationにも同様の問題(タイポ、エラーを返していないなど)がありそうです。意図していない実装になっている場合、このPRで一緒に修正してしまいます。

func (a *AlertService) TestNotification(ctx context.Context, req *alert.TestNotificationRequest) (*empty.Empty, error) {

pkg/server/alert/alert_slack.go Outdated Show resolved Hide resolved
proto/alert/service.proto Outdated Show resolved Hide resolved
proto/alert/service.proto Outdated Show resolved Hide resolved
@senk8
Copy link
Contributor Author

senk8 commented Feb 29, 2024

slackとの疎通確認に成功
image

Copy link
Collaborator

@gassara-kys gassara-kys left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

実装LGTMです。
(テスト実装中ということでApproveはそちらを確認してから行おうと思います。)

}
default:
a.logger.Warnf(ctx, "This notification_type is unimplemented. type: %v", notification.Type)
return nil, fmt.Errorf("This notification_type is unavailable. type: %v", notification.Type)
Copy link
Contributor Author

@senk8 senk8 Mar 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

コメント通りにここにエラーを追加しました。ログメッセージではunimplementedですがエラーメッセージとしてはユーザー目線でunavailableとしました。

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

エラーメッセージの場合は最初小文字でお願いします。

return nil, err
}
notifications, err := a.repository.ListNotification(ctx, req.ProjectId, "slack", 0, time.Now().Unix())
if err != nil {
Copy link
Contributor Author

@senk8 senk8 Mar 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここの書き方は他の部分では

	if err != nil {
		if errors.Is(err, gorm.ErrRecordNotFound) {
			return &empty.Empty{}, nil
		}
		return nil, err
	}

となっていますが、

  • このAPIは管理者に権限リクエストを送るもので、何らかのバグで送ることができなかった場合にはエラーをそのまま返してしまうのがよいと考えた

ので、errをそのまま返却するようにしました。

@senk8 senk8 changed the title Add Request Authorization API Add RequestProjectRole API Mar 1, 2024
@senk8 senk8 requested a review from gassara-kys March 1, 2024 04:32
}
default:
a.logger.Warnf(ctx, "This notification_type is unimplemented. type: %v", notification.Type)
return nil, fmt.Errorf("This notification_type is unavailable. type: %v", notification.Type)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

エラーメッセージの場合は最初小文字でお願いします。

cases := []struct {
name string
input *alert.RequestProjectRoleNotificationRequest
want *empty.Empty
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここは、レスポンス内容は問わないので、削っても良いかもと思いました(各テストケースでエラーが返されるか返されないかだけ見れば良い(wantErrのみ見れば良い))

@senk8
Copy link
Contributor Author

senk8 commented Mar 5, 2024

@gassara-kys
コメント内容をこちらのコミットで修正いたしました。
ffd28fd

@senk8 senk8 requested a review from gassara-kys March 5, 2024 01:41
Copy link
Collaborator

@gassara-kys gassara-kys left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@iiiidaaa iiiidaaa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@senk8 senk8 merged commit d9769d5 into master Mar 6, 2024
3 checks passed
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.

None yet

3 participants