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

[ID-125]Get all webtools calendar ids #126

Merged
merged 32 commits into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
7f2c55b
set the changelog.md
Feb 4, 2025
a0288c6
structure the API
Feb 4, 2025
a41e2fb
get originatingCalendarIds
Feb 4, 2025
cec31b4
set the permission and fix the code
Feb 4, 2025
bd751b5
fix function. name and add secrets.baseline
Feb 4, 2025
0a44ecf
secrets
Feb 4, 2025
dcc5df4
secrets
Feb 4, 2025
7dcf747
docs for remove originaiting calendarID from event
Feb 7, 2025
1fdb1c9
fix the docs
Feb 7, 2025
20a7678
structure the API
Feb 7, 2025
499ef51
in progress
Feb 7, 2025
176b6dc
remove calendarIDs from legacy event
Feb 7, 2025
8a1f1f9
set add calendarID docs
Feb 7, 2025
63e82c6
add calendar ID API
Feb 7, 2025
e8211ef
fix lint issue
Feb 7, 2025
4dba73b
remove wrong code
Feb 10, 2025
62408bb
fix get calendarIDs
Feb 10, 2025
bf08a7f
fix the docs
Feb 10, 2025
08c6b54
fix the name of the function and the json response
Feb 11, 2025
a437675
add originaiting calendar ids
Feb 11, 2025
8f8f10c
fix the docs
Feb 11, 2025
895fdff
add originating calendar ids
Feb 11, 2025
663d011
fix typo
Feb 11, 2025
f3f741d
remove data from webtools_originaiting_calendar_ids
Feb 11, 2025
7c5032f
Do not disable check
petyos Feb 12, 2025
3e4b7a3
Create section if it does not exist
petyos Feb 12, 2025
28bc99a
Fix wrong query param
petyos Feb 12, 2025
77a879c
Make it summary and introduce all_webtools permission
petyos Feb 12, 2025
8f5ae37
Summary API
petyos Feb 12, 2025
2841fa6
Summary API - more.
petyos Feb 12, 2025
8d52016
Do not commit bypases!
petyos Feb 12, 2025
8a27991
Fix lint issue
petyos Feb 12, 2025
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
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/Yelp/detect-secrets
rev: v1.4.0
rev: v1.5.0
hooks:
- id: detect-secrets
args: ['--baseline', '.secrets.baseline']
46 changes: 17 additions & 29 deletions .secrets.baseline
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.4.0",
"version": "1.5.0",
"plugins_used": [
{
"name": "ArtifactoryDetector"
Expand All @@ -26,6 +26,9 @@
{
"name": "GitHubTokenDetector"
},
{
"name": "GitLabTokenDetector"
},
{
"name": "HexHighEntropyString",
"limit": 3.0
Expand All @@ -36,6 +39,9 @@
{
"name": "IbmCosHmacDetector"
},
{
"name": "IPPublicDetector"
},
{
"name": "JwtTokenDetector"
},
Expand All @@ -49,9 +55,15 @@
{
"name": "NpmDetector"
},
{
"name": "OpenAIDetector"
},
{
"name": "PrivateKeyDetector"
},
{
"name": "PypiTokenDetector"
},
{
"name": "SendGridDetector"
},
Expand All @@ -67,6 +79,9 @@
{
"name": "StripeDetector"
},
{
"name": "TelegramBotTokenDetector"
},
{
"name": "TwilioKeyDetector"
}
Expand All @@ -75,10 +90,6 @@
{
"path": "detect_secrets.filters.allowlist.is_line_allowlisted"
},
{
"path": "detect_secrets.filters.common.is_baseline_file",
"filename": ".secrets.baseline"
},
{
"path": "detect_secrets.filters.common.is_ignored_due_to_verification_policies",
"min_level": 2
Expand Down Expand Up @@ -139,30 +150,7 @@
"line_number": 42
}
],
"driver/web/adapter.go": [
{
"type": "Secret Keyword",
"filename": "driver/web/adapter.go",
"hashed_secret": "a7d09aaaf55864f7ce39a7715aabed433c3fe661",
"is_verified": false,
"line_number": 234
}
],
"driver/web/auth.go": [
{
"type": "Secret Keyword",
"filename": "driver/web/auth.go",
"hashed_secret": "71855a10ce38ee3598463e19b9737c525f3f330a",
"is_verified": false,
"line_number": 77
},
{
"type": "Secret Keyword",
"filename": "driver/web/auth.go",
"hashed_secret": "36c48d6ac9d10902792fa78b9c2d7d535971c2cc",
"is_verified": false,
"line_number": 199
},
{
"type": "Secret Keyword",
"filename": "driver/web/auth.go",
Expand All @@ -172,5 +160,5 @@
}
]
},
"generated_at": "2024-11-04T17:23:04Z"
"generated_at": "2025-02-04T12:10:41Z"
}
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ All notable changes to this project will be documented in this file.

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
### Added
- Get all webtools calendar ids [#125] (https://github.com/rokwire/gateway-building-block/issues/125)

## [2.12.3] - 2025-01-28
### Changed
- updated launch procedures to skip pre-loading the wayfinding data.
Expand Down
24 changes: 20 additions & 4 deletions core/apis_admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ func (a appAdmin) DeleteConfig(id string, claims *tokenauth.Claims) error {
return nil
}

func (a appAdmin) AddWebtoolsBlackList(dataSourceIDs []string, dataCalendarIDs []string) error {
err := a.app.storage.AddWebtoolsBlacklistData(dataSourceIDs, dataCalendarIDs)
func (a appAdmin) AddWebtoolsBlackList(dataSourceIDs []string, dataCalendarIDs []string, dataOriginatingCalendarIDs []string) error {
err := a.app.storage.AddWebtoolsBlacklistData(dataSourceIDs, dataCalendarIDs, dataOriginatingCalendarIDs)
if err != nil {
return nil
}
Expand All @@ -211,15 +211,31 @@ func (a appAdmin) GetWebtoolsBlackList() ([]model.WebToolsItem, error) {
return blacklist, nil
}

func (a appAdmin) RemoveWebtoolsBlackList(sourceIds []string, calendarids []string) error {
err := a.app.storage.RemoveWebtoolsBlacklistData(sourceIds, calendarids)
func (a appAdmin) RemoveWebtoolsBlackList(sourceIds []string, calendarids []string, originatingCalendarIdsList []string) error {
err := a.app.storage.RemoveWebtoolsBlacklistData(sourceIds, calendarids, originatingCalendarIdsList)
if err != nil {
return nil
}

return nil
}

func (a appAdmin) GetWebtoolsSummary() (*model.WebToolsSummary, error) {
webtoolsCalendarIDs, err := a.app.storage.FindAllWebtoolsCalendarIDs()
if err != nil {
return nil, err
}

blacklistedCalendarIDs, err := a.app.storage.FindWebtoolsOriginatingCalendarIDsBlacklistData()
if err != nil {
return nil, err
}

response := model.WebToolsSummary{WebtoolsOriginatingCalendarIDs: webtoolsCalendarIDs, BlackListedOriginatingCalendarIDs: blacklistedCalendarIDs}

return &response, nil
}

// newAppAdmin creates new appAdmin
func newAppAdmin(app *Application) appAdmin {
return appAdmin{app: app}
Expand Down
6 changes: 6 additions & 0 deletions core/apis_bbs.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@ func (a appBBs) isBlacklisted(blacklists []model.WebToolsItem, event model.Legac
return true
}
}
case "webtools_originating_calendar_ids":
for _, id := range blacklist.Data {
if event.OriginatingCalendarID == id {
return true
}
}
}
}
return false
Expand Down
12 changes: 8 additions & 4 deletions core/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ type Admin interface {
CreateConfig(config model.Config, claims *tokenauth.Claims) (*model.Config, error)
UpdateConfig(config model.Config, claims *tokenauth.Claims) error
DeleteConfig(id string, claims *tokenauth.Claims) error
AddWebtoolsBlackList(dataSourceIDs []string, dataCalendarIDs []string) error
AddWebtoolsBlackList(dataSourceIDs []string, dataCalendarIDs []string, dataOriginatingCalendarIDs []string) error
GetWebtoolsBlackList() ([]model.WebToolsItem, error)
RemoveWebtoolsBlackList(sourceids []string, calendarids []string) error
RemoveWebtoolsBlackList(sourceids []string, calendarids []string, originatingCalendarIdsList []string) error
GetWebtoolsSummary() (*model.WebToolsSummary, error)
}

// BBs exposes Building Block APIs for the driver adapters
Expand Down Expand Up @@ -144,10 +145,13 @@ type Storage interface {
DeleteLegacyEventsBySourceID(context storage.TransactionContext, sourceID string) error
DeleteLegacyEventsByIDsAndCreator(context storage.TransactionContext, ids []string, accountID string) error
FindAllLegacyEvents() ([]model.LegacyEvent, error)
FindAllWebtoolsCalendarIDs() ([]model.WebToolsCalendarID, error)
FindWebtoolsLegacyEventByID(ids []string) ([]model.LegacyEventItem, error)

FindWebtoolsBlacklistData() ([]model.WebToolsItem, error)
AddWebtoolsBlacklistData(dataSourceIDs []string, dataCalendarIDs []string) error
RemoveWebtoolsBlacklistData(dataSourceIDs []string, dataCalendarIDs []string) error
AddWebtoolsBlacklistData(dataSourceIDs []string, dataCalendarIDs []string, dataOriginatingCalendarIDs []string) error
RemoveWebtoolsBlacklistData(dataSourceIDs []string, dataCalendarIDs []string, dataOriginatingCalendarIdsList []string) error
FindWebtoolsOriginatingCalendarIDsBlacklistData() ([]model.WebToolsItem, error)

FindImageItems() ([]model.ContentImagesURL, error)
InsertImageItem(items model.ContentImagesURL) error
Expand Down
12 changes: 12 additions & 0 deletions core/model/legacyEvents.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,18 @@ type WebToolsItem struct {
Data []string `json:"data" bson:"data"`
}

// WebToolsCalendarID represents web tools originating calendar ids
type WebToolsCalendarID struct {
Count int `json:"count"`
Name string `json:"id" bson:"originatingCalendarId"`
}

// WebToolsSummary represents web tools summary
type WebToolsSummary struct {
WebtoolsOriginatingCalendarIDs []WebToolsCalendarID `json:"originating_calendar_ids"`
BlackListedOriginatingCalendarIDs []WebToolsItem `json:"blacklisted_originating_calendar_ids"`
}

// LegacyEvent wrapper
type LegacyEvent struct {
AllDay bool `json:"allDay" bson:"allDay"`
Expand Down
100 changes: 98 additions & 2 deletions driven/storage/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,41 @@ func (a *Adapter) FindAllLegacyEvents() ([]model.LegacyEvent, error) {
return legacyEvents, err
}

// FindAllWebtoolsCalendarIDs finds and counts all webtools calendar IDs
func (a *Adapter) FindAllWebtoolsCalendarIDs() ([]model.WebToolsCalendarID, error) {
filter := bson.M{
"sync_process_source": "webtools-direct",
}

var list []model.LegacyEventItem
timeout := 15 * time.Second // 15 seconds timeout
err := a.db.legacyEvents.FindWithParams(nil, filter, &list, nil, &timeout)
if err != nil {
return nil, err
}

// Map to store counts of unique originatingCalendarId
countMap := make(map[string]int)

for _, l := range list {
calendarID := l.Item.OriginatingCalendarID
countMap[calendarID]++
}

// Convert map to slice of WebToolsCalendarID
var legacyEvents []model.WebToolsCalendarID
for id, count := range countMap {
legacyEvents = append(legacyEvents, model.WebToolsCalendarID{
Count: count,
Name: id,
})
}

return legacyEvents, nil
}

// AddWebtoolsBlacklistData update data from the database
func (a *Adapter) AddWebtoolsBlacklistData(dataSourceIDs []string, dataCalendarIDs []string) error {
func (a *Adapter) AddWebtoolsBlacklistData(dataSourceIDs []string, dataCalendarIDs []string, dataOriginatingCalendarIDs []string) error {
if dataSourceIDs != nil {
filterSource := bson.M{"name": "webtools_events_ids"}
updateSource := bson.M{
Expand All @@ -423,6 +456,26 @@ func (a *Adapter) AddWebtoolsBlacklistData(dataSourceIDs []string, dataCalendarI
if err != nil {
return errors.WrapErrorAction(logutils.ActionUpdate, "", filterArgs(filterCalendar), err)
}
}

if dataOriginatingCalendarIDs != nil {
filterCalendar := bson.M{
"_id": "3",
"name": "webtools_originating_calendar_ids",
}

updateCalendar := bson.M{
"$addToSet": bson.M{
"data": bson.M{"$each": dataOriginatingCalendarIDs},
},
}

opts := options.Update().SetUpsert(true) //create webtools_originating_calendar_ids if it does not exist

_, err := a.db.webtoolsBlacklistItems.UpdateOne(a.context, filterCalendar, updateCalendar, opts)
if err != nil {
return errors.WrapErrorAction(logutils.ActionUpdate, "", filterArgs(filterCalendar), err)
}

}

Expand All @@ -431,7 +484,7 @@ func (a *Adapter) AddWebtoolsBlacklistData(dataSourceIDs []string, dataCalendarI
}

// RemoveWebtoolsBlacklistData update data from the database
func (a *Adapter) RemoveWebtoolsBlacklistData(dataSourceIDs []string, dataCalendarIDs []string) error {
func (a *Adapter) RemoveWebtoolsBlacklistData(dataSourceIDs []string, dataCalendarIDs []string, dataOriginatingCalendarIdsList []string) error {
if dataSourceIDs != nil {
filterSource := bson.M{"name": "webtools_events_ids"}
updateSource := bson.M{
Expand Down Expand Up @@ -460,6 +513,21 @@ func (a *Adapter) RemoveWebtoolsBlacklistData(dataSourceIDs []string, dataCalend

}

if dataOriginatingCalendarIdsList != nil {
filterCalendar := bson.M{"name": "webtools_originating_calendar_ids"}
updateCalendar := bson.M{
"$pull": bson.M{
"data": bson.M{"$in": dataOriginatingCalendarIdsList},
},
}

_, err := a.db.webtoolsBlacklistItems.UpdateOne(a.context, filterCalendar, updateCalendar, nil)
if err != nil {
return errors.WrapErrorAction(logutils.ActionUpdate, model.TypeExample, filterArgs(filterCalendar), err)
}

}

return nil

}
Expand All @@ -476,6 +544,34 @@ func (a *Adapter) FindWebtoolsBlacklistData() ([]model.WebToolsItem, error) {
return dataSource, nil
}

// FindWebtoolsOriginatingCalendarIDsBlacklistData finds all webtools blacklist from the database
func (a *Adapter) FindWebtoolsOriginatingCalendarIDsBlacklistData() ([]model.WebToolsItem, error) {
filterSource := bson.M{"name": "webtools_originating_calendar_ids"}
var dataSource []model.WebToolsItem
err := a.db.webtoolsBlacklistItems.FindWithContext(a.context, filterSource, &dataSource, nil)
if err != nil {
return nil, err
}

return dataSource, nil
}

// FindWebtoolsLegacyEventByID finds webtool legacy event by the IDs of the items
func (a *Adapter) FindWebtoolsLegacyEventByID(ids []string) ([]model.LegacyEventItem, error) {
filter := bson.M{
"sync_process_source": "webtools-direct",
"item.id": bson.M{"$in": ids}, // Correctly filter by multiple IDs
}

var webtoolsLegacyEvent []model.LegacyEventItem
err := a.db.legacyEvents.FindWithContext(nil, filter, &webtoolsLegacyEvent, nil) // Use Find instead of FindOne
if err != nil {
return nil, err
}

return webtoolsLegacyEvent, nil
}

// PerformTransaction performs a transaction
func (a *Adapter) PerformTransaction(transaction func(context TransactionContext) error, timeoutMilliSeconds int64) error {
// transaction
Expand Down
1 change: 1 addition & 0 deletions driver/web/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ func (a Adapter) Start() {
adminRouter.HandleFunc("/webtools-blacklist", a.wrapFunc(a.adminAPIsHandler.addwebtoolsblacklist, a.auth.admin.Permissions)).Methods("PUT")
adminRouter.HandleFunc("/webtools-blacklist", a.wrapFunc(a.adminAPIsHandler.getwebtoolsblacklist, a.auth.admin.Permissions)).Methods("GET")
adminRouter.HandleFunc("/webtools-blacklist", a.wrapFunc(a.adminAPIsHandler.removewebtoolsblacklist, a.auth.admin.Permissions)).Methods("DELETE")
adminRouter.HandleFunc("/webtools-summary", a.wrapFunc(a.adminAPIsHandler.getWebtoolsSummary, a.auth.admin.Permissions)).Methods("GET")

// BB APIs
bbsRouter := mainRouter.PathPrefix("/bbs").Subrouter()
Expand Down
2 changes: 2 additions & 0 deletions driver/web/admin_permission_policy.csv
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ p, delete_configs_gateway, /gateway/api/admin/configs/*, (GET)|(DELETE), Delete
p, delete_configs_gateway, /gateway/api/admin/configs, (GET),

p, webtools_blacklist, /gateway/api/admin/webtools-blacklist, (GET)|(POST)|(PUT)|(DELETE), Webtools blacklist actions
p, all_webtools*, /gateway/api/admin/webtools*, (GET)|(POST)|(PUT)|(DELETE), Webtools actions

Loading