Skip to content

Commit

Permalink
remove unused threads-everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
lieut-data committed Sep 19, 2024
1 parent 70b3192 commit a665a89
Show file tree
Hide file tree
Showing 6 changed files with 0 additions and 493 deletions.
10 changes: 0 additions & 10 deletions server/app/permissions_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,6 @@ func (p *PermissionsService) hasPermissionsToPlaybook(userID string, playbook Pl
return p.pluginAPI.User.HasPermissionToTeam(userID, playbook.TeamID, permission)
}

func (p *PermissionsService) HasPermissionsToRun(userID string, run *PlaybookRun, permission *model.Permission) bool {
// Check at run level
if err := p.runManagePropertiesWithPlaybookRun(userID, run); err != nil {
return false
}

// Cascade normally to higher level permissions
return p.pluginAPI.User.HasPermissionToTeam(userID, run.TeamID, permission)
}

func (p *PermissionsService) canViewTeam(userID string, teamID string) bool {
if teamID == "" || userID == "" {
return false
Expand Down
32 changes: 0 additions & 32 deletions server/app/playbook_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -564,18 +564,6 @@ type RunAction struct {
RemoveChannelMemberOnRemovedParticipant bool `json:"remove_channel_member_on_removed_participant"`
}

type RunMetadata struct {
ID string
Name string
TeamID string
}

type TopicMetadata struct {
ID string
RunID string
TeamID string
}

const (
ActionTypeBroadcastChannels = "broadcast_to_channels"
ActionTypeBroadcastWebhooks = "broadcast_to_webhooks"
Expand Down Expand Up @@ -792,16 +780,6 @@ type PlaybookRunService interface {
// GetPlaybookRunIDsForUser returns run ids where user is a participant or is following
GetPlaybookRunIDsForUser(userID string) ([]string, error)

// GetRunMetadataByIDs returns playbook runs metadata by passed run IDs.
// Notice that order of passed ids and returned runs might not coincide
GetRunMetadataByIDs(runIDs []string) ([]RunMetadata, error)

// GetTaskMetadataByIDs gets PlaybookRunIDs and TeamIDs from runs by taskIDs
GetTaskMetadataByIDs(taskIDs []string) ([]TopicMetadata, error)

// GetStatusMetadataByIDs gets PlaybookRunIDs and TeamIDs from runs by statusIDs
GetStatusMetadataByIDs(statusIDs []string) ([]TopicMetadata, error)

// GraphqlUpdate taking a setmap for graphql
GraphqlUpdate(id string, setmap map[string]interface{}) error

Expand Down Expand Up @@ -920,16 +898,6 @@ type PlaybookRunStore interface {
// GetPlaybookRunIDsForUser returns run ids where user is a participant or is following
GetPlaybookRunIDsForUser(userID string) ([]string, error)

// GetRunMetadataByIDs returns playbook runs metadata by passed run IDs.
// Notice that order of passed ids and returned runs might not coincide
GetRunMetadataByIDs(runIDs []string) ([]RunMetadata, error)

// GetTaskAsTopicMetadataByIDs gets PlaybookRunIDs and TeamIDs from runs by taskIDs
GetTaskAsTopicMetadataByIDs(taskIDs []string) ([]TopicMetadata, error)

// GetStatusAsTopicMetadataByIDs gets PlaybookRunIDs and TeamIDs from runs by statusIDs
GetStatusAsTopicMetadataByIDs(statusIDs []string) ([]TopicMetadata, error)

// GetStatsPostsByIDs gets the status posts for playbook runs
GetStatusPostsByIDs(playbookRunID []string) (map[string][]StatusPost, error)

Expand Down
15 changes: 0 additions & 15 deletions server/app/playbook_run_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -3665,18 +3665,3 @@ func (s *PlaybookRunServiceImpl) doActions(taskActions []Action, runID string, u
func (s *PlaybookRunServiceImpl) GetPlaybookRunIDsForUser(userID string) ([]string, error) {
return s.store.GetPlaybookRunIDsForUser(userID)
}

// GetRunMetadataByIDs returns playbook runs metadata by passed run IDs.
func (s *PlaybookRunServiceImpl) GetRunMetadataByIDs(runIDs []string) ([]RunMetadata, error) {
return s.store.GetRunMetadataByIDs(runIDs)
}

// GetTaskMetadataByIDs gets PlaybookRunIDs and TeamIDs from runs by taskIDs
func (s *PlaybookRunServiceImpl) GetTaskMetadataByIDs(taskIDs []string) ([]TopicMetadata, error) {
return s.store.GetTaskAsTopicMetadataByIDs(taskIDs)
}

// GetStatusMetadataByIDs gets PlaybookRunIDs and TeamIDs from runs by statusIDs
func (s *PlaybookRunServiceImpl) GetStatusMetadataByIDs(statusIDs []string) ([]TopicMetadata, error) {
return s.store.GetStatusAsTopicMetadataByIDs(statusIDs)
}
126 changes: 0 additions & 126 deletions server/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,6 @@ const (
updateMetricsTaskFrequency = 15 * time.Minute

metricsExposePort = ":9093"

// Topic represents a start of a thread. In playbooks we support 2 types of topics:
// status topic - indicating the start of the thread below status update and
// task topic - indicating the start of the thread below task(checklist item)
TopicTypeStatus = "status"
TopicTypeTask = "task"

// Collection is a group of topics and their corresponding threads.
// In Playbooks we support a single type of collection - a run
CollectionTypeRun = "run"
)

const (
Expand Down Expand Up @@ -235,15 +225,6 @@ func (p *Plugin) OnActivate() error {

p.permissions = app.NewPermissionsService(p.playbookService, p.playbookRunService, pluginAPIClient, p.config, p.licenseChecker)

// register collections and topics.
// TODO bump the minimum server version
if err := p.API.RegisterCollectionAndTopic(CollectionTypeRun, TopicTypeStatus); err != nil {
logrus.WithError(err).Warnf("failed to register collection - %s and topic - %s", CollectionTypeRun, TopicTypeStatus)
}
if err := p.API.RegisterCollectionAndTopic(CollectionTypeRun, TopicTypeTask); err != nil {
logrus.WithError(err).Warnf("failed to register collection - %s and topic - %s", CollectionTypeRun, TopicTypeTask)
}

api.NewGraphQLHandler(
p.handler.APIRouter,
p.playbookService,
Expand Down Expand Up @@ -423,114 +404,7 @@ func (p *Plugin) getErrorCounterHandler() func(next http.Handler) http.Handler {
}
}

func (p *Plugin) UserHasPermissionToCollection(c *plugin.Context, userID string, collectionType, collectionID string, permission *model.Permission) (bool, error) {
if collectionType != CollectionTypeRun {
return false, errors.Errorf("collection %s is not registered by playbooks", collectionType)
}

run, err := p.playbookRunService.GetPlaybookRun(collectionID)
if err != nil {
return false, errors.Wrapf(err, "No run with id - %s", collectionID)
}
return p.permissions.HasPermissionsToRun(userID, run, permission), nil
}

func (p *Plugin) GetAllCollectionIDsForUser(c *plugin.Context, userID, collectionType string) ([]string, error) {
if collectionType != CollectionTypeRun {
return nil, errors.Errorf("collection %s is not registered by playbooks", collectionType)
}

ids, err := p.playbookRunService.GetPlaybookRunIDsForUser(userID)
if err != nil {
return nil, err
}

return ids, nil
}

func (p *Plugin) GetAllUserIDsForCollection(c *plugin.Context, collectionType, collectionID string) ([]string, error) {
if collectionType != CollectionTypeRun {
return nil, errors.Errorf("collection %s is not registered by playbooks", collectionType)
}

run, err := p.playbookRunService.GetPlaybookRun(collectionID)
if err != nil {
return nil, errors.Wrapf(err, "No run with id - %s", collectionID)
}
followers, err := p.playbookRunService.GetFollowers(collectionID)
if err != nil {
return nil, errors.Wrapf(err, "can't get followers for run - %s", collectionID)
}
return mergeSlice(run.ParticipantIDs, followers), nil
}

func (p *Plugin) GetCollectionMetadataByIds(c *plugin.Context, collectionType string, collectionIDs []string) (map[string]*model.CollectionMetadata, error) {
if collectionType != CollectionTypeRun {
return nil, errors.Errorf("collection %s is not registered by playbooks", collectionType)
}
runsMetadata := map[string]*model.CollectionMetadata{}
runs, err := p.playbookRunService.GetRunMetadataByIDs(collectionIDs)
if err != nil {
return nil, errors.Wrap(err, "can't get playbook run metadata by ids")
}
for _, run := range runs {
runsMetadata[run.ID] = &model.CollectionMetadata{
Id: run.ID,
CollectionType: CollectionTypeRun,
TeamId: run.TeamID,
Name: run.Name,
RelativeURL: app.GetRunDetailsRelativeURL(run.ID),
}
}
return runsMetadata, nil
}

func (p *Plugin) GetTopicMetadataByIds(c *plugin.Context, topicType string, topicIDs []string) (map[string]*model.TopicMetadata, error) {
topicsMetadata := map[string]*model.TopicMetadata{}

var getTopicMetadataByIDs func(topicIDs []string) ([]app.TopicMetadata, error)
switch topicType {
case TopicTypeStatus:
getTopicMetadataByIDs = p.playbookRunService.GetStatusMetadataByIDs
case TopicTypeTask:
getTopicMetadataByIDs = p.playbookRunService.GetTaskMetadataByIDs
default:
return map[string]*model.TopicMetadata{}, errors.Errorf("topic type %s is not registered by playbooks", topicType)
}

topics, err := getTopicMetadataByIDs(topicIDs)
if err != nil {
return nil, errors.Wrap(err, "can't get metadata by topic ids")
}
for _, topic := range topics {
topicsMetadata[topic.ID] = &model.TopicMetadata{
Id: topic.ID,
TopicType: topicType,
CollectionType: CollectionTypeRun,
TeamId: topic.TeamID,
CollectionId: topic.RunID,
}
}

return topicsMetadata, nil
}

func (p *Plugin) OnDeactivate() error {
logrus.Info("Shutting down store..")
return p.pluginAPI.Store.Close()
}

func mergeSlice(a, b []string) []string {
m := make(map[string]struct{}, len(a)+len(b))
for _, elem := range a {
m[elem] = struct{}{}
}
for _, elem := range b {
m[elem] = struct{}{}
}
merged := make([]string, 0, len(m))
for key := range m {
merged = append(merged, key)
}
return merged
}
101 changes: 0 additions & 101 deletions server/sqlstore/playbook_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -1536,107 +1536,6 @@ func (s *playbookRunStore) GetPlaybookRunIDsForUser(userID string) ([]string, er
return ids, nil
}

// GetRunMetadataByIDs returns playbook runs metadata by passed run IDs.
func (s *playbookRunStore) GetRunMetadataByIDs(runIDs []string) ([]app.RunMetadata, error) {
var runs []app.RunMetadata
query := s.store.builder.
Select("ID", "TeamID", "Name").
From("IR_Incident").
Where(sq.Eq{"ID": runIDs})
if err := s.store.selectBuilder(s.store.db, &runs, query); err != nil {
return nil, errors.Wrap(err, "failed to query playbook run by runIDs")
}

runsMap := make(map[string]app.RunMetadata, len(runs))
for _, run := range runs {
runsMap[run.ID] = run
}
orderedRuns := make([]app.RunMetadata, len(runIDs))
for i, runID := range runIDs {
orderedRuns[i] = runsMap[runID]
}
return orderedRuns, nil
}

// GetTaskAsTopicMetadataByIDs gets PlaybookRunIDs and TeamIDs from runs by taskIDs
func (s *playbookRunStore) GetTaskAsTopicMetadataByIDs(taskIDs []string) ([]app.TopicMetadata, error) {
tasksMap := make(map[string]app.TopicMetadata, len(taskIDs))
for _, taskID := range taskIDs {
var runsInDB []struct {
app.TopicMetadata
ChecklistsJSON json.RawMessage
}
query := s.store.builder.
Select("ID AS RunID", "TeamID", "ChecklistsJSON").
From("IR_Incident")

if s.store.db.DriverName() == model.DatabaseDriverMysql {
query = query.Where(sq.Like{"ChecklistsJSON": fmt.Sprintf("%%\"%s\"%%", taskID)})
} else {
query = query.Where(sq.Like{"ChecklistsJSON::text": fmt.Sprintf("%%\"%s\"%%", taskID)})
}

if err := s.store.selectBuilder(s.store.db, &runsInDB, query); err != nil {
return nil, errors.Wrapf(err, "failed to query playbook run by taskID - %s", taskID)
}

for _, run := range runsInDB {
var checklists []app.Checklist
err := json.Unmarshal(run.ChecklistsJSON, &checklists)
if err != nil {
return nil, errors.Wrapf(err, "failed to unmarshal checklists json for playbook run id: %s", run.RunID)
}

if isTaskInChecklists(checklists, taskID) {
tasksMap[taskID] = app.TopicMetadata{
ID: taskID,
RunID: run.RunID,
TeamID: run.TeamID,
}
}
}
}
tasks := make([]app.TopicMetadata, len(taskIDs))
for i, taskID := range taskIDs {
tasks[i] = tasksMap[taskID]
}

return tasks, nil
}

func isTaskInChecklists(checklists []app.Checklist, taskID string) bool {
for _, checklist := range checklists {
for _, item := range checklist.Items {
if item.ID == taskID {
return true
}
}
}
return false
}

// GetStatusAsTopicMetadataByIDs gets PlaybookRunIDs and TeamIDs from runs by statusIDs
func (s *playbookRunStore) GetStatusAsTopicMetadataByIDs(statusIDs []string) ([]app.TopicMetadata, error) {
var statuses []app.TopicMetadata
query := s.store.builder.
Select("sp.PostID AS ID", "sp.IncidentID AS RunID", "i.TeamID AS TeamID").
From("IR_StatusPosts as sp").
Join("IR_Incident as i ON sp.IncidentID = i.ID").
Where(sq.Eq{"sp.PostID": statusIDs})
if err := s.store.selectBuilder(s.store.db, &statuses, query); err != nil {
return nil, errors.Wrap(err, "failed to query playbook runs by statusIDs")
}
statusesMap := make(map[string]app.TopicMetadata, len(statuses))
for _, status := range statuses {
statusesMap[status.ID] = status
}
orderedStatuses := make([]app.TopicMetadata, len(statusIDs))
for i, statusID := range statusIDs {
orderedStatuses[i] = statusesMap[statusID]
}
return orderedStatuses, nil
}

func (s *playbookRunStore) GraphqlUpdate(id string, setmap map[string]interface{}) error {
if id == "" {
return errors.New("id should not be empty")
Expand Down
Loading

0 comments on commit a665a89

Please sign in to comment.