Merge pull request #34 from owncloud/add-uid-gid

Add UidNumber and GidNumber when creating new user
This commit is contained in:
Dipak Acharya
2020-08-10 15:11:35 +05:45
committed by GitHub
3 changed files with 55 additions and 11 deletions

View File

@@ -0,0 +1,5 @@
Enhancement: Add option to create user with uidnumber and gidnumber
We have added an option to pass uidnumber and gidnumber to the ocis api while creating a new user
https://github.com/owncloud/ocis-ocs/pull/34

View File

@@ -14,6 +14,8 @@ type User struct {
DisplayName string `json:"displayname" xml:"displayname"`
Email string `json:"email" xml:"email"`
Quota *Quota `json:"quota" xml:"quota"`
UIDNumber int64 `json:"uidnumber" xml:"uidnumber"`
GIDNumber int64 `json:"gidnumber" xml:"gidnumber"`
}
// Quota holds quota information

View File

@@ -5,6 +5,7 @@ import (
"encoding/hex"
"fmt"
"net/http"
"strconv"
"strings"
"github.com/cs3org/reva/pkg/user"
@@ -60,6 +61,8 @@ func (o Ocs) GetUser(w http.ResponseWriter, r *http.Request) {
Username: account.PreferredName,
DisplayName: account.DisplayName,
Email: account.Mail,
UIDNumber: account.UidNumber,
GIDNumber: account.GidNumber,
Enabled: account.AccountEnabled,
// FIXME only return quota for users/{userid} endpoint (not /user)
// TODO query storage registry for free space? of home storage, maybe...
@@ -81,6 +84,28 @@ func (o Ocs) AddUser(w http.ResponseWriter, r *http.Request) {
username := r.PostFormValue("username")
displayname := r.PostFormValue("displayname")
email := r.PostFormValue("email")
uid := r.PostFormValue("uidnumber")
gid := r.PostFormValue("gidnumber")
var uidNumber, gidNumber int64
var err error
if uid != "" {
uidNumber, err = strconv.ParseInt(uid, 10, 64)
if err != nil {
render.Render(w, r, response.ErrRender(data.MetaBadRequest.StatusCode, "Cannot use the uidnumber provided"))
o.logger.Error().Err(err).Str("userid", userid).Msg("Cannot use the uidnumber provided")
return
}
}
if gid != "" {
gidNumber, err = strconv.ParseInt(gid, 10, 64)
if err != nil {
render.Render(w, r, response.ErrRender(data.MetaBadRequest.StatusCode, "Cannot use the gidnumber provided"))
o.logger.Error().Err(err).Str("userid", userid).Msg("Cannot use the gidnumber provided")
return
}
}
// fallbacks
/* TODO decide if we want to make these fallbacks. Keep in mind:
@@ -94,18 +119,28 @@ func (o Ocs) AddUser(w http.ResponseWriter, r *http.Request) {
}
*/
account, err := o.getAccountService().CreateAccount(r.Context(), &accounts.CreateAccountRequest{
Account: &accounts.Account{
DisplayName: displayname,
PreferredName: username,
OnPremisesSamAccountName: username,
PasswordProfile: &accounts.PasswordProfile{
Password: password,
},
Id: userid,
Mail: email,
AccountEnabled: true,
newAccount := &accounts.Account{
DisplayName: displayname,
PreferredName: username,
OnPremisesSamAccountName: username,
PasswordProfile: &accounts.PasswordProfile{
Password: password,
},
Id: userid,
Mail: email,
AccountEnabled: true,
}
if uidNumber != 0 {
newAccount.UidNumber = uidNumber
}
if gidNumber != 0 {
newAccount.GidNumber = gidNumber
}
account, err := o.getAccountService().CreateAccount(r.Context(), &accounts.CreateAccountRequest{
Account: newAccount,
})
if err != nil {
merr := merrors.FromError(err)
@@ -130,6 +165,8 @@ func (o Ocs) AddUser(w http.ResponseWriter, r *http.Request) {
Username: account.PreferredName,
DisplayName: account.DisplayName,
Email: account.Mail,
UIDNumber: account.UidNumber,
GIDNumber: account.UidNumber,
Enabled: account.AccountEnabled,
}))
}