mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
chore: rename notification banners to announcement banners (#13419)
This commit is contained in:
@@ -11,12 +11,12 @@ import (
|
||||
"github.com/coder/coder/v2/codersdk/agentsdk"
|
||||
)
|
||||
|
||||
type NotificationBannerAPI struct {
|
||||
type AnnouncementBannerAPI struct {
|
||||
appearanceFetcher *atomic.Pointer[appearance.Fetcher]
|
||||
}
|
||||
|
||||
// Deprecated: GetServiceBanner has been deprecated in favor of GetNotificationBanners.
|
||||
func (a *NotificationBannerAPI) GetServiceBanner(ctx context.Context, _ *proto.GetServiceBannerRequest) (*proto.ServiceBanner, error) {
|
||||
// Deprecated: GetServiceBanner has been deprecated in favor of GetAnnouncementBanners.
|
||||
func (a *AnnouncementBannerAPI) GetServiceBanner(ctx context.Context, _ *proto.GetServiceBannerRequest) (*proto.ServiceBanner, error) {
|
||||
cfg, err := (*a.appearanceFetcher.Load()).Fetch(ctx)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("fetch appearance: %w", err)
|
||||
@@ -24,16 +24,16 @@ func (a *NotificationBannerAPI) GetServiceBanner(ctx context.Context, _ *proto.G
|
||||
return agentsdk.ProtoFromServiceBanner(cfg.ServiceBanner), nil
|
||||
}
|
||||
|
||||
func (a *NotificationBannerAPI) GetNotificationBanners(ctx context.Context, _ *proto.GetNotificationBannersRequest) (*proto.GetNotificationBannersResponse, error) {
|
||||
func (a *AnnouncementBannerAPI) GetAnnouncementBanners(ctx context.Context, _ *proto.GetAnnouncementBannersRequest) (*proto.GetAnnouncementBannersResponse, error) {
|
||||
cfg, err := (*a.appearanceFetcher.Load()).Fetch(ctx)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("fetch appearance: %w", err)
|
||||
}
|
||||
banners := make([]*proto.BannerConfig, 0, len(cfg.NotificationBanners))
|
||||
for _, banner := range cfg.NotificationBanners {
|
||||
banners := make([]*proto.BannerConfig, 0, len(cfg.AnnouncementBanners))
|
||||
for _, banner := range cfg.AnnouncementBanners {
|
||||
banners = append(banners, agentsdk.ProtoFromBannerConfig(banner))
|
||||
}
|
||||
return &proto.GetNotificationBannersResponse{
|
||||
NotificationBanners: banners,
|
||||
return &proto.GetAnnouncementBannersResponse{
|
||||
AnnouncementBanners: banners,
|
||||
}, nil
|
||||
}
|
||||
+8
-8
@@ -14,7 +14,7 @@ import (
|
||||
"github.com/coder/coder/v2/codersdk/agentsdk"
|
||||
)
|
||||
|
||||
func TestGetNotificationBanners(t *testing.T) {
|
||||
func TestGetAnnouncementBanners(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
t.Run("OK", func(t *testing.T) {
|
||||
@@ -26,15 +26,15 @@ func TestGetNotificationBanners(t *testing.T) {
|
||||
BackgroundColor: "#00FF00",
|
||||
}}
|
||||
|
||||
var ff appearance.Fetcher = fakeFetcher{cfg: codersdk.AppearanceConfig{NotificationBanners: cfg}}
|
||||
var ff appearance.Fetcher = fakeFetcher{cfg: codersdk.AppearanceConfig{AnnouncementBanners: cfg}}
|
||||
ptr := atomic.Pointer[appearance.Fetcher]{}
|
||||
ptr.Store(&ff)
|
||||
|
||||
api := &NotificationBannerAPI{appearanceFetcher: &ptr}
|
||||
resp, err := api.GetNotificationBanners(context.Background(), &agentproto.GetNotificationBannersRequest{})
|
||||
api := &AnnouncementBannerAPI{appearanceFetcher: &ptr}
|
||||
resp, err := api.GetAnnouncementBanners(context.Background(), &agentproto.GetAnnouncementBannersRequest{})
|
||||
require.NoError(t, err)
|
||||
require.Len(t, resp.NotificationBanners, 1)
|
||||
require.Equal(t, cfg[0], agentsdk.BannerConfigFromProto(resp.NotificationBanners[0]))
|
||||
require.Len(t, resp.AnnouncementBanners, 1)
|
||||
require.Equal(t, cfg[0], agentsdk.BannerConfigFromProto(resp.AnnouncementBanners[0]))
|
||||
})
|
||||
|
||||
t.Run("FetchError", func(t *testing.T) {
|
||||
@@ -45,8 +45,8 @@ func TestGetNotificationBanners(t *testing.T) {
|
||||
ptr := atomic.Pointer[appearance.Fetcher]{}
|
||||
ptr.Store(&ff)
|
||||
|
||||
api := &NotificationBannerAPI{appearanceFetcher: &ptr}
|
||||
resp, err := api.GetNotificationBanners(context.Background(), &agentproto.GetNotificationBannersRequest{})
|
||||
api := &AnnouncementBannerAPI{appearanceFetcher: &ptr}
|
||||
resp, err := api.GetAnnouncementBanners(context.Background(), &agentproto.GetAnnouncementBannersRequest{})
|
||||
require.Error(t, err)
|
||||
require.ErrorIs(t, err, expectedErr)
|
||||
require.Nil(t, resp)
|
||||
@@ -36,7 +36,7 @@ import (
|
||||
type API struct {
|
||||
opts Options
|
||||
*ManifestAPI
|
||||
*NotificationBannerAPI
|
||||
*AnnouncementBannerAPI
|
||||
*StatsAPI
|
||||
*LifecycleAPI
|
||||
*AppsAPI
|
||||
@@ -108,7 +108,7 @@ func New(opts Options) *API {
|
||||
},
|
||||
}
|
||||
|
||||
api.NotificationBannerAPI = &NotificationBannerAPI{
|
||||
api.AnnouncementBannerAPI = &AnnouncementBannerAPI{
|
||||
appearanceFetcher: opts.AppearanceFetcher,
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user