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
29bd67cc
Commit
29bd67cc
authored
Nov 22, 2020
by
Juliusz Chroboczek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement subgroups.
parent
dcfd071e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
21 deletions
+64
-21
README
README
+2
-0
group/group.go
group/group.go
+62
-21
No files found.
README
View file @
29bd67cc
...
...
@@ -119,6 +119,8 @@ fields, all of which are optional.
kept (default 14400, i.e. 4 hours);
- `allow-recording`: if true, then recording is allowed in this group;
- `allow-anonymous`: if true, then users may connect with an empty username.
- `allow-subgroups`: if true, then subgroups of the form `group/subgroup`
are automatically created when accessed.
- `redirect`: if set, then attempts to join the group will be redirected
to the given URL; most other fields are ignored in this case.
...
...
group/group.go
View file @
29bd67cc
...
...
@@ -9,6 +9,7 @@ import (
"encoding/json"
"log"
"os"
"path"
"path/filepath"
"sort"
"strings"
...
...
@@ -198,16 +199,7 @@ func Add(name string, desc *description) (*Group, error) {
}
if
g
.
dead
||
time
.
Since
(
g
.
description
.
loadTime
)
>
5
*
time
.
Second
{
changed
,
err
:=
descriptionChanged
(
name
,
g
.
description
)
if
err
!=
nil
{
if
!
os
.
IsNotExist
(
err
)
{
log
.
Printf
(
"Reading group %v: %v"
,
name
,
err
)
}
g
.
dead
=
true
delGroupUnlocked
(
name
)
return
nil
,
err
}
if
changed
{
if
descriptionChanged
(
name
,
g
.
description
)
{
desc
,
err
:=
GetDescription
(
name
)
if
err
!=
nil
{
if
!
os
.
IsNotExist
(
err
)
{
...
...
@@ -478,6 +470,7 @@ func matchUser(user ClientCredentials, users []ClientCredentials) (bool, bool) {
}
type
description
struct
{
fileName
string
`json:"-"`
loadTime
time
.
Time
`json:"-"`
modTime
time
.
Time
`json:"-"`
fileSize
int64
`json:"-"`
...
...
@@ -485,27 +478,65 @@ type description struct {
Redirect
string
`json:"redirect,omitempty"`
Public
bool
`json:"public,omitempty"`
MaxClients
int
`json:"max-clients,omitempty"`
MaxHistoryAge
int
`json:"max-history-age
",omitempty
`
MaxHistoryAge
int
`json:"max-history-age
,omitempty"
`
AllowAnonymous
bool
`json:"allow-anonymous,omitempty"`
AllowRecording
bool
`json:"allow-recording,omitempty"`
AllowSubgroups
bool
`json:"allow-subgroups,omitempty"`
Op
[]
ClientCredentials
`json:"op,omitempty"`
Presenter
[]
ClientCredentials
`json:"presenter,omitempty"`
Other
[]
ClientCredentials
`json:"other,omitempty"`
}
func
descriptionChanged
(
name
string
,
old
*
description
)
(
bool
,
error
)
{
fi
,
err
:=
os
.
Stat
(
filepath
.
Join
(
Directory
,
name
+
".json"
))
if
err
!=
nil
{
return
false
,
err
func
openDescriptionFile
(
name
string
)
(
*
os
.
File
,
string
,
bool
,
error
)
{
isParent
:=
false
for
name
!=
""
{
fileName
:=
filepath
.
Join
(
Directory
,
path
.
Clean
(
"/"
+
name
)
+
".json"
,
)
r
,
err
:=
os
.
Open
(
fileName
)
if
!
os
.
IsNotExist
(
err
)
{
return
r
,
fileName
,
isParent
,
err
}
isParent
=
true
name
,
_
=
path
.
Split
(
name
)
name
=
strings
.
TrimRight
(
name
,
"/"
)
}
if
fi
.
Size
()
!=
old
.
fileSize
||
fi
.
ModTime
()
!=
old
.
modTime
{
return
true
,
err
return
nil
,
""
,
false
,
os
.
ErrNotExist
}
func
statDescriptionFile
(
name
string
)
(
os
.
FileInfo
,
string
,
bool
,
error
)
{
isParent
:=
false
for
name
!=
""
{
fileName
:=
filepath
.
Join
(
Directory
,
path
.
Clean
(
"/"
+
name
)
+
".json"
,
)
fi
,
err
:=
os
.
Stat
(
fileName
)
if
!
os
.
IsNotExist
(
err
)
{
return
fi
,
fileName
,
isParent
,
err
}
isParent
=
true
name
,
_
=
path
.
Split
(
name
)
name
=
strings
.
TrimRight
(
name
,
"/"
)
}
return
false
,
err
return
nil
,
""
,
false
,
os
.
ErrNotExist
}
// descriptionChanged returns true if a group's description may have
// changed since it was last read.
func
descriptionChanged
(
name
string
,
desc
*
description
)
bool
{
fi
,
fileName
,
_
,
err
:=
statDescriptionFile
(
name
)
if
err
!=
nil
||
fileName
!=
desc
.
fileName
{
return
true
}
if
fi
.
Size
()
!=
desc
.
fileSize
||
fi
.
ModTime
()
!=
desc
.
modTime
{
return
true
}
return
false
}
func
GetDescription
(
name
string
)
(
*
description
,
error
)
{
r
,
err
:=
os
.
Open
(
filepath
.
Join
(
Directory
,
name
+
".json"
)
)
r
,
fileName
,
isParent
,
err
:=
openDescriptionFile
(
name
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -517,15 +548,25 @@ func GetDescription(name string) (*description, error) {
if
err
!=
nil
{
return
nil
,
err
}
desc
.
fileSize
=
fi
.
Size
()
desc
.
modTime
=
fi
.
ModTime
()
d
:=
json
.
NewDecoder
(
r
)
err
=
d
.
Decode
(
&
desc
)
if
err
!=
nil
{
return
nil
,
err
}
if
isParent
{
if
!
desc
.
AllowSubgroups
{
return
nil
,
os
.
ErrNotExist
}
desc
.
Public
=
false
desc
.
Description
=
""
}
desc
.
fileName
=
fileName
desc
.
fileSize
=
fi
.
Size
()
desc
.
modTime
=
fi
.
ModTime
()
desc
.
loadTime
=
time
.
Now
()
return
&
desc
,
nil
}
...
...
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