@@ -58,13 +58,13 @@ func (commitCtl CommitController) GetEntriesInRef(ctx context.Context, w *api.Ji
5858 return
5959 }
6060
61- commit , err := commitCtl .Repo .CommitRepo ().Commit (ctx , ref .CommitHash )
61+ commit , err := commitCtl .Repo .CommitRepo (repository . ID ).Commit (ctx , ref .CommitHash )
6262 if err != nil {
6363 w .Error (err )
6464 return
6565 }
6666
67- workTree , err := versionmgr .NewWorkTree (ctx , commitCtl .Repo .FileTreeRepo (), models .NewRootTreeEntry (commit .TreeHash ))
67+ workTree , err := versionmgr .NewWorkTree (ctx , commitCtl .Repo .FileTreeRepo (repository . ID ), models .NewRootTreeEntry (commit .TreeHash ))
6868 if err != nil {
6969 w .Error (err )
7070 return
@@ -82,14 +82,26 @@ func (commitCtl CommitController) GetEntriesInRef(ctx context.Context, w *api.Ji
8282 w .JSON (treeEntry )
8383}
8484
85- func (commitCtl CommitController ) GetCommitDiff (ctx context.Context , w * api.JiaozifsResponse , _ * http.Request , ownerName string , _ string , basehead string , params api.GetCommitDiffParams ) {
85+ func (commitCtl CommitController ) GetCommitDiff (ctx context.Context , w * api.JiaozifsResponse , _ * http.Request , ownerName string , repositoryName string , basehead string , params api.GetCommitDiffParams ) {
8686 operator , err := auth .GetOperator (ctx )
8787 if err != nil {
8888 w .Error (err )
8989 return
9090 }
9191
92- if operator .Name == ownerName { //todo check permission
92+ owner , err := commitCtl .Repo .UserRepo ().Get (ctx , models .NewGetUserParams ().SetName (ownerName ))
93+ if err != nil {
94+ w .Error (err )
95+ return
96+ }
97+
98+ repository , err := commitCtl .Repo .RepositoryRepo ().Get (ctx , models .NewGetRepoParams ().SetName (repositoryName ).SetOwnerID (owner .ID ))
99+ if err != nil {
100+ w .Error (err )
101+ return
102+ }
103+
104+ if operator .ID == owner .ID { //todo check permission
93105 w .Forbidden ()
94106 return
95107 }
@@ -111,7 +123,7 @@ func (commitCtl CommitController) GetCommitDiff(ctx context.Context, w *api.Jiao
111123 return
112124 }
113125
114- bashCommit , err := commitCtl .Repo .CommitRepo ().Commit (ctx , bashCommitHash )
126+ bashCommit , err := commitCtl .Repo .CommitRepo (repository . ID ).Commit (ctx , bashCommitHash )
115127 if err != nil {
116128 w .Error (err )
117129 return
@@ -122,7 +134,7 @@ func (commitCtl CommitController) GetCommitDiff(ctx context.Context, w *api.Jiao
122134 path = * params .Path
123135 }
124136
125- commitOp := versionmgr .NewCommitOp (commitCtl .Repo , bashCommit )
137+ commitOp := versionmgr .NewCommitOp (commitCtl .Repo , repository . ID , bashCommit )
126138 changes , err := commitOp .DiffCommit (ctx , toCommitHash )
127139 if err != nil {
128140 w .Error (err )
0 commit comments