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

merge develop into main #48

Merged
merged 5 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
## [1.6.0] - 2024-007-23
### Added
- Archived flag [#40](https://github.com/rokwire/surveys-building-block/issues/40)
### Added
- Public flag [#37](https://github.com/rokwire/surveys-building-block/issues/37)
### Added
- Add extras field to survey data [#39](https://github.com/rokwire/surveys-building-block/issues/39)
### Fixed
- Fix "start_date" and "end_date" [#43](https://github.com/rokwire/surveys-building-block/issues/43)

## [1.5.0] - 2024-007-22
### Added
- Start/end date [#38](https://github.com/rokwire/surveys-building-block/issues/38)
Expand Down
4 changes: 2 additions & 2 deletions SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ Patches for **Surveys Building Block** in this repository will only be applied t

| Version | Supported |
| ------- | ------------------ |
| 1.5.0 | :white_check_mark: |
| < 1.5.0 | :x: |
| 1.6.0 | :white_check_mark: |
| < 1.6.0 | :x: |

## Reporting a Bug or Vulnerability

Expand Down
4 changes: 2 additions & 2 deletions core/app_admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ func (a appAdmin) GetSurvey(id string, orgID string, appID string) (*model.Surve
}

// GetSurvey returns surveys matching the provided query
func (a appAdmin) GetSurveys(orgID string, appID string, creatorID *string, surveyIDs []string, surveyTypes []string, calendarEventID string, limit *int, offset *int, filter *model.SurveyTimeFilter) ([]model.Survey, error) {
return a.app.shared.getSurveys(orgID, appID, creatorID, surveyIDs, surveyTypes, calendarEventID, limit, offset, filter)
func (a appAdmin) GetSurveys(orgID string, appID string, creatorID *string, surveyIDs []string, surveyTypes []string, calendarEventID string, limit *int, offset *int, filter *model.SurveyTimeFilter, public *bool, archived *bool) ([]model.Survey, error) {
return a.app.shared.getSurveys(orgID, appID, creatorID, surveyIDs, surveyTypes, calendarEventID, limit, offset, filter, public, archived)
}

// GetAllSurveyResponses returns survey responses matching the provided query
Expand Down
4 changes: 2 additions & 2 deletions core/app_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ func (a appClient) GetSurvey(id string, orgID string, appID string) (*model.Surv

// GetSurvey returns surveys matching the provided query
func (a appClient) GetSurveys(orgID string, appID string, creatorID *string, surveyIDs []string, surveyTypes []string, calendarEventID string,
limit *int, offset *int, filter *model.SurveyTimeFilter) ([]model.Survey, error) {
return a.app.shared.getSurveys(orgID, appID, creatorID, surveyIDs, surveyTypes, calendarEventID, limit, offset, filter)
limit *int, offset *int, filter *model.SurveyTimeFilter, public *bool, archived *bool) ([]model.Survey, error) {
return a.app.shared.getSurveys(orgID, appID, creatorID, surveyIDs, surveyTypes, calendarEventID, limit, offset, filter, public, archived)
}

// CreateSurvey creates a new survey
Expand Down
4 changes: 2 additions & 2 deletions core/app_shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ func (a appShared) getSurvey(id string, orgID string, appID string) (*model.Surv
return a.app.storage.GetSurvey(id, orgID, appID)
}

func (a appShared) getSurveys(orgID string, appID string, creatorID *string, surveyIDs []string, surveyTypes []string, calendarEventID string, limit *int, offset *int, filter *model.SurveyTimeFilter) ([]model.Survey, error) {
return a.app.storage.GetSurveys(orgID, appID, creatorID, surveyIDs, surveyTypes, calendarEventID, limit, offset, filter)
func (a appShared) getSurveys(orgID string, appID string, creatorID *string, surveyIDs []string, surveyTypes []string, calendarEventID string, limit *int, offset *int, filter *model.SurveyTimeFilter, public *bool, archived *bool) ([]model.Survey, error) {
return a.app.storage.GetSurveys(orgID, appID, creatorID, surveyIDs, surveyTypes, calendarEventID, limit, offset, filter, public, archived)
}

func (a appShared) createSurvey(survey model.Survey, externalIDs map[string]string) (*model.Survey, error) {
Expand Down
2 changes: 1 addition & 1 deletion core/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import "application/core/model"
type Shared interface {
// Surveys
getSurvey(id string, orgID string, appID string) (*model.Survey, error)
getSurveys(orgID string, appID string, creatorID *string, surveyIDs []string, surveyTypes []string, calendarEventID string, limit *int, offset *int, filter *model.SurveyTimeFilter) ([]model.Survey, error)
getSurveys(orgID string, appID string, creatorID *string, surveyIDs []string, surveyTypes []string, calendarEventID string, limit *int, offset *int, filter *model.SurveyTimeFilter, public *bool, archived *bool) ([]model.Survey, error)
createSurvey(survey model.Survey, externalIDs map[string]string) (*model.Survey, error)
updateSurvey(survey model.Survey, userID string, externalIDs map[string]string, admin bool) error
deleteSurvey(id string, orgID string, appID string, userID string, externalIDs map[string]string, admin bool) error
Expand Down
4 changes: 2 additions & 2 deletions core/interfaces/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type Default interface {
type Client interface {
// Surveys
GetSurvey(id string, orgID string, appID string) (*model.Survey, error)
GetSurveys(orgID string, appID string, creatorID *string, surveyIDs []string, surveyTypes []string, calendarEventID string, limit *int, offset *int, filter *model.SurveyTimeFilter) ([]model.Survey, error)
GetSurveys(orgID string, appID string, creatorID *string, surveyIDs []string, surveyTypes []string, calendarEventID string, limit *int, offset *int, filter *model.SurveyTimeFilter, public *bool, archived *bool) ([]model.Survey, error)
CreateSurvey(survey model.Survey, externalIDs map[string]string) (*model.Survey, error)
UpdateSurvey(survey model.Survey, userID string, externalIDs map[string]string) error
DeleteSurvey(id string, orgID string, appID string, userID string, externalIDs map[string]string) error
Expand Down Expand Up @@ -59,7 +59,7 @@ type Admin interface {

// Surveys
GetSurvey(id string, orgID string, appID string) (*model.Survey, error)
GetSurveys(orgID string, appID string, creatorID *string, surveyIDs []string, surveyTypes []string, calendarEventID string, limit *int, offset *int, filter *model.SurveyTimeFilter) ([]model.Survey, error)
GetSurveys(orgID string, appID string, creatorID *string, surveyIDs []string, surveyTypes []string, calendarEventID string, limit *int, offset *int, filter *model.SurveyTimeFilter, public *bool, archived *bool) ([]model.Survey, error)
CreateSurvey(survey model.Survey, externalIDs map[string]string) (*model.Survey, error)
UpdateSurvey(survey model.Survey, userID string, externalIDs map[string]string) error
DeleteSurvey(id string, orgID string, appID string, userID string, externalIDs map[string]string) error
Expand Down
2 changes: 1 addition & 1 deletion core/interfaces/driven.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type Storage interface {
DeleteConfig(id string) error

GetSurvey(id string, orgID string, appID string) (*model.Survey, error)
GetSurveys(orgID string, appID string, creatorID *string, surveyIDs []string, surveyTypes []string, calendarEventID string, limit *int, offset *int, filter *model.SurveyTimeFilter) ([]model.Survey, error)
GetSurveys(orgID string, appID string, creatorID *string, surveyIDs []string, surveyTypes []string, calendarEventID string, limit *int, offset *int, filter *model.SurveyTimeFilter, public *bool, archived *bool) ([]model.Survey, error)
CreateSurvey(survey model.Survey) (*model.Survey, error)
UpdateSurvey(survey model.Survey, admin bool) error
DeleteSurvey(id string, orgID string, appID string, creatorID string, admin bool) error
Expand Down
18 changes: 9 additions & 9 deletions core/interfaces/mocks/Storage.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 18 additions & 13 deletions core/model/surveys.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,10 @@ type Survey struct {
DateCreated time.Time `json:"date_created" bson:"date_created"`
DateUpdated *time.Time `json:"date_updated" bson:"date_updated"`
CalendarEventID string `json:"calendar_event_id" bson:"calendar_event_id"`
StartDate time.Time `json:"start_date" bson:"start_date"`
StartDate *time.Time `json:"start_date" bson:"start_date"`
EndDate *time.Time `json:"end_date" bson:"end_date"`
Public *bool `json:"public" bson:"public"`
Archived *bool `json:"archived" bson:"archived"`
}

// SurveyResponseAnonymous represents an anonymized survey response
Expand Down Expand Up @@ -92,17 +94,18 @@ type SurveyStats struct {

// SurveyData is data stored for a Survey
type SurveyData struct {
Section *string `json:"section,omitempty" bson:"section,omitempty"`
Sections []string `json:"sections,omitempty" bson:"sections,omitempty"`
AllowSkip bool `json:"allow_skip" bson:"allow_skip"`
Text string `json:"text" bson:"text"`
MoreInfo string `json:"more_info" bson:"more_info"`
DefaultFollowUpKey *string `json:"default_follow_up_key" bson:"default_follow_up_key"`
DefaultResponseRule *string `json:"default_response_rule" bson:"default_response_rule"`
FollowUpRule *string `json:"follow_up_rule" bson:"follow_up_rule"`
ScoreRule *string `json:"score_rule" bson:"score_rule"`
Replace bool `json:"replace" bson:"replace"`
Response interface{} `json:"response" bson:"response"`
Section *string `json:"section,omitempty" bson:"section,omitempty"`
Sections []string `json:"sections,omitempty" bson:"sections,omitempty"`
AllowSkip bool `json:"allow_skip" bson:"allow_skip"`
Text string `json:"text" bson:"text"`
MoreInfo string `json:"more_info" bson:"more_info"`
DefaultFollowUpKey *string `json:"default_follow_up_key" bson:"default_follow_up_key"`
DefaultResponseRule *string `json:"default_response_rule" bson:"default_response_rule"`
FollowUpRule *string `json:"follow_up_rule" bson:"follow_up_rule"`
ScoreRule *string `json:"score_rule" bson:"score_rule"`
Replace bool `json:"replace" bson:"replace"`
Response interface{} `json:"response" bson:"response"`
Extras *map[string]interface{} `json:"extras" bson:"extras"`

Type string `json:"type" bson:"type"`

Expand Down Expand Up @@ -193,8 +196,10 @@ type SurveyRequest struct {
DateCreated time.Time `json:"date_created" bson:"date_created"`
DateUpdated *time.Time `json:"date_updated" bson:"date_updated"`
CalendarEventID string `json:"calendar_event_id" bson:"calendar_event_id"`
StartDate int64 `json:"start_date" bson:"start_date"`
StartDate *int64 `json:"start_date" bson:"start_date"`
EndDate *int64 `json:"end_date" bson:"end_date"`
Public *bool `json:"public" bson:"public"`
Archived *bool `json:"archived" bson:"archived"`
}

// SurveyTimeFilter wraps the time filter for surveys
Expand Down
12 changes: 11 additions & 1 deletion driven/storage/adapter_surveys.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (a *Adapter) GetSurvey(id string, orgID string, appID string) (*model.Surve
}

// GetSurveys gets matching surveys
func (a *Adapter) GetSurveys(orgID string, appID string, creatorID *string, surveyIDs []string, surveyTypes []string, calendarEventID string, limit *int, offset *int, timeFilter *model.SurveyTimeFilter) ([]model.Survey, error) {
func (a *Adapter) GetSurveys(orgID string, appID string, creatorID *string, surveyIDs []string, surveyTypes []string, calendarEventID string, limit *int, offset *int, timeFilter *model.SurveyTimeFilter, public *bool, archived *bool) ([]model.Survey, error) {
filter := bson.D{
{Key: "org_id", Value: orgID},
{Key: "app_id", Value: appID},
Expand Down Expand Up @@ -70,6 +70,14 @@ func (a *Adapter) GetSurveys(orgID string, appID string, creatorID *string, surv
filter = append(filter, primitive.E{Key: "end_date", Value: primitive.M{"$lte": *timeFilter.EndTimeBefore}})
}

if public != nil {
filter = append(filter, bson.E{Key: "public", Value: public})
}

if archived != nil {
filter = append(filter, bson.E{Key: "archived", Value: archived})
}

opts := options.Find()
if limit != nil {
opts.SetLimit(int64(*limit))
Expand Down Expand Up @@ -131,6 +139,8 @@ func (a *Adapter) UpdateSurvey(survey model.Survey, admin bool) error {
"sub_rules": survey.SubRules,
"start_date": survey.StartDate,
"end_date": survey.EndDate,
"public": survey.Public,
"archived": survey.Archived,
"date_updated": now,
}}

Expand Down
31 changes: 30 additions & 1 deletion driver/web/apis_admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"io/ioutil"
"log"
"net/http"
"sort"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -233,12 +234,40 @@ func (h AdminAPIsHandler) getSurveys(l *logs.Log, r *http.Request, claims *token
}
offset = intParsed
}
publicStr := r.URL.Query().Get("public")

resData, err := h.app.Admin.GetSurveys(claims.OrgID, claims.AppID, nil, surveyIDs, surveyTypes, calendarEventID, &limit, &offset, filter)
var public *bool

if publicStr != "" {
value, err := strconv.ParseBool(publicStr)
if err != nil {
return l.HTTPResponseErrorAction(logutils.ActionGet, model.TypeSurvey, nil, err, http.StatusInternalServerError, true)
}
public = &value
}
archivedStr := r.URL.Query().Get("archived")

var archived *bool

if archivedStr != "" {
valueArchived, err := strconv.ParseBool(archivedStr)
if err != nil {
return l.HTTPResponseErrorAction(logutils.ActionGet, model.TypeSurvey, nil, err, http.StatusInternalServerError, true)
}
archived = &valueArchived
}

resData, err := h.app.Admin.GetSurveys(claims.OrgID, claims.AppID, nil, surveyIDs, surveyTypes, calendarEventID, &limit, &offset, filter, public, archived)
if err != nil {
return l.HTTPResponseErrorAction(logutils.ActionGet, model.TypeSurvey, nil, err, http.StatusInternalServerError, true)
}

surveys := surveysToSurveyRequests(resData)

sort.Slice(surveys, func(i, j int) bool {
return surveys[i].DateCreated.After(surveys[j].DateCreated)
})

rdata, err := json.Marshal(resData)
if err != nil {
return l.HTTPResponseErrorAction(logutils.ActionMarshal, logutils.TypeResponseBody, nil, err, http.StatusInternalServerError, false)
Expand Down
37 changes: 34 additions & 3 deletions driver/web/apis_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"io/ioutil"
"log"
"net/http"
"sort"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -108,13 +109,43 @@ func (h ClientAPIsHandler) getSurveys(l *logs.Log, r *http.Request, claims *toke
offset = intParsed
}

publicStr := r.URL.Query().Get("public")

var public *bool

if publicStr != "" {
value, err := strconv.ParseBool(publicStr)
if err != nil {
return l.HTTPResponseErrorAction(logutils.ActionGet, model.TypeSurvey, nil, err, http.StatusInternalServerError, true)
}
public = &value
}

archivedStr := r.URL.Query().Get("archived")

var archived *bool

if archivedStr != "" {
valueArchived, err := strconv.ParseBool(archivedStr)
if err != nil {
return l.HTTPResponseErrorAction(logutils.ActionGet, model.TypeSurvey, nil, err, http.StatusInternalServerError, true)
}
archived = &valueArchived
}

resData, err := h.app.Client.GetSurveys(claims.OrgID, claims.AppID, nil, surveyIDs, surveyTypes, calendarEventID,
&limit, &offset, filter)
&limit, &offset, filter, public, archived)
if err != nil {
return l.HTTPResponseErrorAction(logutils.ActionGet, model.TypeSurvey, nil, err, http.StatusInternalServerError, true)
}

rdata, err := json.Marshal(resData)
surveys := surveysToSurveyRequests(resData)

sort.Slice(surveys, func(i, j int) bool {
return surveys[i].DateCreated.After(surveys[j].DateCreated)
})

rdata, err := json.Marshal(surveys)
if err != nil {
return l.HTTPResponseErrorAction(logutils.ActionMarshal, logutils.TypeResponseBody, nil, err, http.StatusInternalServerError, false)
}
Expand Down Expand Up @@ -475,7 +506,7 @@ func (h ClientAPIsHandler) getCreatorSurveys(l *logs.Log, r *http.Request, claim
offset = intParsed
}

resData, err := h.app.Client.GetSurveys(claims.OrgID, claims.AppID, &claims.Subject, surveyIDs, surveyTypes, "", &limit, &offset, nil)
resData, err := h.app.Client.GetSurveys(claims.OrgID, claims.AppID, &claims.Subject, surveyIDs, surveyTypes, "", &limit, &offset, nil, nil, nil)
if err != nil {
return l.HTTPResponseErrorAction(logutils.ActionGet, model.TypeSurvey, nil, err, http.StatusInternalServerError, true)
}
Expand Down
Loading
Loading