FIX update repository

dev_forge
Jasder 5 years ago
parent a0bd1bd9b4
commit f59b08b31b

@ -496,10 +496,10 @@ PATCH api/projects/:id
curl -X PATCH \
-d "name=hnfl_demo" \
-d "description=my first project" \
-d "repository_name=hnfl_demo" \
-d "project_category_id=1" \
-d "project_language_id=2" \
http://localhost:3000/api/projects/3263 | jq
-d "private=true" \
http://localhost:3000/api/projects/3263.json | jq
```
*请求参数说明:*
@ -517,15 +517,25 @@ http://localhost:3000/api/projects/3263 | jq
|参数名|类型|说明|
-|-|-
|id |int |id |
|name |string|项目名称|
|id |int|id |
|identifier |string|项目标识|
|name |string|项目名称|
|description |string|项目简介|
|project_category_id|int|项目类别id|
|project_language_id|int|项目语言id|
|private |否|boolean|项目是否私有, true为私有false: 公开,默认为公开 |
返回值
```
{
"id": 3240,
"name": "好项目"
"id": 3263,
"identifier": "mirror_demo",
"name": "hnfl_demo",
"description": "my first project",
"project_category_id": 1,
"project_language_id": 2,
"is_public": true
}
```
---

@ -42,8 +42,14 @@ class ProjectsController < ApplicationController
def update
ActiveRecord::Base.transaction do
Projects::CreateForm.new(project_params).validate!
@project.update_attributes!(project_params)
# Projects::CreateForm.new(project_params).validate!
private = params[:private]
if [true, false].include? private
new_project_params = project_params.merge(is_public: !private)
Gitea::Repository::UpdateService.new(@project.owner, @project.repository.identifier, {private: private}).call
@project.repository.update_column(:hidden, private)
end
@project.update_attributes!(new_project_params)
end
rescue Exception => e
uid_logger_error(e.message)

@ -66,7 +66,7 @@ class Project < ApplicationRecord
#创建项目管理员
def check_project_members
unless members.present? && members.exists(user_id: self.user_id)
unless members.present? && members.exists?(user_id: self.user_id)
member_params = {
user_id: self.user_id,
project_id: self.id

@ -0,0 +1,7 @@
json.id @project.id
json.identifier @project.identifier
json.name @project.name
json.description @project.description
json.project_category_id @project.project_category_id
json.project_language_id @project.project_language_id
json.is_public @project.is_public
Loading…
Cancel
Save