Skip to content

Commit fd81ec3

Browse files
authored
Merge pull request #131 from rwth-acis/develop
Release v0.9.3
2 parents 5260a0d + 6f7dd51 commit fd81ec3

File tree

10 files changed

+376
-28
lines changed

10 files changed

+376
-28
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ log/
1616
etc/ivy/ivy.jar
1717
/service
1818
/etc/startup
19+
/etc/launcher-configuration.ini
1920
*.iml
2021
/.idea
2122
restMapping.xml
@@ -30,6 +31,7 @@ restMapping.xml
3031
.metadata
3132
.idea/workspace.xml
3233
/bin/start_network.sh
34+
/bin/start_network-debug.sh
3335
/bin/start_network.bat
3436

3537

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,18 @@ the [GitHub Release Page](https://github.com/rwth-acis/RequirementsBazaar/releas
1010

1111
## [Unreleased]
1212

13+
## [0.9.3] - 2021-12-21
14+
15+
### Added
16+
17+
- Build generates a script to start the las2peer node in debug mode for easier debugging [a0ae55f](https://github.com/rwth-acis/RequirementsBazaar/commit/a0ae55f6e08c57a93ed2cf4533a47151e2a24ef4)
18+
19+
### Changed
20+
21+
- Fixed bug in project member API which allowed adding the same users multiple times to the same project.
22+
Also, fixed PUT request to update the role of members if they already exists
23+
[#130](https://github.com/rwth-acis/RequirementsBazaar/pull/130)
24+
1325
## [0.9.2] - 2021-11-16
1426

1527
### Changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
org.gradle.parallel=true
22
java.version=14
33
core.version=1.1.2
4-
service.version=0.9.2
4+
service.version=0.9.3
55
service.name=de.rwth.dbis.acis.bazaar.service
66
service.class=BazaarService
77
jooq.version=3.14.4

reqbaz/build.gradle

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,13 @@ task startscripts {
127127
# it starts a las2peer node providing the service '${project.property('service.name')}.${project.property('service.class')}' of this project
128128
# pls execute it from the root folder of your deployment, e. g. ./bin/start_network.sh
129129
java -cp "lib/*" i5.las2peer.tools.L2pNodeLauncher --port 9011 --service-directory service uploadStartupDirectory startService\\(\\'${project.property('service.name')}.${project.property('service.class')}@${project.property('service.version')}\\'\\) startWebConnector interactive
130+
"""
131+
new File("$rootDir/bin", "start_network-debug.sh").text = """#!/bin/bash
132+
# this script is autogenerated by 'gradle startscripts'
133+
# it starts a las2peer node providing the service '${project.property('service.name')}.${project.property('service.class')}' of this project
134+
# the JVM will be available for debugger connections (e.g., from your favorite IDE)
135+
# pls execute it from the root folder of your deployment, e. g. ./bin/start_network-debug.sh
136+
java -cp "lib/*" -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5433 i5.las2peer.tools.L2pNodeLauncher --port 9011 --service-directory service uploadStartupDirectory startService\\(\\'${project.property('service.name')}.${project.property('service.class')}@${project.property('service.version')}\\'\\) startWebConnector interactive
130137
"""
131138
new File("$rootDir/bin", "start_network.bat").text = """:: this script is autogenerated by 'gradle startscripts'
132139
:: it starts a las2peer node providing the service '${project.property('service.name')}.${project.property('service.class')}' of this project

reqbaz/src/main/java/de/rwth/dbis/acis/bazaar/service/dal/DALFacade.java

Lines changed: 57 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,19 @@ public interface DALFacade {
211211

212212
Statistic getStatisticsForProject(int userId, int projectId, Calendar since) throws BazaarException;
213213

214+
/**
215+
* Returns the count most recent active projects followed by the user
216+
*
217+
* @param userId id of the follower
218+
* @param count how many should be returned
219+
* @return Followed projects ordered by last activity
220+
*/
221+
List<Project> getFollowedProjects(int userId, int count) throws BazaarException;
222+
223+
//endregion
224+
225+
//region ProjectMember
226+
214227
/**
215228
* Get the members of a project and their according role
216229
*
@@ -220,22 +233,33 @@ public interface DALFacade {
220233
PaginationResult<ProjectMember> getProjectMembers(int projectId, Pageable pageable) throws BazaarException;
221234

222235
/**
223-
* Allows to remove a role from a user
236+
* Returns whether a certain user is member of a project (with any role).
224237
*
238+
* @param projectId
225239
* @param userId
226-
* @param context
240+
* @return
241+
*/
242+
boolean isUserProjectMember(int projectId, int userId) throws BazaarException;
243+
244+
/**
245+
* Updates a users role in a project and ensures a user has only one role assigned in
246+
* a certain project.
247+
*
248+
* @param projectId
249+
* @param userId
250+
* @param roleName
227251
* @throws BazaarException
228252
*/
229-
void removeUserFromProject(int userId, Integer context) throws BazaarException;
253+
void updateProjectMemberRole(int projectId, int userId, String roleName) throws BazaarException;
230254

231255
/**
232-
* Returns the count most recent active projects followed by the user
256+
* Removes the given user from the project.
233257
*
234-
* @param userId id of the follower
235-
* @param count how many should be returned
236-
* @return Followed projects ordered by last activity
258+
* @param userId
259+
* @param projectId
260+
* @throws BazaarException
237261
*/
238-
List<Project> getFollowedProjects(int userId, int count) throws BazaarException;
262+
void removeUserFromProject(int userId, int projectId) throws BazaarException;
239263

240264
//endregion
241265

@@ -651,9 +675,33 @@ public interface DALFacade {
651675

652676
void createPrivilegeIfNotExists(PrivilegeEnum privilege) throws BazaarException;
653677

678+
Role getRoleByName(String role) throws BazaarException;
679+
680+
boolean hasUserRole(int userId, String roleName, Integer context) throws BazaarException;
681+
682+
/**
683+
* Returns whether a user has any role in a certain context.
684+
*
685+
* @param userId
686+
* @param context (required)
687+
* @return
688+
*/
689+
boolean hasUserAnyRoleInContext(int userId, int context);
690+
654691
void addUserToRole(int userId, String roleName, Integer context) throws BazaarException;
655692

656-
Role getRoleByName(String role) throws BazaarException;
693+
void removeUserFromRole(int userId, String roleName, Integer context) throws BazaarException;
694+
695+
/**
696+
* Remove the user from all roles assigned in a certain context.
697+
*
698+
* @param userId
699+
* @param context (required for this methdod!)
700+
*/
701+
void removeUserFromRolesByContext(int userId, int context) throws BazaarException;
702+
703+
void replaceUserRole(int userId, String oldRoleName, String newRoleName, Integer context) throws BazaarException;
704+
657705
//endregion
658706

659707

reqbaz/src/main/java/de/rwth/dbis/acis/bazaar/service/dal/DALFacadeImpl.java

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import java.util.Calendar;
4545
import java.util.HashMap;
4646
import java.util.List;
47+
import java.util.Optional;
4748

4849
/**
4950
* @since 6/14/2014
@@ -762,22 +763,80 @@ public void createPrivilegeIfNotExists(PrivilegeEnum privilege) throws BazaarExc
762763

763764
}
764765

766+
@Override
767+
public boolean hasUserRole(int userId, String roleName, Integer context) throws BazaarException {
768+
roleRepository = (roleRepository != null) ? roleRepository : new RoleRepositoryImpl(dslContext);
769+
return roleRepository.hasUserRole(userId, roleName, context);
770+
}
771+
772+
@Override
773+
public boolean hasUserAnyRoleInContext(int userId, int context) {
774+
roleRepository = (roleRepository != null) ? roleRepository : new RoleRepositoryImpl(dslContext);
775+
return roleRepository.hasUserAnyRoleInContext(userId, context);
776+
}
777+
765778
@Override
766779
public void addUserToRole(int userId, String roleName, Integer context) throws BazaarException {
767780
roleRepository = (roleRepository != null) ? roleRepository : new RoleRepositoryImpl(dslContext);
768781
roleRepository.addUserToRole(userId, roleName, context);
769782
}
770783

784+
@Override
785+
public void removeUserFromRole(int userId, String roleName, Integer context) throws BazaarException {
786+
roleRepository = (roleRepository != null) ? roleRepository : new RoleRepositoryImpl(dslContext);
787+
roleRepository.removeUserFromRole(userId, roleName, context);
788+
}
789+
790+
@Override
791+
public void removeUserFromRolesByContext(int userId, int context) throws BazaarException {
792+
roleRepository = (roleRepository != null) ? roleRepository : new RoleRepositoryImpl(dslContext);
793+
roleRepository.removeUserFromRolesByContext(userId, context);
794+
}
795+
796+
@Override
797+
public void replaceUserRole(int userId, String oldRoleName, String newRoleName, Integer context) throws BazaarException {
798+
roleRepository = (roleRepository != null) ? roleRepository : new RoleRepositoryImpl(dslContext);
799+
roleRepository.replaceUserRole(userId, oldRoleName, newRoleName, context);
800+
}
801+
771802
@Override
772803
public Role getRoleByName(String role) throws BazaarException {
773804
roleRepository = (roleRepository != null) ? roleRepository : new RoleRepositoryImpl(dslContext);
774805
return roleRepository.findByRoleName(role);
775806
}
776807

777808
@Override
778-
public void removeUserFromProject(int userId, Integer context) throws BazaarException {
809+
public void updateProjectMemberRole(int projectId, int userId, String roleName) throws BazaarException {
810+
roleRepository = (roleRepository != null) ? roleRepository : new RoleRepositoryImpl(dslContext);
811+
812+
/*
813+
* NOTE: Do NOT use getProjectRole here! This would return 'virtually' assigned project roles e.g., for
814+
* a user with the SystemAdmin role. In this case the replaceUserRole would not work as expected
815+
* because there is no actually stored role to replace!
816+
*
817+
* TODO Refactor this again so these concepts are not mixed up!
818+
*/
819+
Optional<Integer> prevRole = roleRepository.findRoleIdsByContext(userId, projectId).stream().findFirst();
820+
821+
Role newRole = roleRepository.findByRoleName(roleName);
822+
823+
if (prevRole.isPresent()) {
824+
roleRepository.replaceUserRole(userId, prevRole.get(), newRole.getId(), projectId);
825+
} else {
826+
roleRepository.addUserToRole(userId, newRole.getId(), projectId);
827+
}
828+
}
829+
830+
@Override
831+
public void removeUserFromProject(int userId, int projectId) throws BazaarException {
832+
roleRepository = (roleRepository != null) ? roleRepository : new RoleRepositoryImpl(dslContext);
833+
roleRepository.removeUserFromRolesByContext(userId, projectId);
834+
}
835+
836+
@Override
837+
public boolean isUserProjectMember(int projectId, int userId) {
779838
roleRepository = (roleRepository != null) ? roleRepository : new RoleRepositoryImpl(dslContext);
780-
roleRepository.removeUserFromRole(userId, context);
839+
return roleRepository.hasUserAnyRoleInContext(userId, projectId);
781840
}
782841

783842
@Override

reqbaz/src/main/java/de/rwth/dbis/acis/bazaar/service/dal/repositories/RoleRepository.java

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,66 @@
3535
public interface RoleRepository extends Repository<Role> {
3636
List<Role> listParentsForRole(int roleId) throws BazaarException;
3737

38+
/**
39+
* Returns the roles of a user in the given context including 'globally' assigned roles (i.e., roles
40+
* stored with context 'null').<br>
41+
* <br>
42+
* NOTE: This is th higher level function which should be user for authorization / access control.
43+
*
44+
* @param userId
45+
* @param context
46+
* @return
47+
* @throws BazaarException
48+
*/
3849
List<Role> listRolesOfUser(int userId, Integer context) throws BazaarException;
3950

51+
/**
52+
* Returns <i>exactly</i> the roles that are assigned to a user in th given context.<br>
53+
* In contrast to 'listRolesOfUser' this is only a straightforward database query which does
54+
* not apply any knowledge about higher level roles (i.e. SystemAdmin which may override
55+
* locally assigned roles like 'ProjectMember')
56+
*
57+
* @param userId
58+
* @param context
59+
* @return
60+
*/
61+
List<Integer> findRoleIdsByContext(int userId, Integer context);
62+
63+
boolean hasUserRole(int userId, String roleName, Integer context) throws BazaarException;
64+
boolean hasUserRole(int userId, int roleId, Integer context) throws BazaarException;
65+
66+
/**
67+
* Returns whether a user has any role in a certain context.
68+
*
69+
* @param userId
70+
* @param context (required)
71+
* @return
72+
*/
73+
boolean hasUserAnyRoleInContext(int userId, int context);
74+
4075
void addUserToRole(int userId, String roleName, Integer context) throws BazaarException;
76+
void addUserToRole(int userId, int roleId, Integer context) throws BazaarException;
77+
78+
void removeUserFromRole(int userId, String roleName, Integer context) throws BazaarException;
79+
void removeUserFromRole(int userId, int roleId, Integer context) throws BazaarException;
80+
81+
/**
82+
* Remove the user from all roles assigned in a certain context.
83+
*
84+
* @param userId
85+
* @param context (required for this methdod!)
86+
*/
87+
void removeUserFromRolesByContext(int userId, int context) throws BazaarException;
88+
89+
void replaceUserRole(int userId, String oldRoleName, String newRoleName, Integer context) throws BazaarException;
90+
void replaceUserRole(int userId, int oldRoleId, int newRoleId, Integer context) throws BazaarException;
4191

4292
Role findByRoleName(String roleName) throws BazaarException;
4393

94+
//
95+
// project member specific methods -> TODO move to some higher level service!
96+
//
97+
4498
PaginationResult<ProjectMember> listProjectMembers(int projectId, Pageable pageable) throws BazaarException;
4599

46100
/**
@@ -52,6 +106,4 @@ public interface RoleRepository extends Repository<Role> {
52106
* @throws BazaarException
53107
*/
54108
ProjectRole getProjectRole(int userId, int projectId) throws BazaarException;
55-
56-
void removeUserFromRole(int userId, Integer context) throws BazaarException;
57109
}

0 commit comments

Comments
 (0)