func (s *ProjectService) list(req *restful.Request, resp *restful.Response) { // TODO (m0sth8): check permissions query, err := fltr.FromRequest(req, manager.ProjectFltr{}) if err != nil { resp.WriteServiceError(http.StatusBadRequest, services.NewBadReq(err.Error())) return } u := filters.GetUser(req) admin := false // if user is not admin then show him only his projects or where he has membership if !admin { query = manager.Or(fltr.GetQuery(&manager.ProjectFltr{Owner: u.Id, Member: u.Id})) } mgr := s.Manager() defer mgr.Close() results, count, err := mgr.Projects.FilterByQuery(query) if err != nil { logrus.Error(stackerr.Wrap(err)) resp.WriteServiceError(http.StatusInternalServerError, services.DbErr) return } result := &project.ProjectList{ Meta: pagination.Meta{Count: count}, Results: results, } resp.WriteEntity(result) }
func (s *MeService) info(req *restful.Request, resp *restful.Response) { mgr := s.Manager() defer mgr.Close() u := filters.GetUser(req) query := manager.Or(fltr.GetQuery(&manager.ProjectFltr{Owner: u.Id, Member: u.Id})) projects, count, err := mgr.Projects.FilterByQuery(query) if err != nil { logrus.Error(stackerr.Wrap(err)) } else { // TODO (m0sth8): create default project when user on create is triggered. // create one default project if count == 0 { p, err := mgr.Projects.CreateDefault(u.Id) if err != nil { logrus.Error(stackerr.Wrap(err)) // It might be possible, that default project is already created // So, client should repeat request resp.WriteServiceError(http.StatusInternalServerError, services.DbErr) return } else { projects = append(projects, p) } } } info := me.Info{ User: u, Projects: projects, } resp.WriteEntity(info) }
func (m *ScanManager) FilterBy(f *ScanFltr) ([]*scan.Scan, int, error) { query := fltr.GetQuery(f) results := []*scan.Scan{} count, err := m.manager.FilterBy(m.col, &query, &results) return results, count, err }
func (m *CommentManager) FilterBy(f *CommentFltr, opts ...Opts) ([]*comment.Comment, int, error) { query := fltr.GetQuery(f) return m.FilterByQuery(query, opts...) }
func (m *FeedManager) FilterBy(f *FeedItemFltr, opts ...Opts) ([]*feed.FeedItem, int, error) { query := fltr.GetQuery(f) return m.FilterByQuery(query, opts...) }
func (m *PluginManager) FilterBy(f *PluginFltr) ([]*plugin.Plugin, int, error) { query := fltr.GetQuery(f) results := []*plugin.Plugin{} count, err := m.manager.FilterBy(m.col, &query, &results) return results, count, err }
func (m *IssueManager) FilterBy(f *IssueFltr, opts ...Opts) ([]*issue.TargetIssue, int, error) { query := fltr.GetQuery(f) return m.FilterByQuery(query, opts...) }
func (m *ReportManager) FilterBy(f *ReportFltr) ([]*report.Report, int, error) { query := fltr.GetQuery(f) results := []*report.Report{} count, err := m.manager.FilterBy(m.col, &query, &results) return results, count, err }
func (m *TargetManager) FilterBy(f *FeedItemFltr) ([]*target.Target, int, error) { query := fltr.GetQuery(f) return m.FilterByQuery(query) }
func (m *ProjectManager) FilterBy(f *ProjectFltr) ([]*project.Project, int, error) { query := fltr.GetQuery(f) return m.FilterByQuery(query) }
func (m *UserManager) FilterBy(f *UserFltr) ([]*user.User, int, error) { query := fltr.GetQuery(f) results := []*user.User{} count, err := m.manager.FilterBy(m.col, &query, &results) return results, count, err }
func (m *AgentManager) FilterBy(f *AgentFltr) ([]*agent.Agent, int, error) { query := fltr.GetQuery(f) results := []*agent.Agent{} count, err := m.manager.FilterBy(m.col, &query, &results) return results, count, err }