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

[MI-3060]:Fixed review comments of PR #376 on gitlab plugin #38

Merged
merged 4 commits into from
May 8, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions server/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -547,8 +547,9 @@ func (p *Plugin) subscriptionsAddCommand(ctx context.Context, info *gitlab.UserI
}

if hasPermission := p.permissionToProject(ctx, info.UserID, namespace, project); !hasPermission {
p.API.LogWarn("You don't have the permission to create subscription for this project")
return "You don't have the permission to create subscription for this project."
msg := "You don't have the permissions to create subscriptions for this project"
p.client.Log.Warn(msg)
return msg
}

updatedSubscriptions, subscribeErr := p.Subscribe(info, namespace, project, channelID, features)
Expand Down
3 changes: 1 addition & 2 deletions server/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ func getTestPlugin(t *testing.T, mockCtrl *gomock.Controller, hooks []*gitlab.We

api := &plugintest.API{}
p.SetAPI(api)
p.client = pluginapi.NewClient(api, p.Driver)

conf := &model.Config{}
conf.ServiceSettings.SiteURL = &mattermostURL
Expand Down Expand Up @@ -324,8 +325,6 @@ func getTestPlugin(t *testing.T, mockCtrl *gomock.Controller, hooks []*gitlab.We
mock.AnythingOfTypeArgument("string"),
mock.AnythingOfTypeArgument("string"))

p.client = pluginapi.NewClient(api, p.Driver)

return p
}

Expand Down
6 changes: 5 additions & 1 deletion server/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,15 @@ func (p *Plugin) permissionToProject(ctx context.Context, userID, namespace, pro
result, err := p.GitlabClient.GetProject(ctx, info, namespace, project)
if result == nil || err != nil {
if err != nil {
p.API.LogWarn("Can't get project in webhook", "err", err.Error(), "project", namespace+"/"+project)
p.client.Log.Warn("Can't get project in webhook", "err", err.Error(), "project", namespace+"/"+project)
}
return false
}

if result.Permissions.ProjectAccess == nil {
return false
}

// Check for guest level permissions
if result.Permissions.ProjectAccess != nil && result.Permissions.ProjectAccess.AccessLevel == gitlabLib.GuestPermissions {
return false
Expand Down