summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorMorgan Bazalgette <git@howl.moe>2017-02-11 11:57:57 +0100
committerLunny Xiao <xiaolunwen@gmail.com>2017-02-11 18:57:57 +0800
commit442145dbd348a18915de80faea68f30a9d9309b3 (patch)
tree4d1306edbfa72064ec006b73afd6d2150e507da6 /models
parenta36a8f4d72bd8d5161f29c2df177ae5a73fe882c (diff)
downloadgitea-442145dbd348a18915de80faea68f30a9d9309b3.tar.gz
gitea-442145dbd348a18915de80faea68f30a9d9309b3.zip
Fix public activity showing private repos (#892)
* Fix public activity showing private repos (#811) Signed-off-by: Morgan Bazalgette <the@howl.moe> * error check after setting is_private to true * Add test for UpdateRepository w/ visibility change
Diffstat (limited to 'models')
-rw-r--r--models/fixtures/action.yml11
-rw-r--r--models/fixtures/repository.yml12
-rw-r--r--models/fixtures/user.yml15
-rw-r--r--models/repo.go10
-rw-r--r--models/repo_test.go19
5 files changed, 67 insertions, 0 deletions
diff --git a/models/fixtures/action.yml b/models/fixtures/action.yml
index f4f10dde2b..bf44837a1c 100644
--- a/models/fixtures/action.yml
+++ b/models/fixtures/action.yml
@@ -20,3 +20,14 @@
repo_name: repo3 # TODO old or new name?
is_private: false
content: oldRepoName
+
+-
+ id: 3
+ user_id: 11
+ op_type: 1 # create repo
+ act_user_id: 11
+ act_user_name: user11
+ repo_id: 9
+ repo_user_name: user11
+ repo_name: repo9
+ is_private: false
diff --git a/models/fixtures/repository.yml b/models/fixtures/repository.yml
index 93463c0855..d50b88c301 100644
--- a/models/fixtures/repository.yml
+++ b/models/fixtures/repository.yml
@@ -93,3 +93,15 @@
num_pulls: 0
num_closed_pulls: 0
is_mirror: false
+
+-
+ id: 9
+ owner_id: 11
+ lower_name: repo9
+ name: repo9
+ is_private: false
+ num_issues: 0
+ num_closed_issues: 0
+ num_pulls: 0
+ num_closed_pulls: 0
+ is_mirror: false
diff --git a/models/fixtures/user.yml b/models/fixtures/user.yml
index 568f367290..337fb54590 100644
--- a/models/fixtures/user.yml
+++ b/models/fixtures/user.yml
@@ -149,3 +149,18 @@
avatar_email: user10@example.com
num_repos: 3
is_active: true
+
+-
+ id: 11
+ lower_name: user11
+ name: user11
+ full_name: User Eleven
+ email: user11@example.com
+ passwd: password
+ type: 0 # individual
+ salt: salt
+ is_admin: false
+ avatar: avatar11
+ avatar_email: user11@example.com
+ num_repos: 1
+ is_active: true
diff --git a/models/repo.go b/models/repo.go
index a7a36cc7d0..86961d68d7 100644
--- a/models/repo.go
+++ b/models/repo.go
@@ -1408,6 +1408,16 @@ func updateRepository(e Engine, repo *Repository, visibilityChanged bool) (err e
}
}
+ // If repo has become private, we need to set its actions to private.
+ if repo.IsPrivate {
+ _, err = e.Where("repo_id = ?", repo.ID).Cols("is_private").Update(&Action{
+ IsPrivate: true,
+ })
+ if err != nil {
+ return err
+ }
+ }
+
// Create/Remove git-daemon-export-ok for git-daemon...
daemonExportFile := path.Join(repo.RepoPath(), `git-daemon-export-ok`)
if repo.IsPrivate && com.IsExist(daemonExportFile) {
diff --git a/models/repo_test.go b/models/repo_test.go
index db8bd1024e..18da682059 100644
--- a/models/repo_test.go
+++ b/models/repo_test.go
@@ -73,3 +73,22 @@ func TestGetPrivateRepositoryCount(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, int64(2), count)
}
+
+func TestUpdateRepositoryVisibilityChanged(t *testing.T) {
+ assert.NoError(t, PrepareTestDatabase())
+
+ // Get sample repo and change visibility
+ repo, err := GetRepositoryByID(9)
+ repo.IsPrivate = true
+
+ // Update it
+ err = UpdateRepository(repo, true)
+ assert.NoError(t, err)
+
+ // Check visibility of action has become private
+ act := Action{}
+ _, err = x.ID(3).Get(&act)
+
+ assert.NoError(t, err)
+ assert.Equal(t, true, act.IsPrivate)
+}