Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:geonetwork/core-geonetwork into …
Browse files Browse the repository at this point in the history
…develop
  • Loading branch information
Delawen committed Aug 29, 2014
2 parents 5bb5ef4 + 8846a4b commit 7a49a54
Show file tree
Hide file tree
Showing 18 changed files with 241 additions and 214 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ public class SearchParameter {
public static final String SPATIALREPRESENTATIONTYPE = "spatialRepresentationType";
public static final String VALID = "valid";
public static final String HASFEATURECAT="hasfeaturecat";
public static final String ROOT = "_root";
public static final String ISTEMPLATE = "_isTemplate";
public static final String RESULTTYPE = "resultType";

public static final String OP_VIEW = "_operation0";
public static final String OP_DOWNLOAD = "_operation1";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ public Map<String, Set<String>> getSearchCriteria() {
SearchParameter.PARENTUUID,
SearchParameter.OPERATESON,
SearchParameter._SCHEMA,
SearchParameter.ROOT,
SearchParameter.ISTEMPLATE,
SearchParameter.RESULTTYPE,
SearchParameter.RELATION,
SearchParameter.SITEID,
SearchParameter.TYPE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,18 +111,13 @@ public void addPrivileges(String id, Iterable<Privileges> privilegesIterable, Gr
for (int opId: priv.getOperations()) {
name = dataMan.getAccessManager().getPrivilegeName(opId);

//--- allow only: view, dynamic, featured
if (opId == 0 || opId == 5 || opId == 6) {
//--- all existing operation
if (name != null) {
if(log.isDebugEnabled()) {
log.debug(" --> "+ name);
log.debug(" --> Operation: "+ name);
}
dataMan.setOperation(context, id, priv.getGroupId(), opId +"");
}
else {
if(log.isDebugEnabled()) {
log.debug(" --> "+ name +" (skipped)");
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.fao.geonet.constants.Params;
import org.fao.geonet.domain.Metadata;
import org.fao.geonet.domain.OperationAllowed;
import org.fao.geonet.domain.OperationAllowedId;
import org.fao.geonet.kernel.AccessManager;
import org.fao.geonet.kernel.DataManager;
import org.fao.geonet.kernel.SelectionManager;
Expand Down Expand Up @@ -101,17 +102,21 @@ public Element serviceSpecificExec(Element params, ServiceContext context) throw
//-- group does which is why we have an ownerGroup (parameter groupid)
Integer sourceUsr = info.getSourceInfo().getOwner();
Integer sourceGrp = info.getSourceInfo().getGroupOwner();
Vector<String> sourcePriv = retrievePrivileges(context, id, "" + sourceUsr, "" + sourceGrp);
Vector<OperationAllowedId> sourcePriv =
retrievePrivileges(context, id, "" + sourceUsr, "" + sourceGrp);

// -- Set new privileges for new owner from privileges of the old
// -- owner, if none then set defaults
if (sourcePriv.size() == 0) {
dm.copyDefaultPrivForGroup(context, id, targetGrp, false);
context.info("No privileges for user " + sourceUsr + " on metadata " + id + ", so setting default privileges");
} else {
for (String priv : sourcePriv) {
dm.unsetOperation(context, id, "" + sourceGrp, priv);
dm.setOperation(context, id, targetGrp, priv);
for (OperationAllowedId priv : sourcePriv) {
dm.unsetOperation(context, id,
"" + sourceGrp,
"" + priv.getOperationId());
dm.setOperation(context, id, targetGrp,
"" + priv.getOperationId());
}
}
// -- set the new owner into the metadata record
Expand All @@ -138,7 +143,7 @@ public Element serviceSpecificExec(Element params, ServiceContext context) throw

//--------------------------------------------------------------------------

private Vector<String> retrievePrivileges(ServiceContext context, String id, String userId, String groupId) throws Exception {
private Vector<OperationAllowedId> retrievePrivileges(ServiceContext context, String id, String userId, String groupId) throws Exception {

OperationAllowedRepository opAllowRepo = context.getBean(OperationAllowedRepository.class);

Expand All @@ -151,9 +156,9 @@ private Vector<String> retrievePrivileges(ServiceContext context, String id, Str

List<OperationAllowed> operationsAllowed = opAllowRepo.findAllWithOwner(iUserId, Optional.of(spec));

Vector<String> result = new Vector<String>();
Vector<OperationAllowedId> result = new Vector<OperationAllowedId>();
for (OperationAllowed operationAllowed : operationsAllowed) {
result.add(String.valueOf(operationAllowed.getId()));
result.add(operationAllowed.getId());
}

return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class Transfer extends NotInReadOnlyModeService {
* @param params
* @throws Exception
*/
public void init(String appPath, ServiceConfig params) throws Exception {}
public void init(String appPath, ServiceConfig params) throws Exception {}

/**
*
Expand All @@ -62,71 +62,82 @@ public void init(String appPath, ServiceConfig params) throws Exception {}
* @return
* @throws Exception
*/
public Element serviceSpecificExec(Element params, ServiceContext context) throws Exception {
int sourceUsr = Util.getParamAsInt(params, "sourceUser");
int sourceGrp = Util.getParamAsInt(params, "sourceGroup");
int targetUsr = Util.getParamAsInt(params, "targetUser");
int targetGrp = Util.getParamAsInt(params, "targetGroup");
public Element serviceSpecificExec(Element params, ServiceContext context) throws Exception {
int sourceUsr = Util.getParamAsInt(params, "sourceUser");
int sourceGrp = Util.getParamAsInt(params, "sourceGroup");
int targetUsr = Util.getParamAsInt(params, "targetUser");
int targetGrp = Util.getParamAsInt(params, "targetGroup");

GeonetContext gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME);
DataManager dm = gc.getBean(DataManager.class);
GeonetContext gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME);
DataManager dm = gc.getBean(DataManager.class);

//--- transfer privileges (if case)
//--- transfer privileges (if case)

Set<String> sourcePriv = retrievePrivileges(context, sourceUsr, sourceGrp);
Set<String> targetPriv = retrievePrivileges(context, null, targetGrp);
Set<String> sourcePriv = retrievePrivileges(context, sourceUsr, sourceGrp);
Set<String> targetPriv = retrievePrivileges(context, null, targetGrp);

//--- a commit just to release some resources
//--- a commit just to release some resources

dm.flush();

int privCount = 0;

Set<Integer> metadata = new HashSet<Integer>();

for (String priv : sourcePriv)
{
StringTokenizer st = new StringTokenizer(priv, "|");

int opId = Integer.parseInt(st.nextToken());
int mdId = Integer.parseInt(st.nextToken());

dm.unsetOperation(context, mdId, sourceGrp, opId);

if (!targetPriv.contains(priv)) {
OperationAllowedRepository repository = context.getBean(OperationAllowedRepository.class);
OperationAllowedId id = new OperationAllowedId()
.setGroupId(targetGrp)
.setMetadataId(mdId)
.setOperationId(opId);
OperationAllowed operationAllowed = new OperationAllowed(id );
repository.save(operationAllowed);
}
Set<Integer> metadata = new HashSet<Integer>();

for (String priv : sourcePriv)
{
StringTokenizer st = new StringTokenizer(priv, "|");

int opId = Integer.parseInt(st.nextToken());
int mdId = Integer.parseInt(st.nextToken());

// 2 cases could happen, 1) only the owner change
// in that case sourceGrp = targetGrp and operations
// allowed does not need to be modified.
if (sourceGrp != targetGrp) {
// 2) the sourceGrp != targetGrp and in that
// case, all operations need to be transfered to
// the new group if not already defined.
dm.unsetOperation(context, mdId, sourceGrp, opId);

if (!targetPriv.contains(priv)) {
OperationAllowedRepository repository = context.getBean(OperationAllowedRepository.class);
OperationAllowedId id = new OperationAllowedId()
.setGroupId(targetGrp)
.setMetadataId(mdId)
.setOperationId(opId);
OperationAllowed operationAllowed = new OperationAllowed(id );
repository.save(operationAllowed);
}
}

// Collect all metadata ids
metadata.add(mdId);
privCount++;
}

// Set owner for all records to be modified.
for (Integer i : metadata) {
final MetadataRepository metadataRepository = context.getBean(MetadataRepository.class);
final Metadata metadata1 = metadataRepository.findOne(mdId);
final Metadata metadata1 = metadataRepository.findOne(i);
metadata1.getSourceInfo().setGroupOwner(targetGrp).setOwner(targetUsr);
metadataRepository.save(metadata1);

metadata.add(mdId);
privCount++;
}
}

dm.flush();

//--- reindex metadata
List<String> list = new ArrayList<String>();
for (int mdId : metadata) {
for (int mdId : metadata) {
list.add(Integer.toString(mdId));
}

dm.indexMetadata(list);

//--- return summary
return new Element("response")
.addContent(new Element("privileges").setText(privCount +""))
.addContent(new Element("metadata") .setText(metadata.size()+""));
}
return new Element("response")
.addContent(new Element("privileges").setText(privCount +""))
.addContent(new Element("metadata") .setText(metadata.size()+""));
}

/**
*
Expand Down
14 changes: 11 additions & 3 deletions services/src/main/java/org/fao/geonet/services/user/Update.java
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ private void checkAccessRights(final String operation, final String id, final St
private void setUserGroups(final User user, final Element params, final ServiceContext context) throws Exception {
String[] profiles = {Profile.UserAdmin.name(), Profile.Reviewer.name(), Profile.Editor.name(), Profile.RegisteredUser.name()};
Collection<UserGroup> toAdd = new ArrayList<UserGroup>();

Set<String> listOfAddedProfiles = new HashSet<String>();
final GroupRepository groupRepository = context.getBean(GroupRepository.class);
final UserGroupRepository userGroupRepository = context.getBean(UserGroupRepository.class);

Expand All @@ -264,14 +264,22 @@ private void setUserGroups(final User user, final Element params, final ServiceC
.setGroup(group)
.setProfile(Profile.Editor)
.setUser(user);
toAdd.add(userGroup);
String key = Profile.Editor.toString() + group.getId();
if (!listOfAddedProfiles.contains(key)) {
toAdd.add(userGroup);
listOfAddedProfiles.add(key);
}
}

final UserGroup userGroup = new UserGroup()
.setGroup(group)
.setProfile(Profile.findProfileIgnoreCase(profile))
.setUser(user);
toAdd.add(userGroup);
String key = profile + group.getId();
if (!listOfAddedProfiles.contains(key)) {
toAdd.add(userGroup);
listOfAddedProfiles.add(key);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,24 @@ function radioModalUpdate(div, service, modalbox, title) {


function addGroups(xmlRes){
var list = xmlRes.getElementsByTagName('groups'), i;
var list = xmlRes.getElementsByTagName('record'), i, listOfUserGroups = {};
Ext.getDom('group').options.length = 0;
for (i = 0; i < list.length; i++) {
var id = list[i].getElementsByTagName('id')[0].firstChild.nodeValue;
var name = list[i].getElementsByTagName('name')[0].firstChild.nodeValue;
var opt = document.createElement('option');
opt.text = name;
opt.value = id;
if (list.length === 1) {
opt.selected = true;

// User may have a group defined for more than one profile.
// Only display groups once.
if (!listOfUserGroups[id]) {
var opt = document.createElement('option');
opt.text = name;
opt.value = id;
if (list.length === 1) {
opt.selected = true;
}
Ext.getDom('group').options.add(opt);
listOfUserGroups[id] = true;
}
Ext.getDom('group').options.add(opt);
}
}

Expand Down Expand Up @@ -440,4 +446,4 @@ function massiveMetadataReplace_removeRow(id) {

// Clean results report
$('massivereplace-results-container').innerHTML = "";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -218,15 +218,6 @@ GeoNetwork.LoginForm = Ext.extend(Ext.FormPanel, {
},
scope: this
}
}),
new Ext.Button({
text: OpenLayers.i18n('updatePassword'),
listeners: {
click: function () {
this.catalogue.moveToURL(this.catalogue.services.updatePassword + this.catalogue.identifiedUser.username);
},
scope: this
}
}));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@
'@name' : 'view'
}, {
'@name' : 'dynamic'
}, {
'@name' : 'download'
}]};
};
var defaultPrivileges = [getPrivilege(1)];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,17 +163,6 @@
var refreshForm = function(snippet) {
// Compiling
var content = snippet;
if (gnCurrentEdit.compileScope) {
// Destroy previous scope
if (gnCurrentEdit.formScope) {
gnCurrentEdit.formScope.$destroy();
}

// Compile against a new scope
gnCurrentEdit.formScope =
gnCurrentEdit.compileScope.$new();
content = $compile(snippet)(gnCurrentEdit.formScope);
}

// Remove form element / To be improved
// If not doing this, a detached DOM tree
Expand All @@ -184,7 +173,19 @@
// make those objects not reachable by GC.
$(gnCurrentEdit.formId).find('*').remove();

$(gnCurrentEdit.formId).replaceWith(content);
$(gnCurrentEdit.formId).replaceWith(snippet);

if (gnCurrentEdit.compileScope) {
// Destroy previous scope
if (gnCurrentEdit.formScope) {
gnCurrentEdit.formScope.$destroy();
}

// Compile against a new scope
gnCurrentEdit.formScope =
gnCurrentEdit.compileScope.$new();
$compile(snippet)(gnCurrentEdit.formScope);
}

scope.onFormLoad();
};
Expand Down
Loading

0 comments on commit 7a49a54

Please sign in to comment.