Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
galene
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
galene
Commits
6bdcd504
Commit
6bdcd504
authored
Sep 08, 2022
by
Juliusz Chroboczek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make GetPermission a method of Group.
parent
0fe3ed2e
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
12 deletions
+20
-12
group/group.go
group/group.go
+15
-7
webserver/webserver.go
webserver/webserver.go
+5
-5
No files found.
group/group.go
View file @
6bdcd504
...
...
@@ -563,7 +563,7 @@ func AddClient(group string, c Client, creds ClientCredentials) (*Group, error)
clients
:=
g
.
getClientsUnlocked
(
nil
)
if
!
member
(
"system"
,
c
.
Permissions
())
{
username
,
perms
,
err
:=
g
.
description
.
GetPermission
(
group
,
creds
)
username
,
perms
,
err
:=
g
.
getPermission
(
creds
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -815,7 +815,7 @@ func (g *Group) GetChatHistory() []ChatHistoryEntry {
return
h
}
func
matchClient
(
group
string
,
creds
ClientCredentials
,
users
[]
ClientPattern
)
(
bool
,
bool
)
{
func
matchClient
(
creds
ClientCredentials
,
users
[]
ClientPattern
)
(
bool
,
bool
)
{
matched
:=
false
for
_
,
u
:=
range
users
{
if
u
.
Username
==
creds
.
Username
{
...
...
@@ -1103,12 +1103,14 @@ func readDescription(name string) (*Description, error) {
return
&
desc
,
nil
}
func
(
desc
*
Description
)
GetPermission
(
group
string
,
creds
ClientCredentials
)
(
string
,
[]
string
,
error
)
{
// called locked
func
(
g
*
Group
)
getPermission
(
creds
ClientCredentials
)
(
string
,
[]
string
,
error
)
{
desc
:=
g
.
description
if
creds
.
Token
==
""
{
if
!
desc
.
AllowAnonymous
&&
creds
.
Username
==
""
{
return
""
,
nil
,
ErrAnonymousNotAuthorised
}
if
found
,
good
:=
matchClient
(
group
,
creds
,
desc
.
Op
);
found
{
if
found
,
good
:=
matchClient
(
creds
,
desc
.
Op
);
found
{
if
good
{
var
p
[]
string
p
=
[]
string
{
"op"
,
"present"
}
...
...
@@ -1119,13 +1121,13 @@ func (desc *Description) GetPermission(group string, creds ClientCredentials) (s
}
return
""
,
nil
,
ErrNotAuthorised
}
if
found
,
good
:=
matchClient
(
group
,
creds
,
desc
.
Presenter
);
found
{
if
found
,
good
:=
matchClient
(
creds
,
desc
.
Presenter
);
found
{
if
good
{
return
creds
.
Username
,
[]
string
{
"present"
},
nil
}
return
""
,
nil
,
ErrNotAuthorised
}
if
found
,
good
:=
matchClient
(
group
,
creds
,
desc
.
Other
);
found
{
if
found
,
good
:=
matchClient
(
creds
,
desc
.
Other
);
found
{
if
good
{
return
creds
.
Username
,
nil
,
nil
}
...
...
@@ -1164,7 +1166,7 @@ func (desc *Description) GetPermission(group string, creds ClientCredentials) (s
continue
}
}
if
url
.
Path
==
path
.
Join
(
"/group"
,
g
roup
)
+
"/"
{
if
url
.
Path
==
path
.
Join
(
"/group"
,
g
.
name
)
+
"/"
{
ok
=
true
break
}
...
...
@@ -1175,6 +1177,12 @@ func (desc *Description) GetPermission(group string, creds ClientCredentials) (s
return
sub
,
perms
,
nil
}
func
(
g
*
Group
)
GetPermission
(
creds
ClientCredentials
)
(
string
,
[]
string
,
error
)
{
g
.
mu
.
Lock
()
defer
g
.
mu
.
Unlock
()
return
g
.
getPermission
(
creds
)
}
type
Status
struct
{
Name
string
`json:"name"`
Location
string
`json:"location"`
...
...
webserver/webserver.go
View file @
6bdcd504
...
...
@@ -591,17 +591,17 @@ func handleGroupAction(w http.ResponseWriter, r *http.Request, group string) {
}
func
checkGroupPermissions
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
groupname
string
)
bool
{
desc
,
err
:=
group
.
GetDescription
(
groupname
)
if
err
!=
nil
{
user
,
pass
,
ok
:=
r
.
BasicAuth
(
)
if
!
ok
{
return
false
}
user
,
pass
,
ok
:=
r
.
BasicAuth
(
)
if
!
ok
{
g
:=
group
.
Get
(
groupname
)
if
g
==
nil
{
return
false
}
_
,
p
,
err
:=
desc
.
GetPermission
(
groupname
,
_
,
p
,
err
:=
g
.
GetPermission
(
group
.
ClientCredentials
{
Username
:
user
,
Password
:
pass
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment