Same changes made to RoleEditForm, now for RoleAddForm
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4336 8810af33-2d31-482b-a856-94f89814c4dfpull/2/head
parent
7be48cd59e
commit
1046e331ec
|
|
@ -24,11 +24,18 @@ import com.arsdigita.bebop.SingleSelectionModel;
|
||||||
import com.arsdigita.bebop.event.FormProcessListener;
|
import com.arsdigita.bebop.event.FormProcessListener;
|
||||||
import com.arsdigita.bebop.event.FormSectionEvent;
|
import com.arsdigita.bebop.event.FormSectionEvent;
|
||||||
import com.arsdigita.cms.CMS;
|
import com.arsdigita.cms.CMS;
|
||||||
|
import com.arsdigita.kernel.KernelConfig;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.libreccm.security.Group;
|
import org.libreccm.cdi.utils.CdiUtil;
|
||||||
import org.libreccm.security.Role;
|
import org.libreccm.configuration.ConfigurationManager;
|
||||||
|
import org.libreccm.l10n.LocalizedString;
|
||||||
|
import org.libreccm.security.*;
|
||||||
import org.librecms.contentsection.ContentSection;
|
import org.librecms.contentsection.ContentSection;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For more detailed information see {@link com.arsdigita.bebop.Form}.
|
* For more detailed information see {@link com.arsdigita.bebop.Form}.
|
||||||
*
|
*
|
||||||
|
|
@ -59,33 +66,38 @@ final class RoleAddForm extends BaseRoleForm {
|
||||||
public final void process(final FormSectionEvent e)
|
public final void process(final FormSectionEvent e)
|
||||||
throws FormProcessException {
|
throws FormProcessException {
|
||||||
final PageState state = e.getPageState();
|
final PageState state = e.getPageState();
|
||||||
final ContentSection section =
|
|
||||||
CMS.getContext().getContentSection();
|
|
||||||
|
|
||||||
Group group;
|
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||||
/*
|
final PermissionManager permissionManager = cdiUtil.findBean(PermissionManager.class);
|
||||||
if (m_useViewersGroup) {
|
final ConfigurationManager manager = cdiUtil.findBean(ConfigurationManager.class);
|
||||||
group = section.getViewersGroup();
|
final KernelConfig config = manager.findConfiguration(KernelConfig.class);
|
||||||
} else {
|
|
||||||
group = section.getStaffGroup();
|
final Role role = new Role();
|
||||||
}
|
|
||||||
|
|
||||||
final Role role = group.createRole
|
|
||||||
((String) m_name.getValue(state));
|
|
||||||
role.setName((String) m_name.getValue(state));
|
role.setName((String) m_name.getValue(state));
|
||||||
role.setDescription((String) m_description.getValue(state));
|
|
||||||
|
|
||||||
group.save();
|
LocalizedString localizedDescription = role.getDescription();
|
||||||
|
localizedDescription.addValue(config.getDefaultLocale(), (String) m_description.getValue(state));
|
||||||
|
role.setDescription(localizedDescription);
|
||||||
|
|
||||||
RoleFactory.updatePrivileges
|
List<Permission> newPermissions = new ArrayList<>();
|
||||||
(role,
|
String[] selectedPermissions = (String[]) m_privileges.getValue(state);
|
||||||
(String[]) m_privileges.getValue(state),
|
|
||||||
CMS.getContext().getContentSection());
|
|
||||||
|
|
||||||
role.save();
|
for (Permission p : role.getPermissions()) {
|
||||||
|
if (Arrays.stream(selectedPermissions).anyMatch(x -> x.equals(p.getGrantedPrivilege()))) {
|
||||||
|
newPermissions.add(p);
|
||||||
|
} else {
|
||||||
|
permissionManager.revokePrivilege(p.getGrantedPrivilege(), role);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
m_model.setSelectedKey(state, role.getID().toString());
|
for (String s : selectedPermissions) {
|
||||||
*/
|
if (newPermissions.stream().noneMatch(x -> x.getGrantedPrivilege().equals(s))) {
|
||||||
|
permissionManager.grantPrivilege(s, role);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
m_model.setSelectedKey(state, Long.toString(role.getRoleId()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue