-
-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added permission model for API keys #79, replaced button text with icons
- Loading branch information
Showing
24 changed files
with
599 additions
and
58 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 |
---|---|---|
@@ -1,9 +1,51 @@ | ||
package models | ||
|
||
const ( | ||
ApiPermView = 1 << iota // upper case | ||
ApiPermUpload // lower case | ||
ApiPermDelete // capitalizes | ||
ApiPermApiMod // reverses | ||
) | ||
|
||
const ApiPermNone = 0 | ||
const ApiPermAllNoApiMod = 7 | ||
const ApiPermAll = 15 | ||
|
||
// ApiKey contains data of a single api key | ||
type ApiKey struct { | ||
Id string `json:"Id"` | ||
FriendlyName string `json:"FriendlyName"` | ||
LastUsed int64 `json:"LastUsed"` | ||
LastUsedString string `json:"LastUsedString"` | ||
LastUsed int64 `json:"LastUsed"` | ||
Permissions uint8 `json:"Permissions"` | ||
} | ||
|
||
func (key *ApiKey) SetPermission(permission uint8) { | ||
key.Permissions |= permission | ||
} | ||
func (key *ApiKey) RemovePermission(permission uint8) { | ||
key.Permissions &^= permission | ||
} | ||
|
||
func (key *ApiKey) HasPermission(permission uint8) bool { | ||
if permission == ApiPermNone { | ||
return true | ||
} | ||
return (key.Permissions & permission) == permission | ||
} | ||
|
||
func (key *ApiKey) HasPermissionView() bool { | ||
return key.HasPermission(ApiPermView) | ||
} | ||
|
||
func (key *ApiKey) HasPermissionUpload() bool { | ||
return key.HasPermission(ApiPermUpload) | ||
} | ||
|
||
func (key *ApiKey) HasPermissionDelete() bool { | ||
return key.HasPermission(ApiPermDelete) | ||
} | ||
|
||
func (key *ApiKey) HasPermissionApiMod() bool { | ||
return key.HasPermission(ApiPermApiMod) | ||
} |
Oops, something went wrong.