package common import "strings" // These are the various privileges a token can have. const ( PrivilegeRead = 1 << iota // used to be to fetch public data, such as user information etc. this is deprecated. PrivilegeReadConfidential // (eventual) private messages, reports... of self PrivilegeWrite // change user information, write into confidential stuff... PrivilegeManageBadges // can change various users' badges. PrivilegeBetaKeys // can add, remove, upgrade/downgrade, make public beta keys. PrivilegeManageSettings // maintainance, set registrations, global alerts, bancho settings PrivilegeViewUserAdvanced // can see user email, and perhaps warnings in the future, basically. PrivilegeManageUser // can change user email, allowed status, userpage, rank, username... PrivilegeManageRoles // translates as admin, as they can basically assign roles to anyone, even themselves PrivilegeManageAPIKeys // admin permission to manage user permission, not only self permissions. Only ever do this if you completely trust the application, because this essentially means to put the entire ripple database in the hands of a (potentially evil?) application. PrivilegeBlog // can do pretty much anything to the blog, and the documentation. PrivilegeAPIMeta // can do /meta API calls. basically means they can restart the API server. PrivilegeBeatmap // rank/unrank beatmaps. also BAT when implemented ) // Privileges is a bitwise enum of the privileges of an user's API key. type Privileges uint64 var privilegeString = [...]string{ "Read", "ReadConfidential", "Write", "ManageBadges", "BetaKeys", "ManageSettings", "ViewUserAdvanced", "ManageUser", "ManageRoles", "ManageAPIKeys", "Blog", "APIMeta", "Beatmap", } func (p Privileges) String() string { var pvs []string for i, v := range privilegeString { if uint64(p)&uint64(1<>= 1 } return Privileges(newPrivilege) } var privilegeMap = map[string]Privileges{ "read_confidential": PrivilegeReadConfidential, "write": PrivilegeWrite, } // OAuthPrivileges returns the equivalent in Privileges of a space-separated // list of scopes. func OAuthPrivileges(scopes string) Privileges { var p Privileges for _, x := range strings.Split(scopes, " ") { p |= privilegeMap[x] } return p }