-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Creates a separate subscriptions package
- Loading branch information
Showing
7 changed files
with
60 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package subscriptions | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/vocdoni/saas-backend/db" | ||
"go.vocdoni.io/proto/build/go/models" | ||
) | ||
|
||
type SubscriptionsConfig struct { | ||
DB *db.MongoStorage | ||
} | ||
|
||
type Subscriptions struct { | ||
db *db.MongoStorage | ||
} | ||
|
||
func New(conf *SubscriptionsConfig) *Subscriptions { | ||
if conf == nil { | ||
return nil | ||
} | ||
return &Subscriptions{ | ||
db: conf.DB, | ||
} | ||
} | ||
|
||
func (p *Subscriptions) HasPermission( | ||
tx *models.Tx, | ||
txType models.TxType, | ||
org *db.Organization, | ||
) (bool, error) { | ||
// get subscription plan | ||
// plan, err := p.db.Subscription(org.Subscription.SubscriptionID) | ||
// if err != nil { | ||
// return false, fmt.Errorf("could not get organization subscription: %v", err) | ||
// } | ||
switch txType { | ||
case models.TxType_NEW_PROCESS, models.TxType_SET_PROCESS_CENSUS: | ||
newProcess := tx.GetNewProcess() | ||
if newProcess.Process.MaxCensusSize > uint64(org.Subscription.MaxCensusSize) { | ||
return false, fmt.Errorf("MaxCensusSize is greater than the allowed") | ||
} | ||
} | ||
return true, nil | ||
} |