changed permission struct usage.
This commit is contained in:
parent
839a6163da
commit
f11411a988
@ -8,7 +8,7 @@ type Permissions struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Init all of the perms for channel.
|
// Init all of the perms for channel.
|
||||||
func (p *Permissions) InitChannel() {
|
func (p *Permissions) InitChannel() *Permissions {
|
||||||
p.Permissions = map[string]uint{
|
p.Permissions = map[string]uint{
|
||||||
"VIEW": 1 << 0,
|
"VIEW": 1 << 0,
|
||||||
"SEND_MESSAGE": 1 << 1,
|
"SEND_MESSAGE": 1 << 1,
|
||||||
@ -20,10 +20,11 @@ func (p *Permissions) InitChannel() {
|
|||||||
"UPLOAD_FILES": 1 << 7,
|
"UPLOAD_FILES": 1 << 7,
|
||||||
}
|
}
|
||||||
p.Mode = "CHANNEL"
|
p.Mode = "CHANNEL"
|
||||||
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
// Init all of the perms for user.
|
// Init all of the perms for user.
|
||||||
func (p *Permissions) InitUser() {
|
func (p *Permissions) InitUser() *Permissions {
|
||||||
p.Permissions = map[string]uint{
|
p.Permissions = map[string]uint{
|
||||||
"ACCESS": 1 << 0,
|
"ACCESS": 1 << 0,
|
||||||
"VIEW_PROFILE": 1 << 1,
|
"VIEW_PROFILE": 1 << 1,
|
||||||
@ -31,10 +32,11 @@ func (p *Permissions) InitUser() {
|
|||||||
"INVITE": 1 << 3,
|
"INVITE": 1 << 3,
|
||||||
}
|
}
|
||||||
p.Mode = "USER"
|
p.Mode = "USER"
|
||||||
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
// Init all of the perms for server.
|
// Init all of the perms for server.
|
||||||
func (p *Permissions) InitServer() {
|
func (p *Permissions) InitServer() *Permissions {
|
||||||
p.Permissions = map[string]uint{
|
p.Permissions = map[string]uint{
|
||||||
"VIEW": 1 << 0,
|
"VIEW": 1 << 0,
|
||||||
"MANAGE_ROLES": 1 << 1,
|
"MANAGE_ROLES": 1 << 1,
|
||||||
@ -49,6 +51,7 @@ func (p *Permissions) InitServer() {
|
|||||||
"REMOVE_AVATARS": 1 << 15,
|
"REMOVE_AVATARS": 1 << 15,
|
||||||
}
|
}
|
||||||
p.Mode = "SERVER"
|
p.Mode = "SERVER"
|
||||||
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate if bitvise has permission
|
// Calculate if bitvise has permission
|
||||||
@ -60,6 +63,17 @@ func (p Permissions) Has(perm string) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add new permission(s).
|
||||||
|
func (p *Permissions) Add(perms ...string) *Permissions {
|
||||||
|
for _, perm := range perms {
|
||||||
|
if value, ok := p.Permissions[perm]; ok {
|
||||||
|
p.Bitvise = p.Bitvise | value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
// Calculate perms and return unsigned int.
|
// Calculate perms and return unsigned int.
|
||||||
func (p Permissions) Calculate(perms ...string) uint {
|
func (p Permissions) Calculate(perms ...string) uint {
|
||||||
var total uint
|
var total uint
|
||||||
|
@ -277,7 +277,7 @@ func (s Server) SetPermissions(role_id string, channel_permissions, server_permi
|
|||||||
role_id = "default"
|
role_id = "default"
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := c.Client.Request("PUT", "/servers/"+s.Id+"/permissions/"+role_id, []byte(fmt.Sprintf("{\"permissions\":{\"server\":%d,\"channel\":%d}}", channel_permissions, server_permissions)))
|
_, err := s.Client.Request("PUT", "/servers/"+s.Id+"/permissions/"+role_id, []byte(fmt.Sprintf("{\"permissions\":{\"server\":%d,\"channel\":%d}}", channel_permissions, server_permissions)))
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
Loading…
x
Reference in New Issue
Block a user