Skip to content
Snippets Groups Projects
Commit 7f46fd9d authored by srosse's avatar srosse
Browse files

OO-3286,OO-3296: in administrator, remove role per user and not all

roles, enhance REST API for organisations, organisations in repository
entry can be managed...
parent 587d58ac
No related branches found
No related tags found
No related merge requests found
Showing
with 84 additions and 7 deletions
......@@ -147,6 +147,7 @@ public class CurriculumComposerController extends FormBasicController implements
tableEl.setNumOfRowsEnabled(false);
tableEl.setExportEnabled(true);
tableEl.setPageSize(40);
tableEl.setAndLoadPersistedPreferences(ureq, "curriculum-composer");
}
@Override
......
......@@ -95,7 +95,7 @@ public class CurriculumComposerTableModel extends DefaultFlexiTreeTableDataModel
@Override
public boolean sortable() {
return true;
return false;
}
@Override
......
......@@ -124,6 +124,7 @@ public class CurriculumElementResourceListController extends FormBasicController
tableEl.setExportEnabled(true);
tableEl.setSelectAllEnable(true);
tableEl.setMultiSelect(true);
tableEl.setAndLoadPersistedPreferences(ureq, "curriculum-element-resource-list");
}
private void loadModel() {
......
......@@ -123,9 +123,9 @@ public class CurriculumListManagerController extends FormBasicController impleme
tableModel = new CurriculumManagerDataModel(columnsModel, getLocale());
tableEl = uifactory.addTableElement(getWindowControl(), "table", tableModel, 20, false, getTranslator(), formLayout);
tableEl.setCustomizeColumns(true);
tableEl.setSearchEnabled(true);
tableEl.setEmtpyTableMessageKey("table.curriculum.empty");
tableEl.setAndLoadPersistedPreferences(ureq, "cur-curriculum-manage");
tableEl.setSearchEnabled(true);
}
private void loadModel(String searchString, boolean reset) {
......
......@@ -148,6 +148,7 @@ public class CurriculumUserManagementController extends FormBasicController {
tableEl.setSelectAllEnable(true);
tableEl.setMultiSelect(true);
tableEl.setSearchEnabled(true);
tableEl.setAndLoadPersistedPreferences(ureq, "curriculum-element-user-list");
}
private void loadModel(boolean reset) {
......
......@@ -43,6 +43,7 @@ public enum RepositoryEntryManagedFlag {
requirements(details,all),
credits(details,all),
location(details,all),
organisations(details,all),
settings(all),//max num of participants...
access(settings,all),
search(settings, all),
......
......@@ -436,12 +436,18 @@ public class RepositoryEditDescriptionController extends FormBasicController {
keyList.add(organisation.getKey().toString());
valueList.add(organisation.getDisplayName());
}
List<Organisation> reOrganisations = repositoryService.getOrganisations(repositoryEntry);
repositoryEntryOrganisations = new ArrayList<>(reOrganisations.size());
for(Organisation reOrganisation:reOrganisations) {
if(!keyList.contains(reOrganisation.getKey().toString())) {
keyList.add(reOrganisation.getKey().toString());
valueList.add(reOrganisation.getDisplayName());
}
}
organisationsEl = uifactory.addCheckboxesDropdown("organisations", "cif.organisations", formLayout,
keyList.toArray(new String[keyList.size()]), valueList.toArray(new String[valueList.size()]),
null, null);
List<Organisation> reOrganisations = repositoryService.getOrganisations(repositoryEntry);
repositoryEntryOrganisations = new ArrayList<>(reOrganisations.size());
organisationsEl.setEnabled(!RepositoryEntryManagedFlag.isManaged(repositoryEntry, RepositoryEntryManagedFlag.organisations));
for(Organisation reOrganisation:reOrganisations) {
if(keyList.contains(reOrganisation.getKey().toString())) {
organisationsEl.select(reOrganisation.getKey().toString(), true);
......
......@@ -48,8 +48,12 @@ import org.olat.basesecurity.model.OrganisationTypeRefImpl;
import org.olat.core.commons.persistence.DB;
import org.olat.core.id.Identity;
import org.olat.core.id.Organisation;
import org.olat.core.id.OrganisationRef;
import org.olat.core.id.Roles;
import org.olat.repository.RepositoryEntry;
import org.olat.repository.RepositoryService;
import org.olat.restapi.security.RestSecurityHelper;
import org.olat.restapi.support.vo.RepositoryEntryVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
......@@ -71,6 +75,8 @@ public class OrganisationsWebService {
private BaseSecurity securityManager;
@Autowired
private OrganisationService organisationService;
@Autowired
private RepositoryService repositoryService;
/**
* The version of the User Web Service
......@@ -189,6 +195,22 @@ public class OrganisationsWebService {
return Response.ok(organisationVo).build();
}
@GET
@Path("{organisationKey}/entries")
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
public Response getRepositoryEntriesInOrganisation(@PathParam("organisationKey") Long organisationKey, @Context HttpServletRequest httpRequest) {
if(!isAdministrator(httpRequest)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
OrganisationRef organisation = new OrganisationRefImpl(organisationKey);
List<RepositoryEntry> entries = repositoryService.getRepositoryEntryByOrganisation(organisation);
RepositoryEntryVO[] entryVOes = new RepositoryEntryVO[entries.size()];
for (int i=entries.size(); i-->0; ) {
entryVOes[i] = RepositoryEntryVO.valueOf(entries.get(i));
}
return Response.ok(entryVOes).build();
}
/**
* Updates a new organization entity. the primary key is taken from
* the url. The organization object can be "primary key free".
......
......@@ -114,6 +114,7 @@ public class OrganisationResourceListController extends FormBasicController {
tableEl.setExportEnabled(true);
tableEl.setSelectAllEnable(true);
tableEl.setMultiSelect(true);
tableEl.setAndLoadPersistedPreferences(ureq, "organisation-resources-list");
}
private void loadModel() {
......
......@@ -251,7 +251,10 @@ public class OrganisationUserManagementController extends FormBasicController {
private void doRemove(List<OrganisationUserRow> membersToRemove) {
for(OrganisationUserRow memberToRemove:membersToRemove) {
organisationService.removeMember(organisation, new IdentityRefImpl(memberToRemove.getIdentityKey()));
if(OrganisationRoles.isValue(memberToRemove.getRole()) && !OrganisationRoles.user.name().equals(memberToRemove.getRole())) {
organisationService.removeMember(organisation, new IdentityRefImpl(memberToRemove.getIdentityKey()),
OrganisationRoles.valueOf(memberToRemove.getRole()));
}
}
loadModel(true);
}
......
......@@ -50,6 +50,9 @@ import org.olat.core.id.Identity;
import org.olat.core.id.Organisation;
import org.olat.core.logging.OLog;
import org.olat.core.logging.Tracing;
import org.olat.repository.RepositoryEntry;
import org.olat.repository.RepositoryService;
import org.olat.restapi.support.vo.RepositoryEntryVO;
import org.olat.test.JunitTestHelper;
import org.olat.test.OlatJerseyTestCase;
import org.olat.user.restapi.OrganisationVO;
......@@ -73,6 +76,8 @@ public class OrganisationsWebServiceTest extends OlatJerseyTestCase {
@Autowired
private DB dbInstance;
@Autowired
private RepositoryService repositoryService;
@Autowired
private OrganisationService organisationService;
@Test
......@@ -428,7 +433,6 @@ public class OrganisationsWebServiceTest extends OlatJerseyTestCase {
Assert.assertEquals(2, authorList.size());
}
@Test
public void removeMember_administrator()
throws IOException, URISyntaxException {
......@@ -453,6 +457,33 @@ public class OrganisationsWebServiceTest extends OlatJerseyTestCase {
Assert.assertTrue(administators.isEmpty());
}
@Test
public void getRepositoryEntries()
throws IOException, URISyntaxException {
// prepare an organisation with a course
Identity member = JunitTestHelper.createAndPersistIdentityAsRndUser("org-member-13");
Organisation organisation = organisationService.createOrganisation("REST Organisation 8", "REST-p-8-organisation", "", null, null);
organisationService.addMember(organisation, member, OrganisationRoles.administrator);
dbInstance.commit();
RepositoryEntry course = JunitTestHelper.deployBasicCourse(member);
repositoryService.addOrganisation(course, organisation);
dbInstance.commitAndCloseSession();
RestConnection conn = new RestConnection();
assertTrue(conn.login("administrator", "openolat"));
URI request = UriBuilder.fromUri(getContextURI()).path("organisations").path(organisation.getKey().toString())
.path("entries").build();
HttpGet method = conn.createGet(request, MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(method);
Assert.assertEquals(200, response.getStatusLine().getStatusCode());
List<RepositoryEntryVO> entries = parseRepositoryEntryArray(response.getEntity());
Assert.assertNotNull(entries);
Assert.assertEquals(1, entries.size());
Assert.assertEquals(course.getKey(), entries.get(0).getKey());
}
protected List<UserVO> parseUserArray(HttpEntity entity) {
try(InputStream in=entity.getContent()) {
ObjectMapper mapper = new ObjectMapper(jsonFactory);
......@@ -472,4 +503,14 @@ public class OrganisationsWebServiceTest extends OlatJerseyTestCase {
return null;
}
}
protected List<RepositoryEntryVO> parseRepositoryEntryArray(HttpEntity entity) {
try(InputStream in=entity.getContent()) {
ObjectMapper mapper = new ObjectMapper(jsonFactory);
return mapper.readValue(in, new TypeReference<List<RepositoryEntryVO>>(){/* */});
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment