hhuijser/liferay-portal — pull request #1887 by yuhai (2014-05-15 09:06:22+00:00)
Title: LPS-44761 rollback LPS-39268 "from the scope the structure belongs to, y...

...ou can see who is using that structure (or template)"

The issue should be caused by LPS-39268's commit "from the scope the structure belongs to, you can see who is using that structure (or template)". This commit missed one logic "themeDisplay.getScopeGroupId() == themeDisplay.getCompanyGroupId()".

For the current issue, except CompanyAdmin, all people can't see Site's journalArticles by using "browse by Structure". The reason is that exists groupId=0 as query situation when get data from journalarticle table. The groupId=0 was added by the below code:
####
JournalArticleFinderImpl.doCountByG_C_S() {
if (inlineSQLHelper) {
sql = InlineSQLHelperUtil.replacePermissionCheck(
sql, JournalArticle.class.getName(),
"JournalArticle.resourcePrimKey", groupId);
}
}
####

In InlineSQLHelperUtil.replacePermissionCheck, CompanyAdmin only didn't execute replacePermissionCheckJoin.
For other people, the sql looks like:
"SELECT COUNT(DISTINCT JournalArticle.articleId) AS COUNT_VALUE FROM JournalArticle INNER JOIN ( SELECT scope, .. FROM ResourcePermission WHERE (ResourcePermission.companyId = 10156) AND ...) InlineSQLResourcePermission ON (((InlineSQLResourcePermission.primKey = CAST_TEXT(JournalArticle.resourcePrimKey)) AND (((JournalArticle.groupId = 0))))) WHERE (classNameId = ?) AND (structureId = ?) AND (JournalArticle.status != ?)"

So for other Sites except Global site, the groupId shouldn't equal '0'.

LPS-39268's fix missed the logic "themeDisplay.getScopeGroupId() == themeDisplay.getCompanyGroupId()". I think groupId=0 mainly used in global site. When CompanyAdmin view all journalArticles which were created using global structure in global site. At this time, all the articles from all the sites using this structure will be shown. The sql looks like:
"SELECT COUNT(DISTINCT JournalArticle.articleId) AS COUNT_VALUE FROM JournalArticle WHERE (classNameId = ?) AND (structureId = ?) AND (JournalArticle.status != ?)"

So after rollback this commit, we still can distinguish who is using that structure (or template). For global site, groupId equal 0 (groupId=0 will be removed from sql query from the below code fragment). For other sites, groupId shouldn't equal '0'.
####
JournalArticleFinderImpl.doCountByG_C_S() {
if (groupId <= 0) {
sql = StringUtil.replace(
sql, "(groupId = ?) AND", StringPool.BLANK);
}
}
####
Please help and review it.

Thanks,
Hai