diff --git a/src/main/java/org/breedinginsight/api/auth/ProgramSecuredRole.java b/src/main/java/org/breedinginsight/api/auth/ProgramSecuredRole.java index 4294a1f7e..b2f403ac2 100644 --- a/src/main/java/org/breedinginsight/api/auth/ProgramSecuredRole.java +++ b/src/main/java/org/breedinginsight/api/auth/ProgramSecuredRole.java @@ -20,7 +20,8 @@ public enum ProgramSecuredRole { MEMBER("member"), BREEDER("breeder"), - SYSTEM_ADMIN("admin"); + SYSTEM_ADMIN("admin"), + EXPERIMENTAL_COLLABORATOR("Experimental Collaborator"); private String domain; diff --git a/src/main/java/org/breedinginsight/daos/ExperimentalCollaboratorDAO.java b/src/main/java/org/breedinginsight/daos/ExperimentalCollaboratorDAO.java new file mode 100644 index 000000000..b3ac8bbaf --- /dev/null +++ b/src/main/java/org/breedinginsight/daos/ExperimentalCollaboratorDAO.java @@ -0,0 +1,39 @@ +/* + * See the NOTICE file distributed with this work for additional information + * regarding copyright ownership. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.breedinginsight.daos; + +import lombok.extern.slf4j.Slf4j; +import org.breedinginsight.dao.db.tables.daos.ExperimentProgramUserRoleDao; +import org.jooq.Configuration; +import org.jooq.DSLContext; + +import javax.inject.Inject; +import javax.inject.Singleton; + +@Slf4j +@Singleton +public class ExperimentalCollaboratorDAO extends ExperimentProgramUserRoleDao { + + private DSLContext dsl; + + @Inject + public ExperimentalCollaboratorDAO(Configuration config, DSLContext dsl) { + super(config); + this.dsl = dsl; + } +} diff --git a/src/main/java/org/breedinginsight/services/ExperimentalCollaboratorService.java b/src/main/java/org/breedinginsight/services/ExperimentalCollaboratorService.java new file mode 100644 index 000000000..c8aaddf07 --- /dev/null +++ b/src/main/java/org/breedinginsight/services/ExperimentalCollaboratorService.java @@ -0,0 +1,34 @@ +/* + * See the NOTICE file distributed with this work for additional information + * regarding copyright ownership. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.breedinginsight.services; + +import lombok.extern.slf4j.Slf4j; +import org.breedinginsight.daos.ExperimentalCollaboratorDAO; + +import javax.inject.Inject; + +@Slf4j +public class ExperimentalCollaboratorService { + + private final ExperimentalCollaboratorDAO experimentalCollaboratorDAO; + + @Inject + public ExperimentalCollaboratorService(ExperimentalCollaboratorDAO experimentalCollaboratorDAO) { + this.experimentalCollaboratorDAO = experimentalCollaboratorDAO; + } +} diff --git a/src/main/resources/db/migration/V1.26.0__add_experiment_program_user_role.sql b/src/main/resources/db/migration/V1.26.0__add_experiment_program_user_role.sql new file mode 100644 index 000000000..0606109b7 --- /dev/null +++ b/src/main/resources/db/migration/V1.26.0__add_experiment_program_user_role.sql @@ -0,0 +1,27 @@ +/* + * See the NOTICE file distributed with this work for additional information + * regarding copyright ownership. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +-- experiment_id is not tracked in bidb as seperate experiment entities, only in this linking table +CREATE TABLE experiment_program_user_role ( + like base_entity INCLUDING DEFAULTS INCLUDING CONSTRAINTS INCLUDING INDEXES, + experiment_id UUID NOT NULL, + program_user_role_id UUID NOT NULL, + like base_edit_track_entity INCLUDING DEFAULTS INCLUDING CONSTRAINTS INCLUDING INDEXES +); +ALTER TABLE experiment_program_user_role ADD FOREIGN KEY (created_by) REFERENCES bi_user (id); +ALTER TABLE experiment_program_user_role ADD FOREIGN KEY (updated_by) REFERENCES bi_user (id); +ALTER TABLE experiment_program_user_role ADD FOREIGN KEY (program_user_role_id) REFERENCES program_user_role (id); diff --git a/src/main/resources/db/migration/V1.26.1__add_experimental_collaborator_role.sql b/src/main/resources/db/migration/V1.26.1__add_experimental_collaborator_role.sql new file mode 100644 index 000000000..495cab4db --- /dev/null +++ b/src/main/resources/db/migration/V1.26.1__add_experimental_collaborator_role.sql @@ -0,0 +1,31 @@ +/* + * See the NOTICE file distributed with this work for additional information + * regarding copyright ownership. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +DO $$ +DECLARE + user_id UUID; +BEGIN + + user_id := (SELECT id FROM bi_user WHERE name = 'system'); + + INSERT INTO role + (domain, created_by, updated_by) + VALUES + ('Experimental Collaborator', user_id, user_id) + ; + +END $$;