Skip to content

Commit 4d2276b

Browse files
committed
fix #27
1 parent 4f972df commit 4d2276b

3 files changed

Lines changed: 28 additions & 8 deletions

File tree

handlers/File.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,26 @@ func FileHandler(handlerData web.HandlerData, w http.ResponseWriter, r *http.Req
4141

4242
// Apply group filter
4343
if len(request.Attributes.Groups) > 0 {
44+
var newFiles []models.File
45+
for i := range files {
46+
if files[i].IsInGroupList(request.Attributes.Groups) {
47+
newFiles = append(newFiles, files[i])
48+
}
49+
}
50+
51+
files = newFiles
52+
}
53+
54+
// Apply tag filter
55+
if len(request.Attributes.Tags) > 0 {
56+
var newFiles []models.File
57+
for i := range files {
58+
if files[i].IsInTagList(request.Attributes.Tags) {
59+
newFiles = append(newFiles, files[i])
60+
}
61+
}
4462

63+
files = newFiles
4564
}
4665

4766
// Exit if no file was found

models/File.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,25 +93,27 @@ func (file File) GetNamespace() *Namespace {
9393

9494
// IsInTagList return true if file has one of the specified tags
9595
func (file File) IsInTagList(tags []string) bool {
96-
for _, tag := range file.Tags {
97-
for _, t1 := range tags {
98-
if tag.Name == t1 {
96+
for i := range file.Tags {
97+
for j := range tags {
98+
if file.Tags[i].Name == tags[j] {
9999
return true
100100
}
101101
}
102102
}
103+
103104
return false
104105
}
105106

106107
// IsInGroupList return true if file is in one of the specified groups
107108
func (file File) IsInGroupList(groups []string) bool {
108-
for _, group := range file.Groups {
109-
for _, t1 := range groups {
110-
if group.Name == t1 {
109+
for i := range file.Groups {
110+
for j := range groups {
111+
if file.Groups[i].Name == groups[j] {
111112
return true
112113
}
113114
}
114115
}
116+
115117
return false
116118
}
117119

@@ -171,6 +173,7 @@ func FilesByName(db *gorm.DB, userID, namespace uint, fileName string) ([]File,
171173

172174
// Get file
173175
var file []File
176+
174177
err := a.Find(&file).Error
175178
if err != nil {
176179
return nil, err

storage/Database.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ func ConnectToDatabase(config *models.Config) (*gorm.DB, error) {
2121
return nil, err
2222
}
2323

24-
// db = db.Debug()
25-
2624
//Automigration
2725
db.AutoMigrate(
2826
&models.Role{},

0 commit comments

Comments
 (0)