-
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.
Signed-off-by: maxwellgithinji <maxwellgithinji@gmail.com>
- Loading branch information
1 parent
d4648c5
commit 7320fb5
Showing
16 changed files
with
383 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package enums | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
// RolesType is a list of all the role types. | ||
type RolesType string | ||
|
||
// contacts type constants | ||
const ( | ||
RolesTypeCanRegisterStaff RolesType = "CAN_REGISTER_STAFF" | ||
RolesTypeCanInviteStaff RolesType = "CAN_INVITE_STAFF" | ||
RolesTypeCanSuspendStaff RolesType = "CAN_SUSPEND_STAFF" | ||
RolesTypeCanActivateStaff RolesType = "CAN_ACTIVATE_STAFF" | ||
RolesTypeCanDeleteStaff RolesType = "CAN_DELETE_STAFF" | ||
RolesTypeCanInactivateStaff RolesType = "CAN_INACTIVATE_STAFF" | ||
|
||
RolesTypeCanRegisterClient RolesType = "CAN_REGISTER_CLIENT" | ||
RolesTypeCanInviteClient RolesType = "CAN_INVITE_CLIENT" | ||
RolesTypeCanSuspendClient RolesType = "CAN_SUSPEND_CLIENT" | ||
RolesTypeCanActivateClient RolesType = "CAN_ACTIVATE_CLIENT" | ||
RolesTypeCanDeleteClient RolesType = "CAN_DELETE_CLIENT" | ||
RolesTypeCanInactivateClient RolesType = "CAN_INACTIVATE_CLIENT" | ||
) | ||
|
||
// AllRoles is a set of a valid and known role types. | ||
var AllRoles = []RolesType{ | ||
RolesTypeCanRegisterStaff, | ||
RolesTypeCanInviteStaff, | ||
RolesTypeCanSuspendStaff, | ||
RolesTypeCanActivateStaff, | ||
RolesTypeCanDeleteStaff, | ||
RolesTypeCanInactivateStaff, | ||
|
||
RolesTypeCanRegisterClient, | ||
RolesTypeCanInviteClient, | ||
RolesTypeCanSuspendClient, | ||
RolesTypeCanActivateClient, | ||
RolesTypeCanDeleteClient, | ||
RolesTypeCanInactivateClient, | ||
} | ||
|
||
// IsValid returns true if a role is valid | ||
func (m RolesType) IsValid() bool { | ||
switch m { | ||
case RolesTypeCanRegisterStaff, | ||
RolesTypeCanInviteStaff, | ||
RolesTypeCanSuspendStaff, | ||
RolesTypeCanActivateStaff, | ||
RolesTypeCanDeleteStaff, | ||
RolesTypeCanInactivateStaff, | ||
|
||
RolesTypeCanRegisterClient, | ||
RolesTypeCanInviteClient, | ||
RolesTypeCanSuspendClient, | ||
RolesTypeCanActivateClient, | ||
RolesTypeCanDeleteClient, | ||
RolesTypeCanInactivateClient: | ||
return true | ||
} | ||
return false | ||
} | ||
|
||
// String converts roles to string. | ||
func (m RolesType) String() string { | ||
return string(m) | ||
} | ||
|
||
// UnmarshalGQL converts the supplied value to a role type. | ||
func (m *RolesType) UnmarshalGQL(v interface{}) error { | ||
str, ok := v.(string) | ||
if !ok { | ||
return fmt.Errorf("enums must be strings") | ||
} | ||
|
||
*m = RolesType(str) | ||
if !m.IsValid() { | ||
return fmt.Errorf("%s is not a valid RolesType", str) | ||
} | ||
return nil | ||
} |
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
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
Oops, something went wrong.