Hi @Panos,
Please help to check the classes that I used for my content type.
The method canView(final User user, final Object o) of ProductPermissionDelegate never gets called.
Thanks,
public class ProductContentType implements ContentType {
public static final String KEY = ProductContentTypes.PRODUCT_CONTENT_TYPE_KEY;
private final ContentEntityAdapter contentEntityAdapter;
private final PermissionDelegate permissionDelegate;
private final ContentUiSupport contentUiSupport;
@Autowired
public ProductContentType(
@Qualifier ("ProductContentEntityAdapter") final ContentEntityAdapter contentEntityAdapter,
@Qualifier("ProductPermissionDelegate") final PermissionDelegate permissionDelegate)
{
this.permissionDelegate = permissionDelegate;
this.contentEntityAdapter = contentEntityAdapter;
this.contentUiSupport = new ProductContentUiSupport();
}
@Override
public ContentEntityAdapter getContentAdapter()
{
return contentEntityAdapter;
}
@Override
public PermissionDelegate getPermissionDelegate()
{
return permissionDelegate;
}
@Override
public ContentUiSupport getContentUiSupport()
{
return contentUiSupport;
}
}
@Component
public class ProductPermissionDelegate implements PermissionDelegate {
private final static Logger LOG = LoggerFactory.getLogger(ProductPermissionDelegate.class);
private final ProductManager ProductManager;
private final UserAccessor userAccessor;
@Autowired
public ProductPermissionDelegate(ProductManager ProductManager, UserAccessor userAccessor)
{
this.ProductManager = ProductManager;
this.userAccessor = userAccessor;
}
@Override
public boolean canView(final User user, final Object o)
{
ConfluenceUser confluenceUser = user == null ? null : userAccessor.getUserByName(user.getName());
if (o instanceof CustomContentEntityObject)
{
return canViewCustomContentEntityObject((CustomContentEntityObject) o);
}
return false;
}
@Override
public boolean canView(@Nullable User user) {
return true;
}
@Override
public boolean canEdit(User user, Object o) {
return true;
}
@Override
public boolean canSetPermissions(User user, Object o) {
return true;
}
@Override
public boolean canRemove(User user, Object o) {
return true;
}
@Override
public boolean canExport(User user, Object o) {
return true;
}
@Override
public boolean canAdminister(User user, Object o) {
return true;
}
@Override
public boolean canCreate(User user, Object o) {
return true;
}
@Override
public boolean canCreateInTarget(User user, Class aClass) {
return true;
}
protected boolean canViewCustomContentEntityObject(CustomContentEntityObject contentEntityObject)
{
String contentKey = contentEntityObject.getPluginModuleKey();
String spaceKey = contentEntityObject.getProperties().getStringProperty(ProductContentTypes.SPACE_KEY);
if (ProductContentType.KEY.equals(contentKey))
{
return ProductManager.hasViewingPermission(spaceKey);
}
return false;
}
}
@Component
public class ProductContentEntityAdapter extends ContentEntityAdapterParent {
@Override
public Option<String> getUrlPath(CustomContentEntityObject cceo)
{
String spaceKey = getSpaceKey(cceo);
String ProductId = getProductId(cceo);
if(StringUtils.isEmpty(spaceKey)){
return Option.some("/my/Products/" + ProductId);
}
return Option.some("/display/" + spaceKey + "/my/Products/" + ProductId);
}
@Override
public Option<String> getDisplayTitle(CustomContentEntityObject pluginContentEntityObject)
{
return Option.some(pluginContentEntityObject.getTitle());
}
@Override
public BodyType getDefaultBodyType(CustomContentEntityObject pluginContentEntityObject)
{
return BodyType.XHTML;
}
@Override
public Option<String> getExcerpt(CustomContentEntityObject pluginContentEntityObject)
{
return Option.some(pluginContentEntityObject.getBodyAsString());
}
public boolean isIndexable(final CustomContentEntityObject pluginContentEntityObject, final boolean isDefaultIndexable)
{
return true;
}
private String getProductId(CustomContentEntityObject pluginContentEntityObject)
{
return pluginContentEntityObject.getProperties().getStringProperty(ProductContentTypes.Product_ID);
}
private String getSpaceKey(CustomContentEntityObject pluginContentEntityObject)
{
return pluginContentEntityObject.getProperties().getStringProperty(ProductContentTypes.SPACE_KEY);
}
}
public class ProductContentTypeManager implements InitializingBean, DisposableBean {
private final static Logger LOG = LoggerFactory.getLogger(ProductContentTypeManager.class);
SaveContext RETAIN_MODIFICATION_DATA = new DefaultSaveContext(false, true, false);
private final CustomContentManager customContentManager;
private final EventPublisher eventPublisher;
public ProductContentTypeManager(CustomContentManager customContentManager, EventPublisher eventPublisher)
{
this.customContentManager = customContentManager;
this.eventPublisher = eventPublisher;
}
@Override
public void destroy() throws Exception {
eventPublisher.unregister(this);
}
@Override
public void afterPropertiesSet() throws Exception {
eventPublisher.register(this);
}
@EventListener
public void handleProductCreated(ProductEvent ProductEvent)
{
Product product = ProductEvent.getProduct();
CustomContentEntityObject productContentEntity = customContentManager.newPluginContentEntityObject(ProductContentType.KEY);
productContentEntity.setTitle(product.getTitle());
productContentEntity.setBodyAsString(StringEscapeUtils.escapeHtml(product.getBody()));
productContentEntity.getProperties().setStringProperty(ProductContentTypes.SPACE_KEY, product.getSpaceKey());
productContentEntity.getProperties().setStringProperty(ProductContentTypes.Product_ID, Long.toString(product.getId()));
customContentManager.saveContentEntity(productContentEntity, RETAIN_MODIFICATION_DATA);
}
}