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

Implements subscription limitations #40

Merged
merged 3 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion api/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (a *API) signTxHandler(w http.ResponseWriter, r *http.Request) {
return
}
// check if the user is a member of the organization
if !user.IsMemberOf(signReq.Address) {
if !user.HasRoleFor(signReq.Address, db.AnyRole) {
ErrUnauthorized.With("user is not an organization member").Write(w)
return
}
Expand Down
4 changes: 4 additions & 0 deletions db/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const (
AdminRole UserRole = "admin"
ManagerRole UserRole = "manager"
ViewerRole UserRole = "viewer"
AnyRole UserRole = "any"
// organization types
AssemblyType OrganizationType = "assembly"
AssociationType OrganizationType = "association"
Expand All @@ -31,13 +32,15 @@ var writableRoles = map[UserRole]bool{
AdminRole: true,
ManagerRole: true,
ViewerRole: false,
AnyRole: false,
}

// UserRoleNames is a map that contains the user role names by role
var UserRolesNames = map[UserRole]string{
AdminRole: "Admin",
ManagerRole: "Manager",
ViewerRole: "Viewer",
AnyRole: "Any",
}

// HasWriteAccess function checks if the user role has write access
Expand Down Expand Up @@ -81,6 +84,7 @@ var validRoles = map[UserRole]bool{
AdminRole: true,
ManagerRole: true,
ViewerRole: true,
AnyRole: true,
lucasmenendez marked this conversation as resolved.
Show resolved Hide resolved
}

// IsValidUserRole function checks if the user role is valid
Expand Down
13 changes: 3 additions & 10 deletions db/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,9 @@ type UserVerification struct {

func (u *User) HasRoleFor(address string, role UserRole) bool {
for _, org := range u.Organizations {
if org.Address == address && string(org.Role) == string(role) {
return true
}
}
return false
}

func (u *User) IsMemberOf(address string) bool {
for _, org := range u.Organizations {
if org.Address == address {
if org.Address == address &&
// Check if the role is "any: or if the role matches the organization role
(string(role) == string(AnyRole) || string(org.Role) == string(role)) {
return true
}
}
Expand Down
Loading