diff --git a/common/commit-mgr.c b/common/commit-mgr.c index 4ba3e4f6..50c188f3 100644 --- a/common/commit-mgr.c +++ b/common/commit-mgr.c @@ -64,6 +64,7 @@ seaf_commit_new (const char *commit_id, const char *repo_id, const char *root_id, const char *creator_name, + const char *username, const char *creator_id, const char *desc, guint64 ctime) @@ -86,6 +87,8 @@ seaf_commit_new (const char *commit_id, memcpy (commit->creator_id, creator_id, 40); commit->creator_id[40] = '\0'; + commit->username = g_strdup (username); + commit->desc = g_strdup (desc); if (ctime == 0) { @@ -608,6 +611,8 @@ commit_to_json_object (SeafCommit *commit) json_object_set_string_member (object, "repo_id", commit->repo_id); if (commit->creator_name) json_object_set_string_member (object, "creator_name", commit->creator_name); + if (commit->username) + json_object_set_string_member (object, "username", commit->username); json_object_set_string_member (object, "creator", commit->creator_id); json_object_set_string_member (object, "description", commit->desc); json_object_set_int_member (object, "ctime", (gint64)commit->ctime); @@ -661,6 +666,7 @@ commit_from_json_object (const char *commit_id, json_t *object) const char *root_id; const char *repo_id; const char *creator_name = NULL; + const char *username = NULL; const char *creator; const char *desc; gint64 ctime; @@ -684,6 +690,8 @@ commit_from_json_object (const char *commit_id, json_t *object) repo_id = json_object_get_string_member (object, "repo_id"); if (json_object_has_member (object, "creator_name")) creator_name = json_object_get_string_or_null_member (object, "creator_name"); + if (json_object_has_member (object, "username")) + username = json_object_get_string_or_null_member (object, "username"); creator = json_object_get_string_member (object, "creator"); desc = json_object_get_string_member (object, "description"); if (!desc) @@ -775,7 +783,7 @@ commit_from_json_object (const char *commit_id, json_t *object) char *creator_name_l = creator_name ? g_ascii_strdown (creator_name, -1) : NULL; commit = seaf_commit_new (commit_id, repo_id, root_id, - creator_name_l, creator, desc, ctime); + creator_name_l, username, creator, desc, ctime); g_free (creator_name_l); commit->parent_id = parent_id ? g_strdup(parent_id) : NULL; diff --git a/common/commit-mgr.h b/common/commit-mgr.h index 27842307..d79cdbeb 100644 --- a/common/commit-mgr.h +++ b/common/commit-mgr.h @@ -20,7 +20,8 @@ struct _SeafCommit { char repo_id[37]; char root_id[41]; /* the fs root */ char *desc; - char *creator_name; + char *creator_name; // creator_name is user's email. + char *username; // username is user's friendly username. char creator_id[41]; guint64 ctime; /* creation time */ char *parent_id; @@ -56,6 +57,7 @@ seaf_commit_new (const char *commit_id, const char *repo_id, const char *root_id, const char *author_name, + const char *username, const char *creator_id, const char *desc, guint64 ctime); diff --git a/common/merge-new.c b/common/merge-new.c index 3d5a2e88..b7c17e57 100644 --- a/common/merge-new.c +++ b/common/merge-new.c @@ -71,7 +71,11 @@ merge_conflict_dirname (const char *store_id, int version, opt->remote_repo_id, opt->remote_head); goto out; } - modifier = g_strdup(commit->creator_name); + if (commit->username) { + modifier = g_strdup(commit->username); + } else { + modifier = g_strdup(commit->creator_name); + } seaf_commit_unref (commit); conflict_name = gen_conflict_path (dirname, modifier, (gint64)time(NULL)); diff --git a/common/rpc-service.c b/common/rpc-service.c index 239f2be6..0767ec9a 100644 --- a/common/rpc-service.c +++ b/common/rpc-service.c @@ -1073,6 +1073,7 @@ seafile_change_repo_passwd (const char *repo_id, repo->id, parent->root_id, user, + NULL, EMPTY_SHA1, "Changed library password", 0); @@ -1398,6 +1399,7 @@ seafile_web_get_access_token (const char *repo_id, const char *obj_id, const char *op, const char *username, + const char *friendly_name, int use_onetime, GError **error) { @@ -1410,7 +1412,8 @@ seafile_web_get_access_token (const char *repo_id, token = seaf_web_at_manager_get_access_token (seaf->web_at_mgr, repo_id, obj_id, op, - username, use_onetime, error); + username, friendly_name, + use_onetime, error); return token; } @@ -2345,6 +2348,7 @@ int seafile_revert_on_server (const char *repo_id, const char *commit_id, const char *user_name, + const char *friendly_name, GError **error) { if (!repo_id || strlen(repo_id) != 36 || @@ -2369,13 +2373,14 @@ seafile_revert_on_server (const char *repo_id, repo_id, commit_id, user_name, + friendly_name, error); } int seafile_post_file (const char *repo_id, const char *temp_file_path, const char *parent_dir, const char *file_name, - const char *user, + const char *user, const char *friendly_name, GError **error) { char *norm_parent_dir = NULL, *norm_file_name = NULL, *rpath = NULL; @@ -2412,7 +2417,7 @@ seafile_post_file (const char *repo_id, const char *temp_file_path, if (seaf_repo_manager_post_file (seaf->repo_mgr, repo_id, temp_file_path, rpath, - norm_file_name, user, + norm_file_name, user, friendly_name, error) < 0) { ret = -1; } @@ -2493,6 +2498,7 @@ seafile_post_multi_files (const char *repo_id, const char *filenames_json, const char *paths_json, const char *user, + const char *friendly_name, int replace_existed, GError **error) { @@ -2525,6 +2531,7 @@ seafile_post_multi_files (const char *repo_id, filenames_json, paths_json, user, + friendly_name, replace_existed, &ret_json, NULL, @@ -2540,7 +2547,8 @@ seafile_post_multi_files (const char *repo_id, char * seafile_put_file (const char *repo_id, const char *temp_file_path, const char *parent_dir, const char *file_name, - const char *user, const char *head_id, + const char *user, const char *friendly_name, + const char *head_id, GError **error) { char *norm_parent_dir = NULL, *norm_file_name = NULL, *rpath = NULL; @@ -2575,7 +2583,7 @@ seafile_put_file (const char *repo_id, const char *temp_file_path, seaf_repo_manager_put_file (seaf->repo_mgr, repo_id, temp_file_path, rpath, - norm_file_name, user, head_id, + norm_file_name, user, friendly_name, head_id, &new_file_id, error); out: @@ -2640,6 +2648,7 @@ seafile_put_file (const char *repo_id, const char *temp_file_path, int seafile_post_dir (const char *repo_id, const char *parent_dir, const char *new_dir_name, const char *user, + const char *friendly_name, GError **error) { char *norm_parent_dir = NULL, *norm_dir_name = NULL, *rpath = NULL; @@ -2675,7 +2684,7 @@ seafile_post_dir (const char *repo_id, const char *parent_dir, if (seaf_repo_manager_post_dir (seaf->repo_mgr, repo_id, rpath, norm_dir_name, - user, error) < 0) { + user, friendly_name, error) < 0) { ret = -1; } @@ -2690,6 +2699,7 @@ seafile_post_dir (const char *repo_id, const char *parent_dir, int seafile_post_empty_file (const char *repo_id, const char *parent_dir, const char *new_file_name, const char *user, + const char *friendly_name, GError **error) { char *norm_parent_dir = NULL, *norm_file_name = NULL, *rpath = NULL; @@ -2725,7 +2735,7 @@ seafile_post_empty_file (const char *repo_id, const char *parent_dir, if (seaf_repo_manager_post_empty_file (seaf->repo_mgr, repo_id, rpath, norm_file_name, - user, error) < 0) { + user, friendly_name, error) < 0) { ret = -1; } @@ -2740,6 +2750,7 @@ seafile_post_empty_file (const char *repo_id, const char *parent_dir, int seafile_del_file (const char *repo_id, const char *parent_dir, const char *file_name, const char *user, + const char *friendly_name, GError **error) { char *norm_parent_dir = NULL, *norm_file_name = NULL, *rpath = NULL; @@ -2775,7 +2786,7 @@ seafile_del_file (const char *repo_id, const char *parent_dir, if (seaf_repo_manager_del_file (seaf->repo_mgr, repo_id, rpath, norm_file_name, - user, error) < 0) { + user, friendly_name, error) < 0) { ret = -1; } @@ -2795,6 +2806,7 @@ seafile_copy_file (const char *src_repo_id, const char *dst_dir, const char *dst_filename, const char *user, + const char *friendly_name, int need_progress, int synchronous, GError **error) @@ -2849,7 +2861,7 @@ seafile_copy_file (const char *src_repo_id, ret = (GObject *)seaf_repo_manager_copy_multiple_files (seaf->repo_mgr, src_repo_id, rsrc_dir, norm_src_filename, dst_repo_id, rdst_dir, norm_dst_filename, - user, need_progress, synchronous, + user, friendly_name, need_progress, synchronous, error); out: @@ -2872,6 +2884,7 @@ seafile_move_file (const char *src_repo_id, const char *dst_filename, int replace, const char *user, + const char *friendly_name, int need_progress, int synchronous, GError **error) @@ -2926,7 +2939,7 @@ seafile_move_file (const char *src_repo_id, ret = (GObject *)seaf_repo_manager_move_multiple_files (seaf->repo_mgr, src_repo_id, rsrc_dir, norm_src_filename, dst_repo_id, rdst_dir, norm_dst_filename, - replace, user, need_progress, synchronous, + replace, user, friendly_name, need_progress, synchronous, error); out: @@ -2958,6 +2971,7 @@ seafile_rename_file (const char *repo_id, const char *oldname, const char *newname, const char *user, + const char *friendly_name, GError **error) { char *norm_parent_dir = NULL, *norm_oldname = NULL, *norm_newname = NULL; @@ -3002,7 +3016,7 @@ seafile_rename_file (const char *repo_id, if (seaf_repo_manager_rename_file (seaf->repo_mgr, repo_id, rpath, norm_oldname, norm_newname, - user, error) < 0) { + user, friendly_name, error) < 0) { ret = -1; } @@ -3506,6 +3520,7 @@ seafile_revert_file (const char *repo_id, const char *commit_id, const char *path, const char *user, + const char *friendly_name, GError **error) { if (!repo_id || !commit_id || !path || !user) { @@ -3528,7 +3543,7 @@ seafile_revert_file (const char *repo_id, int ret = seaf_repo_manager_revert_file (seaf->repo_mgr, repo_id, commit_id, - rpath, user, error); + rpath, user, friendly_name, error); g_free (rpath); return ret; @@ -3539,6 +3554,7 @@ seafile_revert_dir (const char *repo_id, const char *commit_id, const char *path, const char *user, + const char *friendly_name, GError **error) { if (!repo_id || !commit_id || !path || !user) { @@ -3561,7 +3577,7 @@ seafile_revert_dir (const char *repo_id, int ret = seaf_repo_manager_revert_dir (seaf->repo_mgr, repo_id, commit_id, - rpath, user, error); + rpath, user, friendly_name, error); g_free (rpath); return ret; @@ -4259,6 +4275,7 @@ seafile_get_trash_repo_owner (const char *repo_id, GError **error) int seafile_mkdir_with_parents (const char *repo_id, const char *parent_dir, const char *new_dir_path, const char *user, + const char *friendly_name, GError **error) { if (!repo_id || !parent_dir || !new_dir_path || !user) { @@ -4273,7 +4290,7 @@ seafile_mkdir_with_parents (const char *repo_id, const char *parent_dir, if (seaf_repo_manager_mkdir_with_parents (seaf->repo_mgr, repo_id, parent_dir, new_dir_path, - user, error) < 0) { + user, friendly_name, error) < 0) { return -1; } diff --git a/fileserver/commitmgr/commitmgr.go b/fileserver/commitmgr/commitmgr.go index ed8c03b2..69033d23 100644 --- a/fileserver/commitmgr/commitmgr.go +++ b/fileserver/commitmgr/commitmgr.go @@ -21,6 +21,7 @@ type Commit struct { RepoID string `json:"repo_id"` RootID string `json:"root_id"` CreatorName string `json:"creator_name,omitempty"` + UserName string `json:"username,omitempty"` CreatorID string `json:"creator"` Desc string `json:"description"` Ctime int64 `json:"ctime"` @@ -50,12 +51,13 @@ func Init(seafileConfPath string, seafileDataDir string) { } // NewCommit initializes a Commit object. -func NewCommit(repoID, parentID, newRoot, user, desc string) *Commit { +func NewCommit(repoID, parentID, newRoot, user, username, desc string) *Commit { commit := new(Commit) commit.RepoID = repoID commit.RootID = newRoot commit.Desc = desc commit.CreatorName = user + commit.UserName = username commit.CreatorID = "0000000000000000000000000000000000000000" commit.Ctime = time.Now().Unix() commit.CommitID = computeCommitID(commit) diff --git a/fileserver/fileop.go b/fileserver/fileop.go index 8e5e9623..c26b638b 100644 --- a/fileserver/fileop.go +++ b/fileserver/fileop.go @@ -901,16 +901,17 @@ func packFiles(ar *zip.Writer, dirent *fsmgr.SeafDirent, repo *repomgr.Repo, par } type recvData struct { - parentDir string - tokenType string - repoID string - user string - rstart int64 - rend int64 - fsize int64 - fileNames []string - files []string - fileHeaders []*multipart.FileHeader + parentDir string + tokenType string + repoID string + user string + friendlyName string + rstart int64 + rend int64 + fsize int64 + fileNames []string + files []string + fileHeaders []*multipart.FileHeader } func uploadAPICB(rsp http.ResponseWriter, r *http.Request) *appError { @@ -1109,7 +1110,7 @@ func doUpload(rsp http.ResponseWriter, r *http.Request, fsm *recvData, isAjax bo return &appError{nil, msg, seafHTTPResNoQuota} } - if err := createRelativePath(repoID, parentDir, relativePath, user); err != nil { + if err := createRelativePath(repoID, parentDir, relativePath, user, fsm.friendlyName); err != nil { return err } @@ -1195,12 +1196,12 @@ func writeBlockDataToTmpFile(r *http.Request, fsm *recvData, formFiles map[strin return nil } -func createRelativePath(repoID, parentDir, relativePath, user string) *appError { +func createRelativePath(repoID, parentDir, relativePath, user, friendlyName string) *appError { if relativePath == "" { return nil } - err := mkdirWithParents(repoID, parentDir, relativePath, user) + err := mkdirWithParents(repoID, parentDir, relativePath, user, friendlyName) if err != nil { msg := "Internal error.\n" err := fmt.Errorf("Failed to create parent directory: %v", err) @@ -1210,7 +1211,7 @@ func createRelativePath(repoID, parentDir, relativePath, user string) *appError return nil } -func mkdirWithParents(repoID, parentDir, newDirPath, user string) error { +func mkdirWithParents(repoID, parentDir, newDirPath, user, friendlyName string) error { repo := repomgr.Get(repoID) if repo == nil { err := fmt.Errorf("failed to get repo %s", repoID) @@ -1259,14 +1260,18 @@ func mkdirWithParents(repoID, parentDir, newDirPath, user string) error { dent := fsmgr.NewDirent(dirID, filepath.Base(absPath), uint32(mode), mtime, "", 0) var names []string - rootID, _ = doPostMultiFiles(repo, newRootID, filepath.Dir(absPath), []*fsmgr.SeafDirent{dent}, user, false, &names) + userName := user + if friendlyName != "" { + userName = friendlyName + } + rootID, _ = doPostMultiFiles(repo, newRootID, filepath.Dir(absPath), []*fsmgr.SeafDirent{dent}, userName, false, &names) if rootID == "" { err := fmt.Errorf("failed to put dir") return err } buf := fmt.Sprintf("Added directory \"%s\"", relativeDirCan) - _, err = genNewCommit(repo, headCommit, rootID, user, buf, true) + _, err = genNewCommit(repo, headCommit, rootID, user, friendlyName, buf, true) if err != nil { err := fmt.Errorf("failed to generate new commit: %v", err) return err @@ -1527,7 +1532,7 @@ func postMultiFiles(rsp http.ResponseWriter, r *http.Request, repoID, parentDir, } } - retStr, err := postFilesAndGenCommit(fileNames, repo.ID, user, canonPath, replace, ids, sizes) + retStr, err := postFilesAndGenCommit(fileNames, repo.ID, user, fsm.friendlyName, canonPath, replace, ids, sizes) if err != nil { err := fmt.Errorf("failed to post files and gen commit: %v", err) return &appError{err, "", http.StatusInternalServerError} @@ -1583,7 +1588,7 @@ func checkFilesWithSameName(repo *repomgr.Repo, canonPath string, fileNames []st return false } -func postFilesAndGenCommit(fileNames []string, repoID string, user, canonPath string, replace bool, ids []string, sizes []int64) (string, error) { +func postFilesAndGenCommit(fileNames []string, repoID string, user, friendlyName, canonPath string, replace bool, ids []string, sizes []int64) (string, error) { repo := repomgr.Get(repoID) if repo == nil { err := fmt.Errorf("failed to get repo %s", repoID) @@ -1597,6 +1602,11 @@ func postFilesAndGenCommit(fileNames []string, repoID string, user, canonPath st var names []string var retryCnt int + userName := user + if friendlyName != "" { + userName = friendlyName + } + var dents []*fsmgr.SeafDirent for i, name := range fileNames { if i > len(ids)-1 || i > len(sizes)-1 { @@ -1609,7 +1619,7 @@ func postFilesAndGenCommit(fileNames []string, repoID string, user, canonPath st } retry: - rootID, err := doPostMultiFiles(repo, headCommit.RootID, canonPath, dents, user, replace, &names) + rootID, err := doPostMultiFiles(repo, headCommit.RootID, canonPath, dents, userName, replace, &names) if err != nil { err := fmt.Errorf("failed to post files to %s in repo %s", canonPath, repo.ID) return "", err @@ -1622,7 +1632,7 @@ retry: buf = fmt.Sprintf("Added \"%s\".", fileNames[0]) } - _, err = genNewCommit(repo, headCommit, rootID, user, buf, false) + _, err = genNewCommit(repo, headCommit, rootID, user, friendlyName, buf, false) if err != nil { if err != ErrConflict { err := fmt.Errorf("failed to generate new commit: %v", err) @@ -1686,10 +1696,10 @@ func getCanonPath(p string) string { var ErrConflict = fmt.Errorf("Concurent upload conflict") -func genNewCommit(repo *repomgr.Repo, base *commitmgr.Commit, newRoot, user, desc string, retryOnConflict bool) (string, error) { +func genNewCommit(repo *repomgr.Repo, base *commitmgr.Commit, newRoot, user, friendlyName, desc string, retryOnConflict bool) (string, error) { var retryCnt int repoID := repo.ID - commit := commitmgr.NewCommit(repoID, base.CommitID, newRoot, user, desc) + commit := commitmgr.NewCommit(repoID, base.CommitID, newRoot, user, friendlyName, desc) repomgr.RepoToCommit(repo, commit) err := commitmgr.Save(commit) if err != nil { @@ -1701,7 +1711,7 @@ func genNewCommit(repo *repomgr.Repo, base *commitmgr.Commit, newRoot, user, des maxRetryCnt := 10 for { - retry, err := genCommitNeedRetry(repo, base, commit, newRoot, user, &commitID) + retry, err := genCommitNeedRetry(repo, base, commit, newRoot, user, friendlyName, &commitID) if err != nil { return "", err } @@ -1734,7 +1744,7 @@ func genNewCommit(repo *repomgr.Repo, base *commitmgr.Commit, newRoot, user, des func fastForwardOrMerge(user string, repo *repomgr.Repo, base, newCommit *commitmgr.Commit) error { var retryCnt int for { - retry, err := genCommitNeedRetry(repo, base, newCommit, newCommit.RootID, user, nil) + retry, err := genCommitNeedRetry(repo, base, newCommit, newCommit.RootID, user, newCommit.UserName, nil) if err != nil { return err } @@ -1754,7 +1764,7 @@ func fastForwardOrMerge(user string, repo *repomgr.Repo, base, newCommit *commit return nil } -func genCommitNeedRetry(repo *repomgr.Repo, base *commitmgr.Commit, commit *commitmgr.Commit, newRoot, user string, commitID *string) (bool, error) { +func genCommitNeedRetry(repo *repomgr.Repo, base *commitmgr.Commit, commit *commitmgr.Commit, newRoot, user, friendlyName string, commitID *string) (bool, error) { var secondParentID string repoID := repo.ID var mergeDesc string @@ -1787,7 +1797,7 @@ func genCommitNeedRetry(repo *repomgr.Repo, base *commitmgr.Commit, commit *comm } secondParentID = commit.CommitID - mergedCommit = commitmgr.NewCommit(repoID, currentHead.CommitID, opt.mergedRoot, user, mergeDesc) + mergedCommit = commitmgr.NewCommit(repoID, currentHead.CommitID, opt.mergedRoot, user, friendlyName, mergeDesc) repomgr.RepoToCommit(repo, mergedCommit) mergedCommit.SecondParentID.SetValid(commit.CommitID) mergedCommit.NewMerge = 1 @@ -2480,10 +2490,11 @@ func parseContentRange(ranges string, fsm *recvData) bool { } type webaccessInfo struct { - repoID string - objID string - op string - user string + repoID string + objID string + op string + user string + friendlyName string } func parseWebaccessInfo(token string) (*webaccessInfo, *appError) { @@ -2527,10 +2538,16 @@ func parseWebaccessInfo(token string) (*webaccessInfo, *appError) { } accessInfo.user = user + friendlyName, ok := webaccessMap["friendly-name"].(string) + if !ok { + return nil, &appError{nil, "", http.StatusInternalServerError} + } + accessInfo.friendlyName = friendlyName + return accessInfo, nil } -func updateDir(repoID, dirPath, newDirID, user, headID string) (string, error) { +func updateDir(repoID, dirPath, newDirID, user, friendlyName, headID string) (string, error) { repo := repomgr.Get(repoID) if repo == nil { err := fmt.Errorf("failed to get repo %.10s", repoID) @@ -2555,7 +2572,7 @@ func updateDir(repoID, dirPath, newDirID, user, headID string) (string, error) { if commitDesc == "" { commitDesc = fmt.Sprintf("Auto merge by system") } - newCommitID, err := genNewCommit(repo, headCommit, newDirID, user, commitDesc, true) + newCommitID, err := genNewCommit(repo, headCommit, newDirID, user, friendlyName, commitDesc, true) if err != nil { err := fmt.Errorf("failed to generate new commit: %v", err) return "", err @@ -2596,7 +2613,7 @@ func updateDir(repoID, dirPath, newDirID, user, headID string) (string, error) { commitDesc = fmt.Sprintf("Auto merge by system") } - newCommitID, err := genNewCommit(repo, headCommit, rootID, user, commitDesc, true) + newCommitID, err := genNewCommit(repo, headCommit, rootID, user, friendlyName, commitDesc, true) if err != nil { err := fmt.Errorf("failed to generate new commit: %v", err) return "", err @@ -2972,19 +2989,24 @@ func putFile(rsp http.ResponseWriter, r *http.Request, repoID, parentDir, user, return nil } + userName := user + if fsm.friendlyName != "" { + userName = fsm.friendlyName + } + mtime := time.Now().Unix() mode := (syscall.S_IFREG | 0644) - newDent := fsmgr.NewDirent(fileID, fileName, uint32(mode), mtime, user, size) + newDent := fsmgr.NewDirent(fileID, fileName, uint32(mode), mtime, userName, size) var names []string - rootID, err := doPostMultiFiles(repo, headCommit.RootID, canonPath, []*fsmgr.SeafDirent{newDent}, user, true, &names) + rootID, err := doPostMultiFiles(repo, headCommit.RootID, canonPath, []*fsmgr.SeafDirent{newDent}, userName, true, &names) if err != nil { err := fmt.Errorf("failed to put file %s to %s in repo %s: %v", fileName, canonPath, repo.ID, err) return &appError{err, "", http.StatusInternalServerError} } desc := fmt.Sprintf("Modified \"%s\"", fileName) - _, err = genNewCommit(repo, headCommit, rootID, user, desc, true) + _, err = genNewCommit(repo, headCommit, rootID, user, fsm.friendlyName, desc, true) if err != nil { err := fmt.Errorf("failed to generate new commit: %v", err) return &appError{err, "", http.StatusInternalServerError} @@ -3065,6 +3087,7 @@ func doUploadBlks(rsp http.ResponseWriter, r *http.Request, fsm *recvData) *appE repoID := fsm.repoID user := fsm.user + friendlyName := fsm.friendlyName replaceStr := r.FormValue("replace") var replaceExisted bool @@ -3123,7 +3146,7 @@ func doUploadBlks(rsp http.ResponseWriter, r *http.Request, fsm *recvData) *appE return &appError{nil, msg, http.StatusBadRequest} } - fileID, appErr := commitFileBlocks(repoID, parentDir, fileName, blockIDsJSON, user, fileSize, replaceExisted) + fileID, appErr := commitFileBlocks(repoID, parentDir, fileName, blockIDsJSON, user, friendlyName, fileSize, replaceExisted) if appErr != nil { return appErr } @@ -3149,7 +3172,7 @@ func doUploadBlks(rsp http.ResponseWriter, r *http.Request, fsm *recvData) *appE return nil } -func commitFileBlocks(repoID, parentDir, fileName, blockIDsJSON, user string, fileSize int64, replace bool) (string, *appError) { +func commitFileBlocks(repoID, parentDir, fileName, blockIDsJSON, user, friendlyName string, fileSize int64, replace bool) (string, *appError) { repo := repomgr.Get(repoID) if repo == nil { msg := "Failed to get repo.\n" @@ -3193,18 +3216,23 @@ func commitFileBlocks(repoID, parentDir, fileName, blockIDsJSON, user string, fi return "", appErr } + userName := user + if friendlyName != "" { + userName = friendlyName + } + mtime := time.Now().Unix() mode := (syscall.S_IFREG | 0644) - newDent := fsmgr.NewDirent(fileID, fileName, uint32(mode), mtime, user, fileSize) + newDent := fsmgr.NewDirent(fileID, fileName, uint32(mode), mtime, userName, fileSize) var names []string - rootID, err := doPostMultiFiles(repo, headCommit.RootID, canonPath, []*fsmgr.SeafDirent{newDent}, user, replace, &names) + rootID, err := doPostMultiFiles(repo, headCommit.RootID, canonPath, []*fsmgr.SeafDirent{newDent}, userName, replace, &names) if err != nil { err := fmt.Errorf("failed to post file %s to %s in repo %s: %v", fileName, canonPath, repo.ID, err) return "", &appError{err, "", http.StatusInternalServerError} } desc := fmt.Sprintf("Added \"%s\"", fileName) - _, err = genNewCommit(repo, headCommit, rootID, user, desc, true) + _, err = genNewCommit(repo, headCommit, rootID, user, friendlyName, desc, true) if err != nil { err := fmt.Errorf("failed to generate new commit: %v", err) return "", &appError{err, "", http.StatusInternalServerError} diff --git a/fileserver/merge.go b/fileserver/merge.go index f3c7bd6f..db0305a4 100644 --- a/fileserver/merge.go +++ b/fileserver/merge.go @@ -331,7 +331,11 @@ func mergeConflictFileName(storeID string, opt *mergeOptions, baseDir, fileName err := fmt.Errorf("failed to get head commit") return "", err } - modifier = commit.CreatorName + if commit.UserName != "" { + modifier = commit.UserName + } else { + modifier = commit.CreatorName + } mtime = time.Now().Unix() } diff --git a/fileserver/virtual_repo.go b/fileserver/virtual_repo.go index fb6be165..30902803 100644 --- a/fileserver/virtual_repo.go +++ b/fileserver/virtual_repo.go @@ -155,14 +155,14 @@ func mergeRepo(repoID string) error { if root == origRoot { } else if baseRoot == root { - _, err := updateDir(repoID, "/", origRoot, origHead.CreatorName, head.CommitID) + _, err := updateDir(repoID, "/", origRoot, origHead.CreatorName, origHead.UserName, head.CommitID) if err != nil { err := fmt.Errorf("failed to update root of virtual repo %.10s", repoID) return err } repomgr.SetVirtualRepoBaseCommitPath(repo.ID, origRepo.HeadCommitID, vInfo.Path) } else if baseRoot == origRoot { - newBaseCommit, err := updateDir(vInfo.OriginRepoID, vInfo.Path, root, head.CreatorName, origHead.CommitID) + newBaseCommit, err := updateDir(vInfo.OriginRepoID, vInfo.Path, root, head.CreatorName, head.UserName, origHead.CommitID) if err != nil { err := fmt.Errorf("merge repo %.8s failed: failed to update origin repo%.10s path %s", repoID, vInfo.OriginRepoID, vInfo.Path) return err @@ -182,13 +182,13 @@ func mergeRepo(repoID string) error { return err } - _, err = updateDir(repoID, "/", opt.mergedRoot, origHead.CreatorName, head.CommitID) + _, err = updateDir(repoID, "/", opt.mergedRoot, origHead.CreatorName, origHead.UserName, head.CommitID) if err != nil { err := fmt.Errorf("failed to update root of virtual repo %.10s", repoID) return err } - newBaseCommit, err := updateDir(vInfo.OriginRepoID, vInfo.Path, opt.mergedRoot, head.CreatorName, origHead.CommitID) + newBaseCommit, err := updateDir(vInfo.OriginRepoID, vInfo.Path, opt.mergedRoot, head.CreatorName, head.UserName, origHead.CommitID) if err != nil { err := fmt.Errorf("merge repo %.10s failed: failed to update origin repo %.10s path %s", repoID, vInfo.OriginRepoID, vInfo.Path) return err @@ -351,7 +351,7 @@ func editRepoNeedRetry(repoID, name, desc, user string) (bool, error) { user = parent.CreatorName } - commit := commitmgr.NewCommit(repoID, parent.CommitID, parent.RootID, user, "Changed library name or description") + commit := commitmgr.NewCommit(repoID, parent.CommitID, parent.RootID, user, parent.UserName, "Changed library name or description") repomgr.RepoToCommit(repo, commit) commit.RepoName = name commit.RepoDesc = desc diff --git a/include/seafile-rpc.h b/include/seafile-rpc.h index c9717b62..b418252c 100644 --- a/include/seafile-rpc.h +++ b/include/seafile-rpc.h @@ -494,6 +494,7 @@ seafile_web_get_access_token (const char *repo_id, const char *obj_id, const char *op, const char *username, + const char *friendly_name, int use_onetime, GError **error); @@ -651,6 +652,7 @@ int seafile_revert_on_server (const char *repo_id, const char *commit_id, const char *user_name, + const char *friendly_name, GError **error); /** @@ -665,7 +667,7 @@ seafile_revert_on_server (const char *repo_id, int seafile_post_file (const char *repo_id, const char *temp_file_path, const char *parent_dir, const char *file_name, - const char *user, + const char *user, const char *friendly_name, GError **error); /** @@ -680,6 +682,7 @@ seafile_post_multi_files (const char *repo_id, const char *filenames_json, const char *paths_json, const char *user, + const char *friendly_name, int replace, GError **error); @@ -704,6 +707,7 @@ seafile_post_multi_files (const char *repo_id, int seafile_post_empty_file (const char *repo_id, const char *parent_dir, const char *new_file_name, const char *user, + const char *friendly_name, GError **error); /** @@ -716,7 +720,8 @@ seafile_post_empty_file (const char *repo_id, const char *parent_dir, char * seafile_put_file (const char *repo_id, const char *temp_file_path, const char *parent_dir, const char *file_name, - const char *user, const char *head_id, + const char *user, const char *friendly_name, + const char *head_id, GError **error); /** @@ -735,10 +740,12 @@ seafile_put_file (const char *repo_id, const char *temp_file_path, int seafile_post_dir (const char *repo_id, const char *parent_dir, const char *new_dir_name, const char *user, + const char *friendly_name, GError **error); int seafile_mkdir_with_parents (const char *repo_id, const char *parent_dir, const char *new_dir_path, const char *user, + const char *friendly_name, GError **error); /** @@ -751,7 +758,7 @@ seafile_mkdir_with_parents (const char *repo_id, const char *parent_dir, int seafile_del_file (const char *repo_id, const char *parent_dir, const char *file_name, - const char *user, + const char *user, const char *friendly_name, GError **error); /** @@ -765,6 +772,7 @@ seafile_copy_file (const char *src_repo_id, const char *dst_dir, const char *dst_filename, const char *user, + const char *friendly_name, int need_progress, int synchronous, GError **error); @@ -779,6 +787,7 @@ seafile_move_file (const char *src_repo_id, const char *dst_filename, int replace, const char *user, + const char *friendly_name, int need_progress, int synchronous, GError **error); @@ -795,6 +804,7 @@ seafile_rename_file (const char *repo_id, const char *oldname, const char *newname, const char *user, + const char *friendly_name, GError **error); /** @@ -852,6 +862,7 @@ seafile_revert_file (const char *repo_id, const char *commit_id, const char *path, const char *user, + const char *friendly_name, GError **error); int @@ -859,6 +870,7 @@ seafile_revert_dir (const char *repo_id, const char *commit_id, const char *path, const char *user, + const char *friendly_name, GError **error); char * diff --git a/lib/rpc_table.py b/lib/rpc_table.py index e10bb2f7..ecaffac9 100644 --- a/lib/rpc_table.py +++ b/lib/rpc_table.py @@ -106,6 +106,8 @@ [ "object", ["string", "string", "int", "int"] ], [ "object", ["string", "string", "string", "int"] ], [ "object", ["string", "string", "string", "string", "string", "string", "string", "int", "int"] ], + [ "object", ["string", "string", "string", "string", "string", "string", "string", "string", "int", "int"] ], [ "object", ["string", "string", "string", "string", "string", "string", "int", "string", "int", "int"] ], + [ "object", ["string", "string", "string", "string", "string", "string", "int", "string", "string", "int", "int"] ], ["json", ["string"]], ] diff --git a/lib/webaccess.vala b/lib/webaccess.vala index ecdba49a..5641b64d 100644 --- a/lib/webaccess.vala +++ b/lib/webaccess.vala @@ -5,6 +5,7 @@ public class WebAccess : Object { public string obj_id { set; get; } public string op { set; get; } public string username { set; get; } + public string friendly_name { set; get; } } } diff --git a/python/seafile/rpcclient.py b/python/seafile/rpcclient.py index 6559c2dd..ff57b525 100644 --- a/python/seafile/rpcclient.py +++ b/python/seafile/rpcclient.py @@ -91,8 +91,8 @@ def seafile_repo_query_access_property(repo_id): pass repo_query_access_property = seafile_repo_query_access_property - @searpc_func("int", ["string", "string", "string"]) - def seafile_revert_on_server(repo_id, commit_id, user_name): + @searpc_func("int", ["string", "string", "string", "string"]) + def seafile_revert_on_server(repo_id, commit_id, user_name, friendly_name): pass revert_on_server = seafile_revert_on_server @@ -101,43 +101,43 @@ def seafile_diff(): pass get_diff = seafile_diff - @searpc_func("int", ["string", "string", "string", "string", "string"]) - def seafile_post_file(repo_id, tmp_file_path, parent_dir, filename, user): + @searpc_func("int", ["string", "string", "string", "string", "string", "string"]) + def seafile_post_file(repo_id, tmp_file_path, parent_dir, filename, user, friendly_name): pass post_file = seafile_post_file - @searpc_func("int", ["string", "string", "string", "string"]) - def seafile_post_dir(repo_id, parent_dir, new_dir_name, user): + @searpc_func("int", ["string", "string", "string", "string", "string"]) + def seafile_post_dir(repo_id, parent_dir, new_dir_name, user, friendly_name): pass post_dir = seafile_post_dir - @searpc_func("int", ["string", "string", "string", "string"]) - def seafile_post_empty_file(repo_id, parent_dir, filename, user): + @searpc_func("int", ["string", "string", "string", "string", "string"]) + def seafile_post_empty_file(repo_id, parent_dir, filename, user, friendly_name): pass post_empty_file = seafile_post_empty_file - @searpc_func("int", ["string", "string", "string", "string", "string", "string"]) - def seafile_put_file(repo_id, tmp_file_path, parent_dir, filename, user, head_id): + @searpc_func("int", ["string", "string", "string", "string", "string", "string", "string"]) + def seafile_put_file(repo_id, tmp_file_path, parent_dir, filename, user, friendly_name, head_id): pass put_file = seafile_put_file - @searpc_func("int", ["string", "string", "string", "string"]) - def seafile_del_file(repo_id, parent_dir, filename, user): + @searpc_func("int", ["string", "string", "string", "string", "string"]) + def seafile_del_file(repo_id, parent_dir, filename, user, friendly_name): pass del_file = seafile_del_file - @searpc_func("object", ["string", "string", "string", "string", "string", "string", "string", "int", "int"]) - def seafile_copy_file(src_repo, src_dir, src_filename, dst_repo, dst_dir, dst_filename, user, need_progress, synchronous): + @searpc_func("object", ["string", "string", "string", "string", "string", "string", "string", "string", "int", "int"]) + def seafile_copy_file(src_repo, src_dir, src_filename, dst_repo, dst_dir, dst_filename, user, friendly_name, need_progress, synchronous): pass copy_file = seafile_copy_file - @searpc_func("object", ["string", "string", "string", "string", "string", "string", "int", "string", "int", "int"]) - def seafile_move_file(src_repo, src_dir, src_filename, dst_repo, dst_dir, dst_filename, replace, user, need_progress, synchronous): + @searpc_func("object", ["string", "string", "string", "string", "string", "string", "int", "string", "string", "int", "int"]) + def seafile_move_file(src_repo, src_dir, src_filename, dst_repo, dst_dir, dst_filename, replace, user, friendly_name, need_progress, synchronous): pass move_file = seafile_move_file - @searpc_func("int", ["string", "string", "string", "string", "string"]) - def seafile_rename_file(repo_id, parent_dir, oldname, newname, user): + @searpc_func("int", ["string", "string", "string", "string", "string", "string"]) + def seafile_rename_file(repo_id, parent_dir, oldname, newname, user, friendly_name): pass rename_file = seafile_rename_file @@ -215,8 +215,8 @@ def seafile_calc_files_last_modified(repo_id, parent_dir, limit): pass calc_files_last_modified = seafile_calc_files_last_modified - @searpc_func("int", ["string", "string", "string", "string"]) - def seafile_revert_file(repo_id, commit_id, path, user): + @searpc_func("int", ["string", "string", "string", "string", "string"]) + def seafile_revert_file(repo_id, commit_id, path, user, friendly_name): pass revert_file = seafile_revert_file @@ -225,8 +225,8 @@ def seafile_check_repo_blocks_missing(repo_id, blklist): pass check_repo_blocks_missing = seafile_check_repo_blocks_missing - @searpc_func("int", ["string", "string", "string", "string"]) - def seafile_revert_dir(repo_id, commit_id, path, user): + @searpc_func("int", ["string", "string", "string", "string", "string"]) + def seafile_revert_dir(repo_id, commit_id, path, user, friendly_name): pass revert_dir = seafile_revert_dir @@ -690,8 +690,8 @@ def seafile_get_upload_tmp_file_offset(repo_id, file_path): pass get_upload_tmp_file_offset = seafile_get_upload_tmp_file_offset - @searpc_func("int", ["string", "string", "string", "string"]) - def seafile_mkdir_with_parents (repo_id, parent_dir, relative_path, username): + @searpc_func("int", ["string", "string", "string", "string", "string"]) + def seafile_mkdir_with_parents (repo_id, parent_dir, relative_path, username, friendly_name): pass mkdir_with_parents = seafile_mkdir_with_parents @@ -753,8 +753,8 @@ def get_repo_status(repo_id): pass # token for web access to repo - @searpc_func("string", ["string", "string", "string", "string", "int"]) - def seafile_web_get_access_token(repo_id, obj_id, op, username, use_onetime=1): + @searpc_func("string", ["string", "string", "string", "string", "string", "int"]) + def seafile_web_get_access_token(repo_id, obj_id, op, username, friendly_name, use_onetime=1): pass web_get_access_token = seafile_web_get_access_token diff --git a/python/seaserv/api.py b/python/seaserv/api.py index fe0aaf5d..b105f44a 100644 --- a/python/seaserv/api.py +++ b/python/seaserv/api.py @@ -23,7 +23,7 @@ def __init__(self): # fileserver token - def get_fileserver_access_token(self, repo_id, obj_id, op, username, use_onetime=True): + def get_fileserver_access_token(self, repo_id, obj_id, op, username, friendly_name, use_onetime=True): """Generate token for access file/dir in fileserver op: the operation, can be 'view', 'download', 'download-dir', 'downloadblks', @@ -33,7 +33,7 @@ def get_fileserver_access_token(self, repo_id, obj_id, op, username, use_onetime Return: the access token in string """ onetime = 1 if bool(use_onetime) else 0 - return seafserv_threaded_rpc.web_get_access_token(repo_id, obj_id, op, username, + return seafserv_threaded_rpc.web_get_access_token(repo_id, obj_id, op, username, friendly_name, onetime) def query_fileserver_access_token(self, token): @@ -151,8 +151,8 @@ def get_orphan_repo_list(self): def get_repo_size(self, repo_id): return seafserv_threaded_rpc.server_repo_size(repo_id) - def revert_repo(self, repo_id, commit_id, username): - return seafserv_threaded_rpc.revert_on_server(repo_id, commit_id, username) + def revert_repo(self, repo_id, commit_id, username, friendly_name): + return seafserv_threaded_rpc.revert_on_server(repo_id, commit_id, username, friendly_name) def diff_commits(self, repo_id, old_commit, new_commit, fold_dir_diff = 1): """ @@ -262,8 +262,8 @@ def get_dir_id_by_commit_and_path(self, repo_id, commit_id, path): def list_dir_with_perm(self, repo_id, dir_path, dir_id, user, offset=-1, limit=-1): return seafserv_threaded_rpc.list_dir_with_perm (repo_id, dir_path, dir_id, user, offset, limit) - def mkdir_with_parents (self, repo_id, parent_dir, relative_path, username): - return seafserv_threaded_rpc.mkdir_with_parents(repo_id, parent_dir, relative_path, username) + def mkdir_with_parents (self, repo_id, parent_dir, relative_path, username, friendly_name): + return seafserv_threaded_rpc.mkdir_with_parents(repo_id, parent_dir, relative_path, username, friendly_name) def get_file_count_info_by_path(self, repo_id, path): return seafserv_threaded_rpc.get_file_count_info_by_path(repo_id, path) @@ -276,29 +276,29 @@ def get_total_file_number (self): # file/dir operations - def post_file(self, repo_id, tmp_file_path, parent_dir, filename, username): + def post_file(self, repo_id, tmp_file_path, parent_dir, filename, username, friendly_name): """Add a file to a directory""" return seafserv_threaded_rpc.post_file(repo_id, tmp_file_path, parent_dir, - filename, username) + filename, username, friendly_name) - def post_empty_file(self, repo_id, parent_dir, filename, username): + def post_empty_file(self, repo_id, parent_dir, filename, username, friendly_name): return seafserv_threaded_rpc.post_empty_file(repo_id, parent_dir, - filename, username) + filename, username, friendly_name) def put_file(self, repo_id, tmp_file_path, parent_dir, filename, - username, head_id): + username, friendly_name, head_id): """Update an existing file head_id: the original commit id of the old file """ return seafserv_threaded_rpc.put_file(repo_id, tmp_file_path, parent_dir, - filename, username, head_id) + filename, username, friendly_name, head_id) ''' If you want to delete multiple files in a batch, @filename should be json array ''' - def del_file(self, repo_id, parent_dir, filename, username): - return seafserv_threaded_rpc.del_file(repo_id, parent_dir, filename, username) + def del_file(self, repo_id, parent_dir, filename, username, friendly_name): + return seafserv_threaded_rpc.del_file(repo_id, parent_dir, filename, username, friendly_name) ''' If you want to move or copy multiple files in a batch, @src_filename and @dst_filename @@ -306,16 +306,16 @@ def del_file(self, repo_id, parent_dir, filename, username): in @src_filename and @dst_filename parameters match ''' def copy_file(self, src_repo, src_dir, src_filename, dst_repo, - dst_dir, dst_filename, username, need_progress, synchronous=0): + dst_dir, dst_filename, username, friendly_name, need_progress, synchronous=0): return seafserv_threaded_rpc.copy_file(src_repo, src_dir, src_filename, dst_repo, dst_dir, dst_filename, - username, need_progress, synchronous) + username, friendly_name, need_progress, synchronous) def move_file(self, src_repo, src_dir, src_filename, dst_repo, dst_dir, - dst_filename, replace, username, need_progress, synchronous=0): + dst_filename, replace, username, friendly_name, need_progress, synchronous=0): return seafserv_threaded_rpc.move_file(src_repo, src_dir, src_filename, dst_repo, dst_dir, dst_filename, - replace, username, need_progress, synchronous) + replace, username, friendly_name, need_progress, synchronous) def get_copy_task(self, task_id): return seafserv_threaded_rpc.get_copy_task(task_id) @@ -323,19 +323,19 @@ def get_copy_task(self, task_id): def cancel_copy_task(self, task_id): return seafserv_threaded_rpc.cancel_copy_task(task_id) - def rename_file(self, repo_id, parent_dir, oldname, newname, username): + def rename_file(self, repo_id, parent_dir, oldname, newname, username, friendly_name): return seafserv_threaded_rpc.rename_file(repo_id, parent_dir, - oldname, newname, username) + oldname, newname, username, friendly_name) - def post_dir(self, repo_id, parent_dir, dirname, username): + def post_dir(self, repo_id, parent_dir, dirname, username, friendly_name): """Add a directory""" - return seafserv_threaded_rpc.post_dir(repo_id, parent_dir, dirname, username) + return seafserv_threaded_rpc.post_dir(repo_id, parent_dir, dirname, username, friendly_name) - def revert_file(self, repo_id, commit_id, path, username): - return seafserv_threaded_rpc.revert_file(repo_id, commit_id, path, username) + def revert_file(self, repo_id, commit_id, path, username, friendly_name): + return seafserv_threaded_rpc.revert_file(repo_id, commit_id, path, username, friendly_name) - def revert_dir(self, repo_id, commit_id, path, username): - return seafserv_threaded_rpc.revert_dir(repo_id, commit_id, path, username) + def revert_dir(self, repo_id, commit_id, path, username, friendly_name): + return seafserv_threaded_rpc.revert_dir(repo_id, commit_id, path, username, friendly_name) def get_deleted(self, repo_id, show_days, path='/', scan_stat=None, limit=100): """ diff --git a/server/copy-mgr.c b/server/copy-mgr.c index 407a283a..48839bae 100644 --- a/server/copy-mgr.c +++ b/server/copy-mgr.c @@ -97,6 +97,7 @@ struct CopyThreadData { char *dst_filename; int replace; char *modifier; + char *friendly_name; CopyTask *task; CopyTaskFunc func; }; @@ -109,7 +110,7 @@ copy_thread (void *vdata) data->func (data->src_repo_id, data->src_path, data->src_filename, data->dst_repo_id, data->dst_path, data->dst_filename, - data->replace, data->modifier, data->task); + data->replace, data->modifier, data->friendly_name, data->task); return vdata; } @@ -124,6 +125,7 @@ copy_done (void *vdata) g_free (data->dst_path); g_free (data->dst_filename); g_free (data->modifier); + g_free (data->friendly_name); g_free (data); } @@ -137,6 +139,7 @@ seaf_copy_manager_add_task (SeafCopyManager *mgr, const char *dst_filename, int replace, const char *modifier, + const char *friendly_name, CopyTaskFunc function, gboolean need_progress) { @@ -165,6 +168,7 @@ seaf_copy_manager_add_task (SeafCopyManager *mgr, data->dst_filename = g_strdup(dst_filename); data->replace = replace; data->modifier = g_strdup(modifier); + data->friendly_name = g_strdup(friendly_name); data->task = task; data->func = function; diff --git a/server/copy-mgr.h b/server/copy-mgr.h index ec16ba30..b8f24437 100644 --- a/server/copy-mgr.h +++ b/server/copy-mgr.h @@ -42,7 +42,7 @@ seaf_copy_manager_start (SeafCopyManager *mgr); typedef int (*CopyTaskFunc) (const char *, const char *, const char *, const char *, const char *, const char *, - int, const char *, CopyTask *); + int, const char *, const char *, CopyTask *); char * seaf_copy_manager_add_task (SeafCopyManager *mgr, @@ -54,6 +54,7 @@ seaf_copy_manager_add_task (SeafCopyManager *mgr, const char *dst_filename, int replace, const char *modifier, + const char *friendly_name, CopyTaskFunc function, gboolean need_progress); diff --git a/server/gc/fsck.c b/server/gc/fsck.c index c0ed18c2..dd524da9 100644 --- a/server/gc/fsck.c +++ b/server/gc/fsck.c @@ -393,7 +393,7 @@ reset_commit_to_repair (SeafRepo *repo, SeafCommit *parent, char *new_root_id, SeafCommit *new_commit = NULL; new_commit = seaf_commit_new (NULL, repo->id, new_root_id, - parent->creator_name, parent->creator_id, + parent->creator_name, parent->username, parent->creator_id, desc, 0); g_free (desc); if (!new_commit) { diff --git a/server/http-server.c b/server/http-server.c index 77c137b6..419f06fc 100644 --- a/server/http-server.c +++ b/server/http-server.c @@ -968,7 +968,7 @@ fast_forward_or_merge (const char *repo_id, } merged_commit = seaf_commit_new(NULL, repo->id, opt.merged_tree_root, - new_commit->creator_name, EMPTY_SHA1, + new_commit->creator_name, new_commit->username, EMPTY_SHA1, desc, 0); g_free (desc); diff --git a/server/index-blocks-mgr.c b/server/index-blocks-mgr.c index 32cfbe60..22619aa2 100644 --- a/server/index-blocks-mgr.c +++ b/server/index-blocks-mgr.c @@ -47,6 +47,7 @@ typedef struct IndexPara { GList *paths; SeafRepo *repo; char *user; + char *friendly_name; char *canon_path; int replace_existed; SeafileCrypt *crypt; @@ -132,6 +133,7 @@ free_index_para (IndexPara *idx_para) string_list_free (idx_para->paths); seaf_repo_unref (idx_para->repo); g_free (idx_para->user); + g_free (idx_para->friendly_name); g_free (idx_para->canon_path); g_free (idx_para->crypt); g_free (idx_para); @@ -173,6 +175,7 @@ start_index_task (gpointer data, gpointer user_data) ret = post_files_and_gen_commit (idx_para->filenames, idx_para->repo->id, idx_para->user, + idx_para->friendly_name, idx_para->ret_json ? &ret_json : NULL, idx_para->replace_existed, idx_para->canon_path, @@ -241,6 +244,7 @@ index_blocks_mgr_start_index (IndexBlksMgr *mgr, GList *paths, const char *repo_id, const char *user, + const char *friendly_name, int replace_existed, gboolean ret_json, const char *canon_path, @@ -278,6 +282,7 @@ index_blocks_mgr_start_index (IndexBlksMgr *mgr, idx_para->paths = g_list_copy_deep (paths, (GCopyFunc)g_strdup, NULL); idx_para->repo = repo; idx_para->user = g_strdup (user); + idx_para->friendly_name = g_strdup (friendly_name); idx_para->canon_path = g_strdup(canon_path); idx_para->replace_existed = replace_existed; idx_para->ret_json = ret_json; diff --git a/server/index-blocks-mgr.h b/server/index-blocks-mgr.h index 830e0524..3dd98e1d 100644 --- a/server/index-blocks-mgr.h +++ b/server/index-blocks-mgr.h @@ -32,6 +32,7 @@ index_blocks_mgr_start_index (IndexBlksMgr *mgr, GList *paths, const char *repo_id, const char *user, + const char *friendly_name, int replace_existed, gboolean ret_json, const char *canon_path, diff --git a/server/repo-mgr.c b/server/repo-mgr.c index 03acd42a..db8e99bd 100644 --- a/server/repo-mgr.c +++ b/server/repo-mgr.c @@ -3793,6 +3793,7 @@ create_repo_common (SeafRepoManager *mgr, commit = seaf_commit_new (NULL, repo->id, EMPTY_SHA1, /* root id */ user, /* creator */ + NULL, EMPTY_SHA1, /* creator id */ "Created library", /* description */ 0); /* ctime */ @@ -4154,6 +4155,7 @@ seaf_repo_manager_edit_repo (const char *repo_id, repo->id, parent->root_id, user, + NULL, EMPTY_SHA1, "Changed library name or description", 0); diff --git a/server/repo-mgr.h b/server/repo-mgr.h index c85ccfcc..0921f1b3 100644 --- a/server/repo-mgr.h +++ b/server/repo-mgr.h @@ -297,6 +297,7 @@ seaf_repo_manager_revert_on_server (SeafRepoManager *mgr, const char *repo_id, const char *commit_id, const char *user_name, + const char *friendly_name, GError **error); /** @@ -315,6 +316,7 @@ seaf_repo_manager_post_file (SeafRepoManager *mgr, const char *parent_dir, const char *file_name, const char *user, + const char *friendly_name, GError **error); int @@ -324,6 +326,7 @@ seaf_repo_manager_post_multi_files (SeafRepoManager *mgr, const char *filenames_json, const char *paths_json, const char *user, + const char *friendly_name, int replace_existed, char **new_ids, char **task_id, @@ -357,6 +360,7 @@ seaf_repo_manager_commit_file_blocks (SeafRepoManager *mgr, const char *file_name, const char *blockids_json, const char *user, + const char *friendly_name, gint64 file_size, int replace_existed, char **new_id, @@ -368,6 +372,7 @@ seaf_repo_manager_post_empty_file (SeafRepoManager *mgr, const char *parent_dir, const char *new_file_name, const char *user, + const char *friendly_name, GError **error); int @@ -376,6 +381,7 @@ seaf_repo_manager_post_dir (SeafRepoManager *mgr, const char *parent_dir, const char *new_dir_name, const char *user, + const char *friendly_name, GError **error); int @@ -384,6 +390,7 @@ seaf_repo_manager_mkdir_with_parents (SeafRepoManager *mgr, const char *parent_dir, const char *new_dir_path, const char *user, + const char *friendly_name, GError **error); /** @@ -400,6 +407,7 @@ seaf_repo_manager_put_file (SeafRepoManager *mgr, const char *parent_dir, const char *file_name, const char *user, + const char *friendly_name, const char *head_id, char **new_file_id, GError **error); @@ -423,21 +431,9 @@ seaf_repo_manager_del_file (SeafRepoManager *mgr, const char *parent_dir, const char *file_name, const char *user, + const char *friendly_name, GError **error); -SeafileCopyResult * -seaf_repo_manager_copy_file (SeafRepoManager *mgr, - const char *src_repo_id, - const char *src_dir, - const char *src_filename, - const char *dst_repo_id, - const char *dst_dir, - const char *dst_filename, - const char *user, - int need_progress, - int synchronous, - GError **error); - SeafileCopyResult * seaf_repo_manager_copy_multiple_files (SeafRepoManager *mgr, const char *src_repo_id, @@ -447,24 +443,11 @@ seaf_repo_manager_copy_multiple_files (SeafRepoManager *mgr, const char *dst_dir, const char *dst_filenames, const char *user, + const char *friendly_name, int need_progress, int synchronous, GError **error); -SeafileCopyResult * -seaf_repo_manager_move_file (SeafRepoManager *mgr, - const char *src_repo_id, - const char *src_dir, - const char *src_filename, - const char *dst_repo_id, - const char *dst_dir, - const char *dst_filename, - int replace, - const char *user, - int need_progress, - int synchronous, - GError **error); - SeafileCopyResult * seaf_repo_manager_move_multiple_files (SeafRepoManager *mgr, const char *src_repo_id, @@ -475,6 +458,7 @@ seaf_repo_manager_move_multiple_files (SeafRepoManager *mgr, const char *dst_filenames, int replace, const char *user, + const char *friendly_name, int need_progress, int synchronous, GError **error); @@ -486,6 +470,7 @@ seaf_repo_manager_rename_file (SeafRepoManager *mgr, const char *oldname, const char *newname, const char *user, + const char *friendly_name, GError **error); int @@ -541,6 +526,7 @@ seaf_repo_manager_revert_file (SeafRepoManager *mgr, const char *commit_id, const char *path, const char *user, + const char *friendly_name, GError **error); int @@ -549,6 +535,7 @@ seaf_repo_manager_revert_dir (SeafRepoManager *mgr, const char *old_commit_id, const char *dir_path, const char *user, + const char *friendly_name, GError **error); /* @@ -573,6 +560,7 @@ seaf_repo_manager_update_dir (SeafRepoManager *mgr, const char *dir_path, const char *new_dir_id, const char *user, + const char *friendly_name, const char *head_id, char *new_commit_id, GError **error); @@ -902,6 +890,7 @@ int post_files_and_gen_commit (GList *filenames, const char *repo_id, const char *user, + const char *friendly_name, char **ret_json, int replace_existed, const char *canon_path, diff --git a/server/repo-op.c b/server/repo-op.c index 6c89c35d..071cbe45 100644 --- a/server/repo-op.c +++ b/server/repo-op.c @@ -46,6 +46,7 @@ int post_files_and_gen_commit (GList *filenames, const char *repo_id, const char *user, + const char *friendly_name, char **ret_json, int replace_existed, const char *canon_path, @@ -453,6 +454,7 @@ gen_new_commit (const char *repo_id, SeafCommit *base, const char *new_root, const char *user, + const char *friendly_name, const char *desc, char *new_commit_id, gboolean retry_on_conflict, @@ -475,7 +477,7 @@ gen_new_commit (const char *repo_id, /* Create a new commit pointing to new_root. */ new_commit = seaf_commit_new(NULL, repo->id, new_root, - user, EMPTY_SHA1, + user, friendly_name, EMPTY_SHA1, desc, 0); new_commit->parent_id = g_strdup (base->commit_id); seaf_repo_to_commit (repo, new_commit); @@ -539,7 +541,7 @@ gen_new_commit (const char *repo_id, } merged_commit = seaf_commit_new(NULL, repo->id, opt.merged_tree_root, - user, EMPTY_SHA1, + user, friendly_name, EMPTY_SHA1, desc, 0); g_free (desc); @@ -626,6 +628,7 @@ seaf_repo_manager_post_file (SeafRepoManager *mgr, const char *parent_dir, const char *file_name, const char *user, + const char *friendly_name, GError **error) { SeafRepo *repo = NULL; @@ -698,9 +701,12 @@ seaf_repo_manager_post_file (SeafRepoManager *mgr, } rawdata_to_hex(sha1, hex, 20); + const char *username = user; + if (friendly_name) + username = friendly_name; new_dent = seaf_dirent_new (dir_version_from_repo_version (repo->version), hex, STD_FILE_MODE, file_name, - (gint64)time(NULL), user, size); + (gint64)time(NULL), username, size); retry: root_id = do_post_file (repo, @@ -716,7 +722,7 @@ seaf_repo_manager_post_file (SeafRepoManager *mgr, snprintf(buf, SEAF_PATH_MAX, "Added \"%s\"", file_name); if (gen_new_commit (repo_id, head_commit, root_id, - user, buf, NULL, FALSE, error) < 0) { + user, friendly_name, buf, NULL, FALSE, error) < 0) { if (*error == NULL || (*error)->code != SEAF_ERR_CONCURRENT_UPLOAD) { ret = -1; goto out; @@ -1066,6 +1072,7 @@ seaf_repo_manager_post_multi_files (SeafRepoManager *mgr, const char *filenames_json, const char *paths_json, const char *user, + const char *friendly_name, int replace_existed, char **ret_json, char **task_id, @@ -1162,6 +1169,7 @@ seaf_repo_manager_post_multi_files (SeafRepoManager *mgr, ret = post_files_and_gen_commit (filenames, repo->id, user, + friendly_name, ret_json, replace_existed, canon_path, @@ -1174,6 +1182,7 @@ seaf_repo_manager_post_multi_files (SeafRepoManager *mgr, paths, repo_id, user, + friendly_name, replace_existed, ret_json == NULL ? FALSE : TRUE, canon_path, @@ -1200,6 +1209,7 @@ int post_files_and_gen_commit (GList *filenames, const char *repo_id, const char *user, + const char *friendly_name, char **ret_json, int replace_existed, const char *canon_path, @@ -1214,6 +1224,10 @@ post_files_and_gen_commit (GList *filenames, char *root_id = NULL; int ret = 0; int retry_cnt = 0; + const char *username = user; + + if (friendly_name) + username = friendly_name; GET_REPO_OR_FAIL(repo, repo_id); GET_COMMIT_OR_FAIL(head_commit, repo->id, repo->version, repo->head->commit_id); @@ -1221,7 +1235,7 @@ post_files_and_gen_commit (GList *filenames, retry: /* Add the files to parent dir and commit. */ root_id = do_post_multi_files (repo, head_commit->root_id, canon_path, - filenames, id_list, size_list, user, + filenames, id_list, size_list, username, replace_existed, &name_list); if (!root_id) { seaf_warning ("[post multi-file] Failed to post files to %s in repo %s.\n", @@ -1239,7 +1253,7 @@ post_files_and_gen_commit (GList *filenames, g_string_printf (buf, "Added \"%s\".", (char *)(filenames->data)); if (gen_new_commit (repo->id, head_commit, root_id, - user, buf->str, NULL, FALSE, error) < 0) { + user, friendly_name, buf->str, NULL, FALSE, error) < 0) { if (*error == NULL || (*error)->code != SEAF_ERR_CONCURRENT_UPLOAD) { ret = -1; goto out; @@ -1492,6 +1506,7 @@ seaf_repo_manager_commit_file_blocks (SeafRepoManager *mgr, const char *file_name, const char *blockids_json, const char *user, + const char *friendly_name, gint64 file_size, int replace_existed, char **new_id, @@ -1552,9 +1567,12 @@ seaf_repo_manager_commit_file_blocks (SeafRepoManager *mgr, } rawdata_to_hex(sha1, hex, 20); + const char *username = user; + if (friendly_name) + username = friendly_name; new_dent = seaf_dirent_new (dir_version_from_repo_version(repo->version), hex, STD_FILE_MODE, file_name, - (gint64)time(NULL), user, file_size); + (gint64)time(NULL), username, file_size); root_id = do_post_file_replace (repo, head_commit->root_id, canon_path, replace_existed, new_dent); @@ -1570,7 +1588,7 @@ seaf_repo_manager_commit_file_blocks (SeafRepoManager *mgr, *new_id = g_strdup(hex); snprintf(buf, SEAF_PATH_MAX, "Added \"%s\"", file_name); if (gen_new_commit (repo_id, head_commit, root_id, - user, buf, NULL, TRUE, error) < 0) + user, friendly_name, buf, NULL, TRUE, error) < 0) ret = -1; out: @@ -1739,6 +1757,7 @@ seaf_repo_manager_del_file (SeafRepoManager *mgr, const char *parent_dir, const char *file_name, const char *user, + const char *friendly_name, GError **error) { SeafRepo *repo = NULL; @@ -1794,7 +1813,7 @@ seaf_repo_manager_del_file (SeafRepoManager *mgr, } if (gen_new_commit (repo_id, head_commit, root_id, - user, buf, NULL, TRUE, error) < 0) { + user, friendly_name, buf, NULL, TRUE, error) < 0) { ret = -1; goto out; } @@ -1884,6 +1903,7 @@ put_dirent_and_commit (SeafRepo *repo, int n_dents, int replace, const char *user, + const char *friendly_name, GError **error) { SeafCommit *head_commit = NULL; @@ -1902,7 +1922,10 @@ put_dirent_and_commit (SeafRepo *repo, if (*path == '/') path = path + 1; - root_id = post_multi_files_recursive (repo, root_id, path, dent_list, user, + const char *username = user; + if (friendly_name) + username = user; + root_id = post_multi_files_recursive (repo, root_id, path, dent_list, username, replace, &name_list); g_list_free (dent_list); g_list_free_full (name_list, (GDestroyNotify)g_free); @@ -1931,7 +1954,7 @@ put_dirent_and_commit (SeafRepo *repo, } if (gen_new_commit (repo->id, head_commit, root_id, - user, buf, NULL, TRUE, error) < 0) + user, friendly_name, buf, NULL, TRUE, error) < 0) ret = -1; out: @@ -2345,6 +2368,7 @@ cross_repo_copy (const char *src_repo_id, const char *dst_filename, int replace, const char *modifier, + const char *friendly_name, CopyTask *task) { SeafRepo *src_repo = NULL, *dst_repo = NULL; @@ -2469,10 +2493,13 @@ cross_repo_copy (const char *src_repo_id, i = 0; /* do copy */ + const char *username = modifier; + if (friendly_name) + username = friendly_name; for (ptr = dst_names; ptr; ptr = ptr->next) { name = ptr->data; new_id = copy_recursive (src_repo, dst_repo, src_crypt, dst_crypt, - src_dents[i]->id, src_dents[i]->mode, modifier, task, + src_dents[i]->id, src_dents[i]->mode, username, task, &new_size); if (!new_id) { err_str = COPY_ERR_INTERNAL; @@ -2482,7 +2509,7 @@ cross_repo_copy (const char *src_repo_id, } dst_dents[i] = seaf_dirent_new (dir_version_from_repo_version(dst_repo->version), new_id, src_dents[i]->mode, name, - src_dents[i]->mtime, modifier, new_size); + src_dents[i]->mtime, username, new_size); g_free (new_id); i++; } @@ -2493,6 +2520,7 @@ cross_repo_copy (const char *src_repo_id, file_num, replace, modifier, + friendly_name, NULL) < 0) { err_str = COPY_ERR_INTERNAL; ret = -1; @@ -2599,162 +2627,6 @@ check_file_count_and_size (SeafRepo *repo, SeafDirent *dent, gint64 total_files, return TRUE; } -/** - * Copy a SeafDirent from a SeafDir to another. - * - * 1. When @src_repo and @dst_repo are not the same repo, neither of them - * should be encrypted. - * - * 2. the file being copied must not exist in the dst path of the dst repo. - */ -SeafileCopyResult * -seaf_repo_manager_copy_file (SeafRepoManager *mgr, - const char *src_repo_id, - const char *src_path, - const char *src_filename, - const char *dst_repo_id, - const char *dst_path, - const char *dst_filename, - const char *user, - int need_progress, - int synchronous, - GError **error) -{ - SeafRepo *src_repo = NULL, *dst_repo = NULL; - SeafDirent *src_dent = NULL, *dst_dent = NULL; - char *src_canon_path = NULL, *dst_canon_path = NULL; - SeafCommit *dst_head_commit = NULL; - int ret = 0; - gboolean background = FALSE; - char *task_id = NULL; - SeafileCopyResult *res= NULL; - - GET_REPO_OR_FAIL(src_repo, src_repo_id); - - if (strcmp(src_repo_id, dst_repo_id) != 0) { - GET_REPO_OR_FAIL(dst_repo, dst_repo_id); - - if (src_repo->encrypted || dst_repo->encrypted) { - g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_BAD_ARGS, - "Can't copy files between encrypted repo(s)"); - ret = -1; - goto out; - } - - } else { - seaf_repo_ref (src_repo); - dst_repo = src_repo; - } - - src_canon_path = get_canonical_path (src_path); - dst_canon_path = get_canonical_path (dst_path); - - GET_COMMIT_OR_FAIL(dst_head_commit, - dst_repo->id, dst_repo->version, - dst_repo->head->commit_id); - - /* FAIL_IF_FILE_EXISTS(dst_repo->store_id, dst_repo->version, - dst_head_commit->root_id, dst_canon_path, dst_filename, NULL); */ - - if (strcmp (src_repo_id, dst_repo_id) == 0 || - is_virtual_repo_and_origin (src_repo, dst_repo)) { - - /* get src dirent */ - src_dent = get_dirent_by_path (src_repo, NULL, - src_canon_path, src_filename, error); - if (!src_dent) { - seaf_warning("[copy file] file %s/%s doesn't exist.\n", src_canon_path, src_filename); - ret = -1; - goto out; - } - - gint64 file_size = (src_dent->version > 0) ? src_dent->size : -1; - - /* duplicate src dirent with new name */ - dst_dent = seaf_dirent_new (dir_version_from_repo_version(dst_repo->version), - src_dent->id, src_dent->mode, dst_filename, - src_dent->mtime, user, file_size); - - if (put_dirent_and_commit (dst_repo, - dst_canon_path, - &dst_dent, - 1, - 0, - user, - error) < 0) { - if (!error) - g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_GENERAL, - "failed to put dirent"); - ret = -1; - goto out; - } - - seaf_repo_manager_merge_virtual_repo (mgr, dst_repo_id, NULL); - - update_repo_size (dst_repo_id); - } else if (!synchronous) { - background = TRUE; - task_id = seaf_copy_manager_add_task (seaf->copy_mgr, - src_repo_id, - src_canon_path, - src_filename, - dst_repo_id, - dst_canon_path, - dst_filename, - 0, - user, - cross_repo_copy, - need_progress); - if (need_progress && !task_id) { - seaf_warning ("Failed to start copy task.\n"); - g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_GENERAL, - "failed to start copy task"); - ret = -1; - goto out; - } - } else { - /* Synchronous for cross-repo copy */ - if (cross_repo_copy (src_repo_id, - src_canon_path, - src_filename, - dst_repo_id, - dst_canon_path, - dst_filename, - 0, - user, - NULL) < 0) { - g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_GENERAL, - "Failed to move"); - ret = -1; - goto out; - } - } - -out: - if (src_repo) - seaf_repo_unref (src_repo); - if (dst_repo) - seaf_repo_unref (dst_repo); - if (dst_head_commit) - seaf_commit_unref(dst_head_commit); - if (src_canon_path) - g_free (src_canon_path); - if (dst_canon_path) - g_free (dst_canon_path); - if (src_dent) - seaf_dirent_free(src_dent); - if (dst_dent) - seaf_dirent_free(dst_dent); - - if (ret == 0) { - res = seafile_copy_result_new (); - g_object_set (res, "background", background, "task_id", task_id, NULL); - g_free (task_id); - } - - return res; -} - static gboolean check_move (SeafRepo *src_repo, SeafRepo *dst_repo, const char *src_path, const char *dst_path, @@ -2769,6 +2641,7 @@ seaf_repo_manager_copy_multiple_files (SeafRepoManager *mgr, const char *dst_path, const char *dst_filenames, const char *user, + const char *friendly_name, int need_progress, int synchronous, GError **error) @@ -2861,6 +2734,9 @@ seaf_repo_manager_copy_multiple_files (SeafRepoManager *mgr, dst_dents = g_new0 (SeafDirent *, file_num); i = 0; + const char *username = user; + if (friendly_name) + username = friendly_name; for (ptr = dst_names; ptr; ptr = ptr->next) { name = ptr->data; if (strcmp(name, "") == 0) { @@ -2871,7 +2747,7 @@ seaf_repo_manager_copy_multiple_files (SeafRepoManager *mgr, /* duplicate src dirents with new names */ dst_dents[i] = seaf_dirent_new (dir_version_from_repo_version (dst_repo->version), src_dents[i]->id, src_dents[i]->mode, name, - src_dents[i]->mtime, user, file_sizes[i]); + src_dents[i]->mtime, username, file_sizes[i]); i++; } if (put_dirent_and_commit (dst_repo, @@ -2880,6 +2756,7 @@ seaf_repo_manager_copy_multiple_files (SeafRepoManager *mgr, file_num, 0, user, + friendly_name, error) < 0) { if (!error) g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_GENERAL, @@ -2905,6 +2782,7 @@ seaf_repo_manager_copy_multiple_files (SeafRepoManager *mgr, dst_filenames, 0, user, + friendly_name, cross_repo_copy, need_progress); if (need_progress && !task_id) { @@ -2924,6 +2802,7 @@ seaf_repo_manager_copy_multiple_files (SeafRepoManager *mgr, dst_filenames, 0, user, + friendly_name, NULL) < 0) { g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_GENERAL, "Failed to move"); @@ -2974,6 +2853,7 @@ move_file_same_repo (const char *repo_id, int file_num, int replace, const char *user, + const char *friendly_name, GError **error) { SeafRepo *repo = NULL; @@ -2995,7 +2875,10 @@ move_file_same_repo (const char *repo_id, if (*dst_path == '/') dst_path = dst_path + 1; - root_id_after_put = post_multi_files_recursive (repo, head_commit->root_id, dst_path, dent_list, user, + const char *username = user; + if (friendly_name) + username = friendly_name; + root_id_after_put = post_multi_files_recursive (repo, head_commit->root_id, dst_path, dent_list, username, replace, &name_list); g_list_free (dent_list); g_list_free_full (name_list, (GDestroyNotify)g_free); @@ -3025,7 +2908,7 @@ move_file_same_repo (const char *repo_id, } if (gen_new_commit (repo_id, head_commit, root_id, - user, buf, NULL, TRUE, error) < 0) + user, friendly_name, buf, NULL, TRUE, error) < 0) ret = -1; out: @@ -3049,6 +2932,7 @@ cross_repo_move (const char *src_repo_id, const char *dst_filename, int replace, const char *modifier, + const char *friendly_name, CopyTask *task) { SeafRepo *src_repo = NULL, *dst_repo = NULL; @@ -3174,10 +3058,13 @@ cross_repo_move (const char *src_repo_id, i = 0; /* do copy */ + const char *username = modifier; + if (friendly_name) + username = friendly_name; for (ptr = dst_names; ptr; ptr = ptr->next) { name = ptr->data; new_id = copy_recursive (src_repo, dst_repo, src_crypt, dst_crypt, - src_dents[i]->id, src_dents[i]->mode, modifier, task, + src_dents[i]->id, src_dents[i]->mode, username, task, &new_size); if (!new_id) { err_str = COPY_ERR_INTERNAL; @@ -3187,7 +3074,7 @@ cross_repo_move (const char *src_repo_id, } dst_dents[i] = seaf_dirent_new (dir_version_from_repo_version(dst_repo->version), new_id, src_dents[i]->mode, name, - src_dents[i]->mtime, modifier, new_size); + src_dents[i]->mtime, username, new_size); g_free (new_id); i++; } @@ -3198,6 +3085,7 @@ cross_repo_move (const char *src_repo_id, file_num, replace, modifier, + friendly_name, NULL) < 0) { err_str = COPY_ERR_INTERNAL; ret = -1; @@ -3207,7 +3095,7 @@ cross_repo_move (const char *src_repo_id, seaf_repo_manager_merge_virtual_repo (seaf->repo_mgr, dst_repo_id, NULL); if (seaf_repo_manager_del_file (seaf->repo_mgr, src_repo_id, src_path, - src_filename, modifier, NULL) < 0) { + src_filename, modifier, friendly_name, NULL) < 0) { err_str = COPY_ERR_INTERNAL; ret = -1; goto out; @@ -3296,6 +3184,7 @@ seaf_repo_manager_move_multiple_files (SeafRepoManager *mgr, const char *dst_filenames, int replace, const char *user, + const char *friendly_name, int need_progress, int synchronous, GError **error) @@ -3388,6 +3277,9 @@ seaf_repo_manager_move_multiple_files (SeafRepoManager *mgr, dst_dents = g_new0 (SeafDirent *, file_num); i = 0; + const char *username = user; + if (friendly_name) + username = friendly_name; for (ptr = dst_names; ptr; ptr = ptr->next) { name = ptr->data; if (strcmp(name, "") == 0) { @@ -3398,7 +3290,7 @@ seaf_repo_manager_move_multiple_files (SeafRepoManager *mgr, /* duplicate src dirents with new names */ dst_dents[i] = seaf_dirent_new (dir_version_from_repo_version (dst_repo->version), src_dents[i]->id, src_dents[i]->mode, name, - src_dents[i]->mtime, user, file_sizes[i]); + src_dents[i]->mtime, username, file_sizes[i]); i++; } /* move file within the same repo */ @@ -3407,7 +3299,8 @@ seaf_repo_manager_move_multiple_files (SeafRepoManager *mgr, src_filenames, src_canon_path, src_dents, dst_canon_path, dst_dents, - file_num, replace, user, error) < 0) { + file_num, replace, + user, friendly_name, error) < 0) { ret = -1; goto out; } @@ -3419,6 +3312,7 @@ seaf_repo_manager_move_multiple_files (SeafRepoManager *mgr, file_num, replace, user, + friendly_name, NULL) < 0) { ret = -1; goto out; @@ -3426,7 +3320,7 @@ seaf_repo_manager_move_multiple_files (SeafRepoManager *mgr, seaf_repo_manager_merge_virtual_repo (mgr, dst_repo->id, NULL); if (seaf_repo_manager_del_file (mgr, src_repo->id, src_path, - src_filenames, user, error) < 0) { + src_filenames, user, friendly_name, error) < 0) { ret = -1; goto out; } @@ -3448,6 +3342,7 @@ seaf_repo_manager_move_multiple_files (SeafRepoManager *mgr, dst_filenames, 0, user, + friendly_name, cross_repo_move, need_progress); if (need_progress && !task_id) { @@ -3467,6 +3362,7 @@ seaf_repo_manager_move_multiple_files (SeafRepoManager *mgr, dst_filenames, replace, user, + friendly_name, NULL) < 0) { g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_GENERAL, "Failed to move"); @@ -3517,6 +3413,7 @@ seaf_repo_manager_mkdir_with_parents (SeafRepoManager *mgr, const char *parent_dir, const char *new_dir_path, const char *user, + const char *friendly_name, GError **error) { SeafRepo *repo = NULL; @@ -3643,7 +3540,7 @@ seaf_repo_manager_mkdir_with_parents (SeafRepoManager *mgr, /* Commit. */ snprintf(buf, SEAF_PATH_MAX, "Added directory \"%s\"", relative_dir_can); if (gen_new_commit (repo_id, head_commit, root_id, - user, buf, NULL, TRUE, error) < 0) { + user, friendly_name, buf, NULL, TRUE, error) < 0) { ret = -1; g_free (root_id); goto out; @@ -3678,6 +3575,7 @@ seaf_repo_manager_post_dir (SeafRepoManager *mgr, const char *parent_dir, const char *new_dir_name, const char *user, + const char *friendly_name, GError **error) { SeafRepo *repo = NULL; @@ -3724,7 +3622,7 @@ seaf_repo_manager_post_dir (SeafRepoManager *mgr, /* Commit. */ snprintf(buf, SEAF_PATH_MAX, "Added directory \"%s\"", new_dir_name); if (gen_new_commit (repo_id, head_commit, root_id, - user, buf, NULL, TRUE, error) < 0) { + user, friendly_name, buf, NULL, TRUE, error) < 0) { ret = -1; goto out; } @@ -3749,6 +3647,7 @@ seaf_repo_manager_post_empty_file (SeafRepoManager *mgr, const char *parent_dir, const char *new_file_name, const char *user, + const char *friendly_name, GError **error) { SeafRepo *repo = NULL; @@ -3774,13 +3673,16 @@ seaf_repo_manager_post_empty_file (SeafRepoManager *mgr, goto out; } + const char *username = user; + if (friendly_name) + username = friendly_name; FAIL_IF_FILE_EXISTS(repo->store_id, repo->version, head_commit->root_id, canon_path, new_file_name, NULL); if (!new_dent) { new_dent = seaf_dirent_new (dir_version_from_repo_version(repo->version), EMPTY_SHA1, STD_FILE_MODE, new_file_name, - (gint64)time(NULL), user, 0); + (gint64)time(NULL), username, 0); } root_id = do_post_file (repo, @@ -3796,7 +3698,7 @@ seaf_repo_manager_post_empty_file (SeafRepoManager *mgr, /* Commit. */ snprintf(buf, SEAF_PATH_MAX, "Added \"%s\"", new_file_name); if (gen_new_commit (repo_id, head_commit, root_id, - user, buf, NULL, TRUE, error) < 0) { + user, friendly_name, buf, NULL, TRUE, error) < 0) { ret = -1; goto out; } @@ -3940,6 +3842,7 @@ seaf_repo_manager_rename_file (SeafRepoManager *mgr, const char *oldname, const char *newname, const char *user, + const char *friendly_name, GError **error) { SeafRepo *repo = NULL; @@ -3989,7 +3892,7 @@ seaf_repo_manager_rename_file (SeafRepoManager *mgr, } if (gen_new_commit (repo_id, head_commit, root_id, - user, buf, NULL, TRUE, error) < 0) { + user, friendly_name, buf, NULL, TRUE, error) < 0) { ret = -1; goto out; } @@ -4117,6 +4020,7 @@ seaf_repo_manager_put_file (SeafRepoManager *mgr, const char *parent_dir, const char *file_name, const char *user, + const char *friendly_name, const char *head_id, char **new_file_id, GError **error) @@ -4195,9 +4099,12 @@ seaf_repo_manager_put_file (SeafRepoManager *mgr, } rawdata_to_hex(sha1, hex, 20); + const char *username = user; + if (friendly_name) + username = friendly_name; new_dent = seaf_dirent_new (dir_version_from_repo_version(repo->version), hex, STD_FILE_MODE, file_name, - (gint64)time(NULL), user, size); + (gint64)time(NULL), username, size); if (!fullpath) fullpath = g_build_filename(parent_dir, file_name, NULL); @@ -4225,7 +4132,7 @@ seaf_repo_manager_put_file (SeafRepoManager *mgr, /* Commit. */ snprintf(buf, SEAF_PATH_MAX, "Modified \"%s\"", file_name); - if (gen_new_commit (repo_id, head_commit, root_id, user, buf, NULL, TRUE, error) < 0) { + if (gen_new_commit (repo_id, head_commit, root_id, user, friendly_name, buf, NULL, TRUE, error) < 0) { ret = -1; goto out; } @@ -4283,6 +4190,7 @@ seaf_repo_manager_update_dir (SeafRepoManager *mgr, const char *dir_path, const char *new_dir_id, const char *user, + const char *friendly_name, const char *head_id, char *new_commit_id, GError **error) @@ -4307,7 +4215,7 @@ seaf_repo_manager_update_dir (SeafRepoManager *mgr, commit_desc = g_strdup("Auto merge by system"); if (gen_new_commit (repo_id, head_commit, new_dir_id, - user, commit_desc, new_commit_id, TRUE, error) < 0) + user, friendly_name, commit_desc, new_commit_id, TRUE, error) < 0) ret = -1; g_free (commit_desc); goto out; @@ -4340,7 +4248,7 @@ seaf_repo_manager_update_dir (SeafRepoManager *mgr, commit_desc = g_strdup("Auto merge by system"); if (gen_new_commit (repo_id, head_commit, root_id, - user, commit_desc, new_commit_id, TRUE, error) < 0) { + user, friendly_name, commit_desc, new_commit_id, TRUE, error) < 0) { ret = -1; g_free (commit_desc); goto out; @@ -4710,6 +4618,7 @@ seaf_repo_manager_revert_file (SeafRepoManager *mgr, const char *old_commit_id, const char *file_path, const char *user, + const char *friendly_name, GError **error) { SeafRepo *repo = NULL; @@ -4829,7 +4738,7 @@ seaf_repo_manager_revert_file (SeafRepoManager *mgr, #endif snprintf(buf, SEAF_PATH_MAX, "Reverted file \"%s\" to status at %s", filename, time_str); if (gen_new_commit (repo_id, head_commit, root_id, - user, buf, NULL, TRUE, error) < 0) { + user, friendly_name, buf, NULL, TRUE, error) < 0) { ret = -1; goto out; } @@ -4931,6 +4840,7 @@ seaf_repo_manager_revert_dir (SeafRepoManager *mgr, const char *old_commit_id, const char *dir_path, const char *user, + const char *friendly_name, GError **error) { SeafRepo *repo = NULL; @@ -5038,7 +4948,7 @@ seaf_repo_manager_revert_dir (SeafRepoManager *mgr, /* Commit. */ snprintf(buf, SEAF_PATH_MAX, "Recovered deleted directory \"%s\"", dirname); if (gen_new_commit (repo_id, head_commit, root_id, - user, buf, NULL, TRUE, error) < 0) { + user, friendly_name, buf, NULL, TRUE, error) < 0) { ret = -1; goto out; } @@ -5959,6 +5869,7 @@ seaf_repo_manager_revert_on_server (SeafRepoManager *mgr, const char *repo_id, const char *commit_id, const char *user_name, + const char *friendly_name, GError **error) { SeafRepo *repo; @@ -5993,7 +5904,7 @@ seaf_repo_manager_revert_on_server (SeafRepoManager *mgr, #endif new_commit = seaf_commit_new (NULL, repo->id, commit->root_id, - user_name, EMPTY_SHA1, + user_name, friendly_name, EMPTY_SHA1, desc, 0); new_commit->parent_id = g_strdup (repo->head->commit_id); diff --git a/server/seaf-server.c b/server/seaf-server.c index 43c4798b..67e21ced 100644 --- a/server/seaf-server.c +++ b/server/seaf-server.c @@ -150,7 +150,7 @@ static void start_rpc_service (const char *seafile_dir, searpc_server_register_function ("seafserv-threaded-rpcserver", seafile_revert_on_server, "seafile_revert_on_server", - searpc_signature_int__string_string_string()); + searpc_signature_int__string_string_string_string()); searpc_server_register_function ("seafserv-threaded-rpcserver", seafile_diff, @@ -160,7 +160,7 @@ static void start_rpc_service (const char *seafile_dir, searpc_server_register_function ("seafserv-threaded-rpcserver", seafile_post_file, "seafile_post_file", - searpc_signature_int__string_string_string_string_string()); + searpc_signature_int__string_string_string_string_string_string()); /* searpc_server_register_function ("seafserv-threaded-rpcserver", */ /* seafile_post_file_blocks, */ @@ -169,12 +169,12 @@ static void start_rpc_service (const char *seafile_dir, searpc_server_register_function ("seafserv-threaded-rpcserver", seafile_post_multi_files, "seafile_post_multi_files", - searpc_signature_string__string_string_string_string_string_int()); + searpc_signature_string__string_string_string_string_string_string_int()); searpc_server_register_function ("seafserv-threaded-rpcserver", seafile_put_file, "seafile_put_file", - searpc_signature_string__string_string_string_string_string_string()); + searpc_signature_string__string_string_string_string_string_string_string()); /* searpc_server_register_function ("seafserv-threaded-rpcserver", */ /* seafile_put_file_blocks, */ /* "seafile_put_file_blocks", */ @@ -183,37 +183,37 @@ static void start_rpc_service (const char *seafile_dir, searpc_server_register_function ("seafserv-threaded-rpcserver", seafile_post_empty_file, "seafile_post_empty_file", - searpc_signature_int__string_string_string_string()); + searpc_signature_int__string_string_string_string_string()); searpc_server_register_function ("seafserv-threaded-rpcserver", seafile_post_dir, "seafile_post_dir", - searpc_signature_int__string_string_string_string()); + searpc_signature_int__string_string_string_string_string()); searpc_server_register_function ("seafserv-threaded-rpcserver", seafile_mkdir_with_parents, "seafile_mkdir_with_parents", - searpc_signature_int__string_string_string_string()); + searpc_signature_int__string_string_string_string_string()); searpc_server_register_function ("seafserv-threaded-rpcserver", seafile_del_file, "seafile_del_file", - searpc_signature_int__string_string_string_string()); + searpc_signature_int__string_string_string_string_string()); searpc_server_register_function ("seafserv-threaded-rpcserver", seafile_copy_file, "seafile_copy_file", - searpc_signature_object__string_string_string_string_string_string_string_int_int()); + searpc_signature_object__string_string_string_string_string_string_string_string_int_int()); searpc_server_register_function ("seafserv-threaded-rpcserver", seafile_move_file, "seafile_move_file", - searpc_signature_object__string_string_string_string_string_string_int_string_int_int()); + searpc_signature_object__string_string_string_string_string_string_int_string_string_int_int()); searpc_server_register_function ("seafserv-threaded-rpcserver", seafile_rename_file, "seafile_rename_file", - searpc_signature_int__string_string_string_string_string()); + searpc_signature_int__string_string_string_string_string_string()); searpc_server_register_function ("seafserv-threaded-rpcserver", seafile_is_valid_filename, @@ -298,12 +298,12 @@ static void start_rpc_service (const char *seafile_dir, searpc_server_register_function ("seafserv-threaded-rpcserver", seafile_revert_file, "seafile_revert_file", - searpc_signature_int__string_string_string_string()); + searpc_signature_int__string_string_string_string_string()); searpc_server_register_function ("seafserv-threaded-rpcserver", seafile_revert_dir, "seafile_revert_dir", - searpc_signature_int__string_string_string_string()); + searpc_signature_int__string_string_string_string_string()); searpc_server_register_function ("seafserv-threaded-rpcserver", seafile_check_repo_blocks_missing, @@ -571,7 +571,7 @@ static void start_rpc_service (const char *seafile_dir, searpc_server_register_function ("seafserv-threaded-rpcserver", seafile_web_get_access_token, "seafile_web_get_access_token", - searpc_signature_string__string_string_string_string_int()); + searpc_signature_string__string_string_string_string_string_int()); searpc_server_register_function ("seafserv-threaded-rpcserver", seafile_web_query_access_token, "seafile_web_query_access_token", diff --git a/server/seafile-session.c b/server/seafile-session.c index a2409ffd..512394fe 100644 --- a/server/seafile-session.c +++ b/server/seafile-session.c @@ -572,6 +572,7 @@ copy_template_files_recursive (SeafileSession *session, repo_dir_path, name, "System", + "System", NULL); if (rc < 0) seaf_warning ("Failed to add template file %s.\n", sub_path); @@ -581,6 +582,7 @@ copy_template_files_recursive (SeafileSession *session, repo_dir_path, name, "System", + "System", NULL); if (rc < 0) { seaf_warning ("Failed to add template dir %s.\n", sub_path); diff --git a/server/upload-file.c b/server/upload-file.c index 7ba17656..fde8322f 100755 --- a/server/upload-file.c +++ b/server/upload-file.c @@ -59,6 +59,7 @@ typedef struct RecvFSM { char *repo_id; char *user; + char *friendly_name; char *boundary; /* boundary of multipart form-data. */ char *input_name; /* input name of the current form field. */ char *parent_dir; @@ -382,6 +383,7 @@ create_relative_path (RecvFSM *fsm, char *parent_dir, char *relative_path) parent_dir, relative_path, fsm->user, + fsm->friendly_name, &error); if (rc < 0) { if (error) { @@ -574,6 +576,7 @@ upload_api_cb(evhtp_request_t *req, void *arg) filenames_json, tmp_files_json, fsm->user, + fsm->friendly_name, replace, &ret_json, fsm->need_idx_progress ? &task_id : NULL, @@ -766,6 +769,7 @@ upload_blks_api_cb(evhtp_request_t *req, void *arg) file_name, blockids_json, fsm->user, + fsm->friendly_name, file_size, replace, &new_file_id, @@ -1189,6 +1193,7 @@ upload_ajax_cb(evhtp_request_t *req, void *arg) filenames_json, tmp_files_json, fsm->user, + fsm->friendly_name, 0, &ret_json, fsm->need_idx_progress ? &task_id : NULL, @@ -1347,6 +1352,7 @@ update_api_cb(evhtp_request_t *req, void *arg) parent_dir, filename, fsm->user, + fsm->friendly_name, head_id, &new_file_id, &error); @@ -1459,6 +1465,7 @@ update_blks_api_cb(evhtp_request_t *req, void *arg) filename, blockids_json, fsm->user, + fsm->friendly_name, file_size, 1, &new_file_id, @@ -1715,6 +1722,7 @@ update_ajax_cb(evhtp_request_t *req, void *arg) parent_dir, filename, fsm->user, + fsm->friendly_name, head_id, &new_file_id, &error); @@ -2316,6 +2324,7 @@ check_access_token (const char *token, char **repo_id, char **parent_dir, char **user, + char **friendly_name, char **token_type, char **err_msg) { @@ -2359,6 +2368,7 @@ check_access_token (const char *token, *repo_id = g_strdup (_repo_id); *user = g_strdup (seafile_web_access_get_username (webaccess)); + *friendly_name = g_strdup (seafile_web_access_get_friendly_name (webaccess)); _obj_id = seafile_web_access_get_obj_id (webaccess); parent_dir_json = json_loadb (_obj_id, strlen (_obj_id), 0, NULL); @@ -2455,7 +2465,7 @@ static evhtp_res upload_headers_cb (evhtp_request_t *req, evhtp_headers_t *hdr, void *arg) { char **parts = NULL; - char *token, *repo_id = NULL, *user = NULL; + char *token, *repo_id = NULL, *user = NULL, *friendly_name = NULL; char *parent_dir = NULL; char *boundary = NULL; gint64 content_len; @@ -2485,7 +2495,7 @@ upload_headers_cb (evhtp_request_t *req, evhtp_headers_t *hdr, void *arg) } char *url_op = parts[0]; - if (check_access_token (token, url_op, &repo_id, &parent_dir, &user, &token_type, &err_msg) < 0) { + if (check_access_token (token, url_op, &repo_id, &parent_dir, &user, &friendly_name, &token_type, &err_msg) < 0) { error_code = EVHTP_RES_FORBIDDEN; goto err; } @@ -2525,6 +2535,7 @@ upload_headers_cb (evhtp_request_t *req, evhtp_headers_t *hdr, void *arg) fsm->repo_id = repo_id; fsm->parent_dir = parent_dir; fsm->user = user; + fsm->friendly_name = friendly_name; fsm->token_type = token_type; fsm->rstart = rstart; fsm->rend = rend; @@ -2570,6 +2581,7 @@ upload_headers_cb (evhtp_request_t *req, evhtp_headers_t *hdr, void *arg) g_free (repo_id); g_free (user); + g_free (friendly_name); g_free (boundary); g_free (token_type); g_free (progress_id); diff --git a/server/virtual-repo.c b/server/virtual-repo.c index 2698c2de..69e2bc35 100644 --- a/server/virtual-repo.c +++ b/server/virtual-repo.c @@ -99,6 +99,7 @@ do_create_virtual_repo (SeafRepoManager *mgr, commit = seaf_commit_new (NULL, repo->id, root_id, /* root id */ user, /* creator */ + NULL, EMPTY_SHA1, /* creator id */ repo_desc, /* description */ 0); /* ctime */ @@ -903,6 +904,7 @@ static void *merge_virtual_repo (void *vtask) "/", orig_root, orig_head->creator_name, + orig_head->username, head->commit_id, NULL, NULL); @@ -922,6 +924,7 @@ static void *merge_virtual_repo (void *vtask) vinfo->path, root, head->creator_name, + head->username, orig_head->commit_id, new_base_commit, NULL); @@ -973,6 +976,7 @@ static void *merge_virtual_repo (void *vtask) "/", opt.merged_tree_root, orig_head->creator_name, + orig_head->username, head->commit_id, NULL, NULL); @@ -988,6 +992,7 @@ static void *merge_virtual_repo (void *vtask) vinfo->path, opt.merged_tree_root, head->creator_name, + head->username, orig_head->commit_id, new_base_commit, NULL); @@ -1236,6 +1241,7 @@ seaf_repo_manager_repair_virtual_repo (char *repo_id) "/", opt.merged_tree_root, orig_head->creator_name, + orig_head->username, head->commit_id, NULL, NULL); @@ -1251,6 +1257,7 @@ seaf_repo_manager_repair_virtual_repo (char *repo_id) vinfo->path, opt.merged_tree_root, head->creator_name, + head->username, orig_head->commit_id, new_base_commit, NULL); diff --git a/server/web-accesstoken-mgr.c b/server/web-accesstoken-mgr.c index d6504bd2..562b68bd 100644 --- a/server/web-accesstoken-mgr.c +++ b/server/web-accesstoken-mgr.c @@ -34,6 +34,7 @@ typedef struct { char *obj_id; char *op; char *username; + char *friendly_name; long expire_time; gboolean use_onetime; } AccessInfo; @@ -48,6 +49,7 @@ free_access_info (AccessInfo *info) g_free (info->obj_id); g_free (info->op); g_free (info->username); + g_free (info->friendly_name); g_free (info); } @@ -128,6 +130,7 @@ seaf_web_at_manager_get_access_token (SeafWebAccessTokenManager *mgr, const char *obj_id, const char *op, const char *username, + const char *friendly_name, int use_onetime, GError **error) { @@ -167,6 +170,7 @@ seaf_web_at_manager_get_access_token (SeafWebAccessTokenManager *mgr, info->obj_id = g_strdup (obj_id); info->op = g_strdup (op); info->username = g_strdup (username); + info->friendly_name = g_strdup (friendly_name); info->expire_time = expire; if (use_onetime) { info->use_onetime = TRUE; @@ -188,6 +192,7 @@ seaf_web_at_manager_get_access_token (SeafWebAccessTokenManager *mgr, "obj_id", info->obj_id, "op", info->op, "username", info->username, + "friendly_name", info->friendly_name, NULL); if (zip_download_mgr_start_zip_task (seaf->zip_download_mgr, @@ -231,6 +236,7 @@ seaf_web_at_manager_query_access_token (SeafWebAccessTokenManager *mgr, "obj_id", info->obj_id, "op", info->op, "username", info->username, + "friendly_name", info->friendly_name, NULL); if (info->use_onetime) { diff --git a/server/web-accesstoken-mgr.h b/server/web-accesstoken-mgr.h index b2d310f5..bbb15b4a 100644 --- a/server/web-accesstoken-mgr.h +++ b/server/web-accesstoken-mgr.h @@ -28,6 +28,7 @@ seaf_web_at_manager_get_access_token (SeafWebAccessTokenManager *mgr, const char *obj_id, const char *op, const char *username, + const char *friendly_name, int use_onetime, GError **error); diff --git a/tests/config.py b/tests/config.py index c70841c9..c6b7fde3 100644 --- a/tests/config.py +++ b/tests/config.py @@ -1,6 +1,8 @@ USER = 'testuser@test.seafile.com' +USERNAME = 'test_friendly_name' PASSWORD = 'testuser' USER2 = 'testuser2@test.seafile.com' +USERNAME2 = 'test_friendly_name2' PASSWORD2 = 'testuser2' ADMIN_USER = 'adminuser@test.seafile.com' ADMIN_PASSWORD = 'adminuser' diff --git a/tests/conftest.py b/tests/conftest.py index 372c492e..b3abd461 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -7,7 +7,7 @@ from tenacity import retry, stop_after_attempt, wait_fixed from tests.config import ( ADMIN_PASSWORD, ADMIN_USER, INACTIVE_PASSWORD, INACTIVE_USER, PASSWORD, - PASSWORD2, USER, USER2 + PASSWORD2, USER, USER2, USERNAME ) from tests.utils import create_and_get_repo, randstring, create_and_get_group @@ -43,10 +43,10 @@ def encrypted_repo(): 'test_repo_{}'.format(randstring(10)), '', USER, passwd='123' ) try: - seafile_api.post_dir(repo.id, '/', 'dir1', USER) - seafile_api.post_dir(repo.id, '/', 'dir2', USER) - seafile_api.post_dir(repo.id, '/dir1', 'subdir1', USER) - seafile_api.post_dir(repo.id, '/dir2', 'subdir2', USER) + seafile_api.post_dir(repo.id, '/', 'dir1', USER, USERNAME) + seafile_api.post_dir(repo.id, '/', 'dir2', USER, USERNAME) + seafile_api.post_dir(repo.id, '/dir1', 'subdir1', USER, USERNAME) + seafile_api.post_dir(repo.id, '/dir2', 'subdir2', USER, USERNAME) yield repo finally: if seafile_api.get_repo(repo.id): @@ -59,8 +59,8 @@ def repo(): 'test_repo_{}'.format(randstring(10)), '', USER, passwd=None ) try: - seafile_api.post_dir(repo.id, '/', 'dir1', USER) - seafile_api.post_dir(repo.id, '/', 'dir2', USER) + seafile_api.post_dir(repo.id, '/', 'dir1', USER, USERNAME) + seafile_api.post_dir(repo.id, '/', 'dir2', USER, USERNAME) yield repo finally: if seafile_api.get_repo(repo.id): diff --git a/tests/test_file_operation/test_file_operation.py b/tests/test_file_operation/test_file_operation.py index 994abcb4..06ff5e69 100644 --- a/tests/test_file_operation/test_file_operation.py +++ b/tests/test_file_operation/test_file_operation.py @@ -1,7 +1,7 @@ import pytest import os import time -from tests.config import USER +from tests.config import USER, USERNAME from seaserv import seafile_api as api file_name = 'test.txt' @@ -24,16 +24,16 @@ def test_file_operation(): create_the_file() # test post_file - assert api.post_file(t_repo_id1, file_path, '/', file_name, USER) == 0 + assert api.post_file(t_repo_id1, file_path, '/', file_name, USER, USERNAME) == 0 t_file_id = api.get_file_id_by_path(t_repo_id1, '/' + file_name) t_file_size = len(file_content) assert t_file_size == api.get_file_size(t_repo_id1, t_repo_version, t_file_id) # test post_dir - assert api.post_dir(t_repo_id1, '/', dir_name, USER) == 0 + assert api.post_dir(t_repo_id1, '/', dir_name, USER, USERNAME) == 0 # test copy_file (synchronize) - t_copy_file_result1 = api.copy_file(t_repo_id1, '/', '[\"'+file_name+'\"]', t_repo_id1, '/', '[\"'+new_file_name+'\"]', USER, 0, 1) + t_copy_file_result1 = api.copy_file(t_repo_id1, '/', '[\"'+file_name+'\"]', t_repo_id1, '/', '[\"'+new_file_name+'\"]', USER, USERNAME, 0, 1) assert t_copy_file_result1 assert t_copy_file_result1.task_id is None assert not t_copy_file_result1.background @@ -44,7 +44,7 @@ def test_file_operation(): t_repo_id2 = api.create_repo('test_file_operation2', '', USER, passwd = None) usage = api.get_user_self_usage (USER) api.set_user_quota(USER, usage + 1); - t_copy_file_result2 = api.copy_file(t_repo_id1, '/', '[\"'+file_name+'\"]', t_repo_id2, '/', '[\"'+file_name+'\"]', USER, 1, 0) + t_copy_file_result2 = api.copy_file(t_repo_id1, '/', '[\"'+file_name+'\"]', t_repo_id2, '/', '[\"'+file_name+'\"]', USER, USERNAME, 1, 0) assert t_copy_file_result2 assert t_copy_file_result2.background while True: @@ -56,7 +56,7 @@ def test_file_operation(): break; api.set_user_quota(USER, -1); - t_copy_file_result2 = api.copy_file(t_repo_id1, '/', '[\"'+file_name+'\"]', t_repo_id2, '/', '[\"'+file_name+'\"]', USER, 1, 0) + t_copy_file_result2 = api.copy_file(t_repo_id1, '/', '[\"'+file_name+'\"]', t_repo_id2, '/', '[\"'+file_name+'\"]', USER, USERNAME, 1, 0) assert t_copy_file_result2 assert t_copy_file_result2.task_id assert t_copy_file_result2.background @@ -70,7 +70,7 @@ def test_file_operation(): # test move_file (synchronize) t_move_file_info1 = api.get_dirent_by_path(t_repo_id1, '/' + new_file_name) - t_move_file_result1 = api.move_file(t_repo_id1, '/', '[\"'+new_file_name+'\"]', t_repo_id1, '/' + dir_name, '[\"'+new_file_name+'\"]', 1, USER, 0, 1) + t_move_file_result1 = api.move_file(t_repo_id1, '/', '[\"'+new_file_name+'\"]', t_repo_id1, '/' + dir_name, '[\"'+new_file_name+'\"]', 1, USER, USERNAME, 0, 1) assert t_move_file_result1 t_move_file_info2 = api.get_dirent_by_path(t_repo_id1, '/' + dir_name + '/' + new_file_name) assert t_move_file_info1.mtime == t_move_file_info2.mtime @@ -78,7 +78,7 @@ def test_file_operation(): assert t_file_id is None # test move_file (synchronize) - t_move_file_result1 = api.move_file(t_repo_id1, '/' + dir_name, '[\"'+new_file_name+'\"]', t_repo_id1, '/', '[\"'+new_file_name_2+'\"]', 1, USER, 0, 1) + t_move_file_result1 = api.move_file(t_repo_id1, '/' + dir_name, '[\"'+new_file_name+'\"]', t_repo_id1, '/', '[\"'+new_file_name_2+'\"]', 1, USER, USERNAME, 0, 1) assert t_move_file_result1 t_file_id = api.get_file_id_by_path(t_repo_id1, '/' + dir_name + '/' + new_file_name) assert t_file_id is None @@ -86,7 +86,7 @@ def test_file_operation(): # test move_file (asynchronous) usage = api.get_user_self_usage (USER) api.set_user_quota(USER, usage + 1); - t_move_file_result2 = api.move_file(t_repo_id1, '/', '[\"'+file_name+'\"]', t_repo_id2, '/' , '[\"'+new_file_name+'\"]', 1, USER, 1, 0) + t_move_file_result2 = api.move_file(t_repo_id1, '/', '[\"'+file_name+'\"]', t_repo_id2, '/' , '[\"'+new_file_name+'\"]', 1, USER, USERNAME, 1, 0) assert t_move_file_result2 assert t_move_file_result2.task_id assert t_move_file_result2.background @@ -99,7 +99,7 @@ def test_file_operation(): break api.set_user_quota(USER, -1); - t_move_file_result2 = api.move_file(t_repo_id1, '/', '[\"'+file_name+'\"]', t_repo_id2, '/' , '[\"'+new_file_name+'\"]', 1, USER, 1, 0) + t_move_file_result2 = api.move_file(t_repo_id1, '/', '[\"'+file_name+'\"]', t_repo_id2, '/' , '[\"'+new_file_name+'\"]', 1, USER, USERNAME, 1, 0) assert t_move_file_result2 assert t_move_file_result2.task_id assert t_move_file_result2.background @@ -112,15 +112,15 @@ def test_file_operation(): assert t_file_size == api.get_file_size(t_repo_id2, t_repo_version, t_file_id) # test post_empty_file - assert api.post_empty_file(t_repo_id1, '/' + dir_name, empty_file_name, USER) == 0 + assert api.post_empty_file(t_repo_id1, '/' + dir_name, empty_file_name, USER, USERNAME) == 0 t_file_id = api.get_file_id_by_path(t_repo_id1, '/' + dir_name + '/' + empty_file_name) assert api.get_file_size(t_repo_id1, t_repo_version, t_file_id) == 0 # test rename_file - assert api.rename_file(t_repo_id1, '/' + dir_name, empty_file_name, new_empty_file_name, USER) == 0 + assert api.rename_file(t_repo_id1, '/' + dir_name, empty_file_name, new_empty_file_name, USER, USERNAME) == 0 #test put_file - t_new_file_id = api.put_file(t_repo_id1, file_path, '/' + dir_name, new_empty_file_name, USER, None) + t_new_file_id = api.put_file(t_repo_id1, file_path, '/' + dir_name, new_empty_file_name, USER, USERNAME, None) assert t_new_file_id # test get_file_revisions @@ -130,7 +130,7 @@ def test_file_operation(): assert t_commit_list[0].creator_name == USER # test del_file - assert api.del_file(t_repo_id2, '/', '[\"'+file_name+'\"]', USER) == 0 + assert api.del_file(t_repo_id2, '/', '[\"'+file_name+'\"]', USER, USERNAME) == 0 # test get_deleted t_deleted_file_list = api.get_deleted(t_repo_id2, 1) @@ -140,12 +140,12 @@ def test_file_operation(): assert t_deleted_file_list[0].basedir == '/' # test del a non-exist file. should return 0. - assert api.del_file(t_repo_id2, '/', '[\"'+file_name+'\"]', USER) == 0 + assert api.del_file(t_repo_id2, '/', '[\"'+file_name+'\"]', USER, USERNAME) == 0 - assert api.del_file(t_repo_id1, '/' + dir_name, '[\"'+new_empty_file_name+'\"]', USER) == 0 - assert api.del_file(t_repo_id1, '/' + dir_name, '[\"'+new_file_name+'\"]', USER) == 0 - assert api.del_file(t_repo_id2, '/', '[\"'+new_file_name+'\"]', USER) == 0 - assert api.del_file(t_repo_id1, '/', '[\"'+new_file_name_2+'\"]', USER) == 0 + assert api.del_file(t_repo_id1, '/' + dir_name, '[\"'+new_empty_file_name+'\"]', USER, USERNAME) == 0 + assert api.del_file(t_repo_id1, '/' + dir_name, '[\"'+new_file_name+'\"]', USER, USERNAME) == 0 + assert api.del_file(t_repo_id2, '/', '[\"'+new_file_name+'\"]', USER, USERNAME) == 0 + assert api.del_file(t_repo_id1, '/', '[\"'+new_file_name_2+'\"]', USER, USERNAME) == 0 time.sleep(1) api.remove_repo(t_repo_id1) diff --git a/tests/test_file_operation/test_merge_virtual_repo.py b/tests/test_file_operation/test_merge_virtual_repo.py index de1c42bc..3889203c 100644 --- a/tests/test_file_operation/test_merge_virtual_repo.py +++ b/tests/test_file_operation/test_merge_virtual_repo.py @@ -2,7 +2,7 @@ import requests import os import time -from tests.config import USER, USER2 +from tests.config import USER, USER2, USERNAME, USERNAME2 from seaserv import seafile_api as api from requests_toolbelt import MultipartEncoder @@ -36,7 +36,7 @@ def create_test_file(): def create_test_dir(repo, dir_name): parent_dir = '/' - api.post_dir(repo.id,parent_dir,dir_name,USER) + api.post_dir(repo.id,parent_dir,dir_name,USER, USERNAME) def assert_upload_response(response, replace, file_exist): assert response.status_code == 200 @@ -103,8 +103,8 @@ def del_local_files(): os.remove(chunked_part2_path) def test_merge_virtual_repo(repo): - api.post_dir(repo.id, '/dir1', 'subdir1', USER) - api.post_dir(repo.id, '/dir2', 'subdir2', USER) + api.post_dir(repo.id, '/dir1', 'subdir1', USER, USERNAME) + api.post_dir(repo.id, '/dir2', 'subdir2', USER, USERNAME) v_repo_id = api.share_subdir_to_user(repo.id, '/dir1', USER, USER2, 'rw') create_test_file() @@ -113,7 +113,7 @@ def test_merge_virtual_repo(repo): create_test_dir(repo,'test') #test upload file to vritual repo root dir. - token = api.get_fileserver_access_token(v_repo_id, obj_id, 'upload', USER2, False) + token = api.get_fileserver_access_token(v_repo_id, obj_id, 'upload', USER2, USERNAME2, False) upload_url_base = 'http://127.0.0.1:8082/upload-api/' + token m = MultipartEncoder( fields={ @@ -165,7 +165,7 @@ def test_merge_virtual_repo(repo): #test update file to virtual repo. write_file(file_path, file_content) - token = api.get_fileserver_access_token(v_repo_id, obj_id, 'update', USER2, False) + token = api.get_fileserver_access_token(v_repo_id, obj_id, 'update', USER2, USERNAME2, False) update_url_base = 'http://127.0.0.1:8082/update-api/' + token m = MultipartEncoder( fields={ @@ -183,7 +183,7 @@ def test_merge_virtual_repo(repo): repo_size = api.get_repo_size (repo.id) assert repo_size == total_size + file_size - api.del_file(v_repo_id, '/', '[\"'+file_name+'\"]', USER2) + api.del_file(v_repo_id, '/', '[\"'+file_name+'\"]', USER2, USERNAME2) time.sleep (1.5) v_repo_size = api.get_repo_size (v_repo_id) @@ -192,7 +192,7 @@ def test_merge_virtual_repo(repo): repo_size = api.get_repo_size (repo.id) assert repo_size == total_size - api.del_file(v_repo_id, '/', '[\"'+resumable_file_name+'\"]', USER2) + api.del_file(v_repo_id, '/', '[\"'+resumable_file_name+'\"]', USER2, USERNAME2) time.sleep (1.5) v_repo_size = api.get_repo_size (v_repo_id) @@ -201,7 +201,7 @@ def test_merge_virtual_repo(repo): repo_size = api.get_repo_size (repo.id) assert repo_size == 0 - api.del_file(repo.id, '/dir1', '[\"subdir1\"]', USER) - api.del_file(repo.id, '/dir2', '[\"subdir1\"]', USER) + api.del_file(repo.id, '/dir1', '[\"subdir1\"]', USER, USERNAME) + api.del_file(repo.id, '/dir2', '[\"subdir1\"]', USER, USERNAME) assert api.unshare_subdir_for_user(repo.id, '/dir1', USER, USER2) == 0 del_local_files() diff --git a/tests/test_file_operation/test_search_files.py b/tests/test_file_operation/test_search_files.py index c755895b..fc0fae01 100644 --- a/tests/test_file_operation/test_search_files.py +++ b/tests/test_file_operation/test_search_files.py @@ -1,7 +1,7 @@ import pytest import os import time -from tests.config import USER +from tests.config import USER, USERNAME from seaserv import seafile_api as api file_name = 'test.txt' @@ -19,8 +19,8 @@ def test_file_operation(): create_the_file() - assert api.post_file(t_repo_id1, file_path, '/', file_name, USER) == 0 - assert api.post_dir(t_repo_id1, '/', dir_name, USER) == 0 + assert api.post_file(t_repo_id1, file_path, '/', file_name, USER, USERNAME) == 0 + assert api.post_dir(t_repo_id1, '/', dir_name, USER, USERNAME) == 0 #test search files file_list = api.search_files (t_repo_id1, "test") diff --git a/tests/test_file_operation/test_upload_and_update.py b/tests/test_file_operation/test_upload_and_update.py index 0727ede6..3976c72e 100644 --- a/tests/test_file_operation/test_upload_and_update.py +++ b/tests/test_file_operation/test_upload_and_update.py @@ -2,7 +2,7 @@ import requests import os import time -from tests.config import USER +from tests.config import USER, USERNAME from seaserv import seafile_api as api from requests_toolbelt import MultipartEncoder @@ -36,7 +36,7 @@ def create_test_file(): def create_test_dir(repo, dir_name): parent_dir = '/' - api.post_dir(repo.id,parent_dir,dir_name,USER) + api.post_dir(repo.id,parent_dir,dir_name,USER, USERNAME) def assert_upload_response(response, replace, file_exist): assert response.status_code == 200 @@ -98,10 +98,10 @@ def write_file(file_path, file_content): fp.close() def del_repo_files(repo_id): - api.del_file(repo_id, '/', '[\"'+file_name+'\"]', USER) - api.del_file(repo_id, '/', '[\"'+file_name_not_replaced+'\"]', USER) - api.del_file(repo_id, '/', '[\"subdir\"]', USER) - api.del_file(repo_id, '/', '[\"'+resumable_file_name+'\"]', USER) + api.del_file(repo_id, '/', '[\"'+file_name+'\"]', USER, USERNAME) + api.del_file(repo_id, '/', '[\"'+file_name_not_replaced+'\"]', USER, USERNAME) + api.del_file(repo_id, '/', '[\"subdir\"]', USER, USERNAME) + api.del_file(repo_id, '/', '[\"'+resumable_file_name+'\"]', USER, USERNAME) def del_local_files(): os.remove(file_path) @@ -114,7 +114,7 @@ def test_ajax(repo): obj_id = '{"parent_dir":"/"}' #test upload file to test dir. - token = api.get_fileserver_access_token(repo.id, obj_id, 'upload', USER, False) + token = api.get_fileserver_access_token(repo.id, obj_id, 'upload', USER, USERNAME, False) upload_url_base = 'http://127.0.0.1:8082/upload-aj/'+ token m = MultipartEncoder( fields={ @@ -126,7 +126,7 @@ def test_ajax(repo): assert response.status_code == 403 #test upload file to root dir. - token = api.get_fileserver_access_token(repo.id, obj_id, 'upload', USER, False) + token = api.get_fileserver_access_token(repo.id, obj_id, 'upload', USER, USERNAME, False) upload_url_base = 'http://127.0.0.1:8082/upload-aj/'+ token m = MultipartEncoder( fields={ @@ -258,7 +258,7 @@ def test_ajax(repo): #test update file. write_file(file_path, file_content) - token = api.get_fileserver_access_token(repo.id, obj_id, 'update', USER, False) + token = api.get_fileserver_access_token(repo.id, obj_id, 'update', USER, USERNAME, False) update_url_base = 'http://127.0.0.1:8082/update-aj/' + token m = MultipartEncoder( fields={ @@ -283,7 +283,7 @@ def test_api(repo): obj_id = '{"parent_dir":"/"}' create_test_dir(repo,'test') #test upload file to test dir instead of root dir. - token = api.get_fileserver_access_token(repo.id, obj_id, 'upload', USER, False) + token = api.get_fileserver_access_token(repo.id, obj_id, 'upload', USER, USERNAME, False) upload_url_base = 'http://127.0.0.1:8082/upload-api/' + token m = MultipartEncoder( fields={ @@ -296,7 +296,7 @@ def test_api(repo): #test upload file to root dir. params = {'ret-json':'1'} - token = api.get_fileserver_access_token(repo.id, obj_id, 'upload', USER, False) + token = api.get_fileserver_access_token(repo.id, obj_id, 'upload', USER, USERNAME, False) upload_url_base = 'http://127.0.0.1:8082/upload-api/' + token m = MultipartEncoder( fields={ @@ -497,7 +497,7 @@ def test_api(repo): #test update file. write_file(file_path, file_content) - token = api.get_fileserver_access_token(repo.id, obj_id, 'update', USER, False) + token = api.get_fileserver_access_token(repo.id, obj_id, 'update', USER, USERNAME, False) update_url_base = 'http://127.0.0.1:8082/update-api/' + token m = MultipartEncoder( fields={ diff --git a/tests/test_file_operation/test_upload_large_files.py b/tests/test_file_operation/test_upload_large_files.py index 8f4b2f45..c3657221 100644 --- a/tests/test_file_operation/test_upload_large_files.py +++ b/tests/test_file_operation/test_upload_large_files.py @@ -2,7 +2,7 @@ import requests import os import hashlib -from tests.config import USER +from tests.config import USER, USERNAME from seaserv import seafile_api as api from requests_toolbelt import MultipartEncoder @@ -43,7 +43,7 @@ def create_test_file(): def create_test_dir(repo, dir_name): parent_dir = '/' - api.post_dir(repo.id,parent_dir,dir_name,USER) + api.post_dir(repo.id,parent_dir,dir_name,USER, USERNAME) def assert_upload_response(response): assert response.status_code == 200 @@ -87,10 +87,10 @@ def write_file(file_path, file_content): fp.close() def del_repo_files(repo_id): - api.del_file(repo_id, '/', '[\"'+file_name+'\"]', USER) - api.del_file(repo_id, '/', '[\"'+file_name_not_replaced+'\"]', USER) - api.del_file(repo_id, '/', '[\"subdir\"]', USER) - api.del_file(repo_id, '/', '[\"'+resumable_file_name+'\"]', USER) + api.del_file(repo_id, '/', '[\"'+file_name+'\"]', USER, USERNAME) + api.del_file(repo_id, '/', '[\"'+file_name_not_replaced+'\"]', USER, USERNAME) + api.del_file(repo_id, '/', '[\"subdir\"]', USER, USERNAME) + api.del_file(repo_id, '/', '[\"'+resumable_file_name+'\"]', USER, USERNAME) def del_local_files(): os.remove(file_path) @@ -119,7 +119,7 @@ def test_large_files_ajax(repo): # upload large file by upload-aj file_id1 = sha1sum(file_path) - token = api.get_fileserver_access_token(repo.id, obj_id, 'upload', USER, False) + token = api.get_fileserver_access_token(repo.id, obj_id, 'upload', USER, USERNAME, False) upload_url_base = 'http://127.0.0.1:8082/upload-aj/'+ token m = MultipartEncoder( fields={ @@ -133,7 +133,7 @@ def test_large_files_ajax(repo): # download file and check sha1 obj_id = api.get_file_id_by_path(repo.id, '/' + file_name) assert obj_id != None - token = api.get_fileserver_access_token (repo.id, obj_id, 'download', USER, False) + token = api.get_fileserver_access_token (repo.id, obj_id, 'download', USER, USERNAME, False) download_url = 'http://127.0.0.1:8082/files/' + token + '/' + file_name response = requests.get(download_url) assert response.status_code == 200 @@ -163,7 +163,7 @@ def test_large_files_ajax(repo): # download file and check sha1 obj_id = api.get_file_id_by_path(repo.id, '/' + resumable_file_name) assert obj_id != None - token = api.get_fileserver_access_token (repo.id, obj_id, 'download', USER, False) + token = api.get_fileserver_access_token (repo.id, obj_id, 'download', USER, USERNAME, False) download_url = 'http://127.0.0.1:8082/files/' + token + '/' + resumable_file_name response = requests.get(download_url) assert response.status_code == 200 @@ -184,7 +184,7 @@ def test_large_files_api(repo): #test upload file to root dir. file_id1 = sha1sum(file_path) params = {'ret-json':'1'} - token = api.get_fileserver_access_token(repo.id, obj_id, 'upload', USER, False) + token = api.get_fileserver_access_token(repo.id, obj_id, 'upload', USER, USERNAME, False) upload_url_base = 'http://127.0.0.1:8082/upload-api/' + token m = MultipartEncoder( fields={ @@ -198,7 +198,7 @@ def test_large_files_api(repo): # download file and check sha1 obj_id = api.get_file_id_by_path(repo.id, '/' + file_name) assert obj_id != None - token = api.get_fileserver_access_token (repo.id, obj_id, 'download', USER, False) + token = api.get_fileserver_access_token (repo.id, obj_id, 'download', USER, USERNAME, False) download_url = 'http://127.0.0.1:8082/files/' + token + '/' + file_name response = requests.get(download_url) assert response.status_code == 200 @@ -228,7 +228,7 @@ def test_large_files_api(repo): obj_id = api.get_file_id_by_path(repo.id, '/' + resumable_file_name) assert obj_id != None - token = api.get_fileserver_access_token (repo.id, obj_id, 'download', USER, False) + token = api.get_fileserver_access_token (repo.id, obj_id, 'download', USER, USERNAME, False) download_url = 'http://127.0.0.1:8082/files/' + token + '/' + resumable_file_name response = requests.get(download_url) assert response.status_code == 200 diff --git a/tests/test_file_operation/test_zip_download.py b/tests/test_file_operation/test_zip_download.py index 3082379a..93e7d67b 100644 --- a/tests/test_file_operation/test_zip_download.py +++ b/tests/test_file_operation/test_zip_download.py @@ -4,7 +4,7 @@ import time import zipfile import json -from tests.config import USER +from tests.config import USER, USERNAME from seaserv import seafile_api as api file1_name = 'file1.txt' @@ -34,15 +34,15 @@ def test_zip_download(): #test zip download dir dir_name = 'dir' - api.post_dir(t_repo_id, '/', dir_name, USER) - api.post_file(t_repo_id, file1_path, '/dir', file1_name, USER) - api.post_file(t_repo_id, file2_path, '/dir', file2_name, USER) + api.post_dir(t_repo_id, '/', dir_name, USER, USERNAME) + api.post_file(t_repo_id, file1_path, '/dir', file1_name, USER, USERNAME) + api.post_file(t_repo_id, file2_path, '/dir', file2_name, USER, USERNAME) dir_id = api.get_dir_id_by_path(t_repo_id, '/dir') obj_id = {'obj_id': dir_id, 'dir_name': dir_name, 'is_windows': 0} obj_id_json_str = json.dumps(obj_id) token = api.get_fileserver_access_token(t_repo_id, obj_id_json_str, - 'download-dir', USER) + 'download-dir', USER, USERNAME) time.sleep(1) download_url = base_url + 'zip/' + token @@ -74,13 +74,13 @@ def test_zip_download(): #test zip download empty dir empty_dir_name = 'empty_dir' - api.post_dir(t_repo_id, '/', empty_dir_name, USER) + api.post_dir(t_repo_id, '/', empty_dir_name, USER, USERNAME) dir_id = api.get_dir_id_by_path(t_repo_id, '/empty_dir') obj_id = {'obj_id': dir_id, 'dir_name': empty_dir_name, 'is_windows': 0} obj_id_json_str = json.dumps(obj_id) token = api.get_fileserver_access_token(t_repo_id, obj_id_json_str, - 'download-dir', USER) + 'download-dir', USER, USERNAME) time.sleep(1) download_url = base_url + 'zip/' + token response = requests.get(download_url) @@ -100,12 +100,12 @@ def test_zip_download(): os.remove(download_dir_path + '/empty_dir.zip') #test zip download mutliple files - api.post_file(t_repo_id, file1_path, '/', file1_name, USER) - api.post_file(t_repo_id, file2_path, '/', file2_name, USER) + api.post_file(t_repo_id, file1_path, '/', file1_name, USER, USERNAME) + api.post_file(t_repo_id, file2_path, '/', file2_name, USER, USERNAME) obj_id = {'parent_dir': '/', 'file_list': [file1_name, file2_name], 'is_windows' : 0} obj_id_json_str = json.dumps(obj_id) token = api.get_fileserver_access_token(t_repo_id, obj_id_json_str, - 'download-multi', USER) + 'download-multi', USER, USERNAME) time.sleep(1) download_url = base_url + 'zip/' + token diff --git a/tests/test_file_property_and_dir_listing/test_file_property_and_dir_listing.py b/tests/test_file_property_and_dir_listing/test_file_property_and_dir_listing.py index c68a72e4..8dd5a703 100644 --- a/tests/test_file_property_and_dir_listing/test_file_property_and_dir_listing.py +++ b/tests/test_file_property_and_dir_listing/test_file_property_and_dir_listing.py @@ -1,7 +1,7 @@ import pytest import os import time -from tests.config import USER +from tests.config import USER, USERNAME from seaserv import seafile_api as api file_name = 'test.txt' @@ -21,9 +21,9 @@ def test_file_property_and_dir_listing (): create_the_file() - api.post_file(t_repo_id, file_path, '/', file_name, USER) - api.post_dir(t_repo_id, '/', dir_name, USER) - api.post_file(t_repo_id, file_path, '/' + dir_name, file_name, USER) + api.post_file(t_repo_id, file_path, '/', file_name, USER, USERNAME) + api.post_dir(t_repo_id, '/', dir_name, USER, USERNAME) + api.post_file(t_repo_id, file_path, '/' + dir_name, file_name, USER, USERNAME) #test is_valid_filename t_valid_file_name = 'valid_filename' @@ -73,7 +73,7 @@ def test_file_property_and_dir_listing (): assert t_dirent_obj.mode == std_file_mode assert t_dirent_obj.version == t_repo_version assert t_dirent_obj.size == t_file_size - assert t_dirent_obj.modifier == USER + assert t_dirent_obj.modifier == USERNAME #test list_file_by_file_id t_block_list = api.list_file_by_file_id(t_repo_id, t_file_id) @@ -104,7 +104,7 @@ def test_file_property_and_dir_listing (): assert len(t_dir_list) == 1 #test mkdir_with_parent - api.mkdir_with_parents (t_repo_id, '/test_dir', 'test_subdir', USER) + api.mkdir_with_parents (t_repo_id, '/test_dir', 'test_subdir', USER, USERNAME) t_dir_id = api.get_dir_id_by_path(t_repo_id, '/test_dir/test_subdir') assert t_dir_id diff --git a/tests/test_repo_manipulation/test_repo_manipulation.py b/tests/test_repo_manipulation/test_repo_manipulation.py index 0ecdced2..dbe81e65 100644 --- a/tests/test_repo_manipulation/test_repo_manipulation.py +++ b/tests/test_repo_manipulation/test_repo_manipulation.py @@ -1,5 +1,5 @@ import pytest -from tests.config import USER, USER2 +from tests.config import USER, USER2, USERNAME from seaserv import seafile_api as api def get_repo_list_order_by(t_start, t_limit, order_by): @@ -39,10 +39,10 @@ def test_repo_manipulation(): #test revert_repo and get_commit t_commit_id_before_changing = t_repo.head_cmmt_id - api.post_dir(t_repo_id, '/', 'dir1', USER) + api.post_dir(t_repo_id, '/', 'dir1', USER, USERNAME) t_repo = api.get_repo(t_repo_id) - api.revert_repo(t_repo_id, t_commit_id_before_changing, USER) + api.revert_repo(t_repo_id, t_commit_id_before_changing, USER, USERNAME) t_repo = api.get_repo(t_repo_id) t_commit_id_after_revert = t_repo.head_cmmt_id diff --git a/tests/test_share_and_perm/test_shared_repo_perm.py b/tests/test_share_and_perm/test_shared_repo_perm.py index d8a2465a..7485209d 100644 --- a/tests/test_share_and_perm/test_shared_repo_perm.py +++ b/tests/test_share_and_perm/test_shared_repo_perm.py @@ -3,7 +3,7 @@ from seaserv import seafile_api as api from seaserv import ccnet_api -from tests.config import ADMIN_USER, USER, USER2 +from tests.config import ADMIN_USER, USER, USER2, USERNAME from tests.utils import assert_repo_with_permission @@ -112,7 +112,7 @@ def test_share_dir_to_user(repo, permission): users = api.get_shared_users_for_subdir(repo.id, '/dir1', USER) assert len(users) == 1 and users[0].user == USER2 - assert api.del_file(repo.id, '/', '[\"dir1\"]', USER) == 0 + assert api.del_file(repo.id, '/', '[\"dir1\"]', USER, USERNAME) == 0 assert api.unshare_subdir_for_user(repo.id, '/dir2', USER, USER2) == 0 time.sleep(2) @@ -135,7 +135,7 @@ def test_share_dir_to_group(repo, group, permission): users = api.get_shared_groups_for_subdir(repo.id, '/dir1', USER) assert len(users) == 1 - assert api.del_file(repo.id, '/', '[\"dir1\"]', USER) == 0 + assert api.del_file(repo.id, '/', '[\"dir1\"]', USER, USERNAME) == 0 assert api.unshare_subdir_for_group(repo.id, '/dir2', USER, group.id) == 0 time.sleep(2) @@ -205,8 +205,8 @@ def test_get_shared_users_by_repo(repo, group, permission): @pytest.mark.parametrize('permission', ['r', 'rw']) def test_subdir_permission_in_virtual_repo(repo, group, permission): - api.post_dir(repo.id, '/dir1', 'subdir1', USER) - api.post_dir(repo.id, '/dir2', 'subdir2', USER) + api.post_dir(repo.id, '/dir1', 'subdir1', USER, USERNAME) + api.post_dir(repo.id, '/dir2', 'subdir2', USER, USERNAME) v_repo_id_1 = api.share_subdir_to_user(repo.id, '/dir1', USER, USER2, permission) v_subdir_repo_id_1 = api.create_virtual_repo(v_repo_id_1, '/subdir1', 'subdir1', 'test_desc', USER, passwd='')