Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finish the functionality of adding collaborators #79

Merged
merged 3 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions README-zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,16 @@ repo gitolite-admin
RW+ = gcs
repo testing
R = @all
include "gitolite.d/*.conf"
include "gitolite.d/user/*.conf"
include "gitolite.d/repository/*.conf"
@all_public_repo =
repo @all_public_repo
R = @all
```

7. 你需要保证 `/home/gcs/gitolite-admin/conf/gitolite.d` 目录存在。该目录用来管理用户对私有仓库的权限。
7. 你需要保证 `/home/gcs/gitolite-admin/conf/gitolite.d/user` 与
`home/gcs/gitolite-admin/conf/gitolite.d/repository`目录存在。第一个目录用来管理私有仓库的权限,
第二个目录用于实现合作者功能。

### 修改 `sudo` 配置
你需要保证你运行 `Java` 程序的用户能够在执行 `sudo -u <git_user> rm`
Expand Down
4 changes: 4 additions & 0 deletions database/constraint/all_column_constraint.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ ADD CONSTRAINT pk_user_star_repository PRIMARY KEY (id);
-- The constraint of the primary key and unique key is added to the table.
ALTER TABLE ONLY public.t_ssh_key
ADD CONSTRAINT pk_ssh_key PRIMARY KEY (id);

-- The constraint of t_user_collaborate_repository is added to the table.
ALTER TABLE ONLY public.t_user_collaborate_repository
ADD CONSTRAINT pk_user_collaborate_repository PRIMARY KEY (id);
18 changes: 18 additions & 0 deletions database/table/t_user_collaborate_repository.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
CREATE TABLE public.t_user_collaborate_repository (
id bigint NOT NULL,
collaborator_id bigint NOT NULL,
repository_id bigint NOT NULL,
gmt_created timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
gmt_updated timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
gmt_deleted timestamp without time zone
);

COMMENT ON TABLE public.t_user_collaborate_repository IS 'Table for collaboration relationship.';

COMMENT ON COLUMN public.t_user_collaborate_repository.id IS 'Primary key of the collaboration relationship table.';
COMMENT ON COLUMN public.t_user_collaborate_repository.collaborator_id IS 'ID of the collaborator.';
COMMENT ON COLUMN public.t_user_collaborate_repository.repository_id IS 'ID of the repository.';
COMMENT ON COLUMN public.t_user_collaborate_repository.gmt_created IS 'Timestamp when the relationship was created.';
COMMENT ON COLUMN public.t_user_collaborate_repository.gmt_updated IS 'Timestamp when the relationship was last updated.';
COMMENT ON COLUMN public.t_user_collaborate_repository.gmt_deleted IS 'Timestamp when the relationship was deleted.
If set to NULL, it indicates that the repository has not been deleted.';
5 changes: 5 additions & 0 deletions database/trigger/all_table_trigger.sql
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,8 @@ FOR EACH ROW EXECUTE FUNCTION public.update_gmt_updated_column();
CREATE TRIGGER update_t_ssh_key_gmt_updated
BEFORE UPDATE ON public.t_ssh_key
FOR EACH ROW EXECUTE FUNCTION public.update_gmt_updated_column();

-- The trigger of the t_user_collaborate_repository table is added.
CREATE TRIGGER update_t_user_collaborate_repository_gmt_updated
BEFORE UPDATE ON public.t_user_collaborate_repository
FOR EACH ROW EXECUTE FUNCTION public.update_gmt_updated_column();
6 changes: 4 additions & 2 deletions prepare_dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ sudo su -c "/home/git/bin/gitolite setup -pk /home/git/$USER.pub" git
rm -rf /home/"$USER"/gitolite-admin
GIT_SSH_COMMAND='ssh -o StrictHostKeyChecking=no' git clone \
ssh://git@localhost:22/gitolite-admin /home/"$USER"/gitolite-admin
mkdir -p /home/"$USER"/gitolite-admin/conf/gitolite.d
mkdir -p /home/"$USER"/gitolite-admin/conf/gitolite.d/user
mkdir -p /home/"$USER"/gitolite-admin/conf/gitolite.d/repository
echo "
repo gitolite-admin
RW+ = $USER
repo testing
R = @all
include \"gitolite.d/*.conf\"
include \"gitolite.d/user/*.conf\"
include \"gitolite.d/repository/*.conf\"
@all_public_repo =
repo @all_public_repo
R = @all" > /home/"$USER"/gitolite-admin/conf/gitolite.conf
Expand Down
9 changes: 7 additions & 2 deletions script/deploy_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,16 +406,21 @@ def init_gitolite(config):
f"{config.serviceUserHomeDirectory}/gitolite-admin\" {config.serviceUser}")
log_debug(f"Clone gitolite-admin command: {command}")
command_checker(os.system(command), f"Failed to clone gitolite-admin")
command = (f"su -c 'mkdir -p {config.serviceUserHomeDirectory}/gitolite-admin/conf/gitolite.d' "
command = (f"su -c 'mkdir -p {config.serviceUserHomeDirectory}/gitolite-admin/conf/gitolite.d/user' "
f"{config.serviceUser}")
log_debug(f"Create usr directory command: {command}")
command_checker(os.system(command), f"Failed to create usr directory in gitolite-admin/conf")
command = (f"su -c 'mkdir -p {config.serviceUserHomeDirectory}/gitolite-admin/conf/gitolite.d/repository' "
f"{config.serviceUser}")
log_debug(f"Create repository directory command: {command}")
command_checker(os.system(command), f"Failed to create repository directory in gitolite-admin/conf")
content = f'''
repo gitolite-admin
RW+ = {config.serviceUser}
repo testing
R = @all
include "gitolite.d/*.conf"
include "gitolite.d/user/*.conf"
include "gitolite.d/repository/*.conf"
@all_public_repo =
repo @all_public_repo
R = @all
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/edu/cmipt/gcs/constant/ApiPathConstant.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@ public class ApiPathConstant {
REPOSITORY_API_PREFIX + "/update";
public static final String REPOSITORY_CHECK_REPOSITORY_NAME_VALIDITY_API_PATH =
REPOSITORY_API_PREFIX + "/repository-name";
public static final String REPOSITORY_PAGE_COLLABORATOR_API_PATH =
REPOSITORY_API_PREFIX + "/page/collaborator";
public static final String REPOSITORY_ADD_COLLABORATOR_API_PREFIX =
REPOSITORY_API_PREFIX + "/add-collaborator";
public static final String REPOSITORY_ADD_COLLABORATOR_BY_NAME_API_PATH =
REPOSITORY_ADD_COLLABORATOR_API_PREFIX + "/name";
public static final String REPOSITORY_ADD_COLLABORATOR_BY_EMAIL_API_PATH =
REPOSITORY_ADD_COLLABORATOR_API_PREFIX + "/email";
public static final String REPOSITORY_ADD_COLLABORATOR_BY_ID_API_PATH =
REPOSITORY_ADD_COLLABORATOR_API_PREFIX + "/id";
public static final String REPOSITORY_REMOVE_COLLABORATION_API_PATH =
REPOSITORY_API_PREFIX + "/remove-collaborator";

public static final String SSH_KEY_API_PREFIX = ALL_API_PREFIX + "/ssh";
public static final String SSH_KEY_UPLOAD_SSH_KEY_API_PATH = SSH_KEY_API_PREFIX + "/upload";
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/edu/cmipt/gcs/constant/GitConstant.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public class GitConstant {

public static String GITOLITE_USER_CONF_DIR_PATH;

public static String GITOLITE_REPOSITORY_CONF_DIR_PATH;

public static String GITOLITE_KEY_DIR_PATH;

@Value("${git.user.name}")
Expand Down Expand Up @@ -53,7 +55,9 @@ public void setGITOLITE_ADMIN_REPOSITORY_PATH(String gitoliteAdminRepositoryPath
GitConstant.GITOLITE_CONF_FILE_PATH =
Paths.get(GITOLITE_CONF_DIR_PATH, "gitolite.conf").toString();
GitConstant.GITOLITE_USER_CONF_DIR_PATH =
Paths.get(GITOLITE_CONF_DIR_PATH, "gitolite.d").toString();
Paths.get(GITOLITE_CONF_DIR_PATH, "gitolite.d", "user").toString();
GitConstant.GITOLITE_REPOSITORY_CONF_DIR_PATH =
Paths.get(GITOLITE_CONF_DIR_PATH, "gitolite.d", "repository").toString();
GitConstant.GITOLITE_KEY_DIR_PATH =
Paths.get(gitoliteAdminRepositoryPath, "keydir").toString();
}
Expand Down
Loading
Loading