mirror of
https://gitlab.bertha.cloud/partitio/Nextcloud-Partitio/gonextcloud
synced 2024-11-24 23:36:25 +00:00
Fix quota odd behaviour
This commit is contained in:
parent
4f50c4817a
commit
dd062fe989
@ -166,7 +166,7 @@ var (
|
|||||||
// username := fmt.Sprintf("%s-2", config.NotExistingUser)
|
// username := fmt.Sprintf("%s-2", config.NotExistingUser)
|
||||||
// err := c.Users().Create(username, password, nil)
|
// err := c.Users().Create(username, password, nil)
|
||||||
// assert.NoError(t, err)
|
// assert.NoError(t, err)
|
||||||
// user := &types.Users{
|
// user := &types.UserDetails{
|
||||||
// ID: username,
|
// ID: username,
|
||||||
// Displayname: strings.ToUpper(username),
|
// Displayname: strings.ToUpper(username),
|
||||||
// Email: "some@address.com",
|
// Email: "some@address.com",
|
||||||
@ -174,6 +174,10 @@ var (
|
|||||||
// Twitter: "@me",
|
// Twitter: "@me",
|
||||||
// Phone: "42 42 242 424",
|
// Phone: "42 42 242 424",
|
||||||
// Website: "my.site.com",
|
// Website: "my.site.com",
|
||||||
|
// Quota: types.Quota{
|
||||||
|
// // Unlimited
|
||||||
|
// Quota: -3,
|
||||||
|
// },
|
||||||
// }
|
// }
|
||||||
// err = c.Users().Update(user)
|
// err = c.Users().Update(user)
|
||||||
// assert.NoError(t, err)
|
// assert.NoError(t, err)
|
||||||
@ -314,7 +318,7 @@ var (
|
|||||||
{
|
{
|
||||||
"TestUserUpdateQuota",
|
"TestUserUpdateQuota",
|
||||||
func(t *testing.T) {
|
func(t *testing.T) {
|
||||||
quota := 1024 * 1024 * 1024
|
quota := int64(1024 * 1024 * 1024)
|
||||||
err := c.Users().UpdateQuota(config.NotExistingUser, quota)
|
err := c.Users().UpdateQuota(config.NotExistingUser, quota)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
// TODO : Find better verification : A never connected Users does not have quota available
|
// TODO : Find better verification : A never connected Users does not have quota available
|
||||||
|
@ -113,7 +113,7 @@ type Users interface {
|
|||||||
UpdateWebSite(name string, website string) error
|
UpdateWebSite(name string, website string) error
|
||||||
UpdateTwitter(name string, twitter string) error
|
UpdateTwitter(name string, twitter string) error
|
||||||
UpdatePassword(name string, password string) error
|
UpdatePassword(name string, password string) error
|
||||||
UpdateQuota(name string, quota int) error
|
UpdateQuota(name string, quota int64) error
|
||||||
GroupList(name string) ([]string, error)
|
GroupList(name string) ([]string, error)
|
||||||
GroupAdd(name string, group string) error
|
GroupAdd(name string, group string) error
|
||||||
GroupRemove(name string, group string) error
|
GroupRemove(name string, group string) error
|
||||||
|
@ -394,11 +394,11 @@ func (_m *Users) UpdatePhone(name string, phone string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UpdateQuota provides a mock function with given fields: name, quota
|
// UpdateQuota provides a mock function with given fields: name, quota
|
||||||
func (_m *Users) UpdateQuota(name string, quota int) error {
|
func (_m *Users) UpdateQuota(name string, quota int64) error {
|
||||||
ret := _m.Called(name, quota)
|
ret := _m.Called(name, quota)
|
||||||
|
|
||||||
var r0 error
|
var r0 error
|
||||||
if rf, ok := ret.Get(0).(func(string, int) error); ok {
|
if rf, ok := ret.Get(0).(func(string, int64) error); ok {
|
||||||
r0 = rf(name, quota)
|
r0 = rf(name, quota)
|
||||||
} else {
|
} else {
|
||||||
r0 = ret.Error(0)
|
r0 = ret.Error(0)
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package types
|
package types
|
||||||
|
|
||||||
|
import "strconv"
|
||||||
|
|
||||||
//User encapsulate the data needed to create a new Nextcloud's User
|
//User encapsulate the data needed to create a new Nextcloud's User
|
||||||
type User struct {
|
type User struct {
|
||||||
Username string
|
Username string
|
||||||
@ -38,3 +40,10 @@ type Quota struct {
|
|||||||
Relative float64 `json:"relative"`
|
Relative float64 `json:"relative"`
|
||||||
Quota int64 `json:"quota"`
|
Quota int64 `json:"quota"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (q *Quota) String() string {
|
||||||
|
if q.Quota < 0 {
|
||||||
|
return "none"
|
||||||
|
}
|
||||||
|
return strconv.FormatInt(q.Quota, 10)
|
||||||
|
}
|
||||||
|
25
users.go
25
users.go
@ -10,7 +10,6 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"path"
|
"path"
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
@ -195,8 +194,21 @@ func (u *Users) Update(user *types.UserDetails) error {
|
|||||||
errs := make(chan types.UpdateError)
|
errs := make(chan types.UpdateError)
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
for k := range m {
|
for k := range m {
|
||||||
if !ignoredUserField(k) && m[k].(string) != "" {
|
var value string
|
||||||
|
// Quota is a special case
|
||||||
|
if k == "Quota" {
|
||||||
|
// If empty
|
||||||
|
if user.Quota == (types.Quota{}) {
|
||||||
|
value = "default"
|
||||||
|
} else {
|
||||||
|
value = user.Quota.String()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
value = m[k].(string)
|
||||||
|
}
|
||||||
|
if !ignoredUserField(k) && value != "" {
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
|
// All other non ignored values are strings
|
||||||
go func(key string, value string) {
|
go func(key string, value string) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
if err := u.updateAttribute(user.ID, strings.ToLower(key), value); err != nil {
|
if err := u.updateAttribute(user.ID, strings.ToLower(key), value); err != nil {
|
||||||
@ -205,7 +217,7 @@ func (u *Users) Update(user *types.UserDetails) error {
|
|||||||
Error: err,
|
Error: err,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}(k, m[k].(string))
|
}(k, value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
go func() {
|
go func() {
|
||||||
@ -250,9 +262,10 @@ func (u *Users) UpdatePassword(name string, password string) error {
|
|||||||
return u.updateAttribute(name, "password", password)
|
return u.updateAttribute(name, "password", password)
|
||||||
}
|
}
|
||||||
|
|
||||||
//UpdateQuota update the user's quota (bytes)
|
//UpdateQuota update the user's quota (bytes). Set negative quota for unlimited
|
||||||
func (u *Users) UpdateQuota(name string, quota int) error {
|
func (u *Users) UpdateQuota(name string, quota int64) error {
|
||||||
return u.updateAttribute(name, "quota", strconv.Itoa(quota))
|
q := types.Quota{Quota: quota}
|
||||||
|
return u.updateAttribute(name, "quota", q.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
//GroupList lists the user's groups
|
//GroupList lists the user's groups
|
||||||
|
2
utils.go
2
utils.go
@ -55,5 +55,7 @@ func reformatJSON(json string) string {
|
|||||||
json = strings.Replace(json, "\"false\"", "false", -1)
|
json = strings.Replace(json, "\"false\"", "false", -1)
|
||||||
// Nextcloud encode quota as an empty array for never connected users
|
// Nextcloud encode quota as an empty array for never connected users
|
||||||
json = strings.Replace(json, "\"quota\":[],", "", -1)
|
json = strings.Replace(json, "\"quota\":[],", "", -1)
|
||||||
|
// Nextcloud send admin unlimited quota as -3, others as "none" : replace with negative value
|
||||||
|
json = strings.Replace(json, "\"quota\":\"none\"", "\"quota\":-3", -1)
|
||||||
return json
|
return json
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user