Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reports fail for non-admins with related fields #3155

Merged
merged 4 commits into from Feb 23, 2017

Conversation

eggsurplus
Copy link
Contributor

If a report is made by a normal user within a group it will fail if there are related fields in the report. This is due to the table alias not being passed along to the logic to include the SecurityGroups queries.

If a report is made by a normal user within a group it will fail if there are related fields in the report. This is due to the table alias not being passed along to the logic to include the SecurityGroups queries.
@pgorod
Copy link
Contributor

pgorod commented Feb 19, 2017

Jason, if I'm not mistaken, you're supposed to target the hotfix branch for fixes, and the develop branch for new features, but never directly master.

I hope you can find an option to just change the base branch of this PR, without having to re-do it...

@@ -1208,7 +1208,7 @@ function build_report_query_join($name, $alias, $parentAlias, SugarBean $module,
$join = $module->$name->getJoin($params, true);
$query['join'][$alias] = $join['join'];
if($rel_module != null) {
$query['join'][$alias] .= $this->build_report_access_query($rel_module, $name);
$query['join'][$alias] .= $this->build_report_access_query($rel_module, "`$alias`");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think backticks are only supported in MySQL

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I followed the same practice already used in that file elsewhere.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Matt, Jason, See #3165 for correct way to let the db manager handle adding backticks depending on if it's using to a database which supports them or not.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See also PR #1086 very similar to this one.

@mattlorimer mattlorimer changed the base branch from master to hotfix February 19, 2017 15:14
@eggsurplus
Copy link
Contributor Author

@pgorod Sorry, I'll remember that next time. Anything that I need to do for this specific PR?

@pgorod
Copy link
Contributor

pgorod commented Feb 19, 2017

@eggsurplus I see that mattlorimer has already changed the base branch on this PR, so now it's correct.

@samus-aran
Copy link
Contributor

@eggsurplus Is it possible to update your PR to reflect removing the backtick (didn't want to take your commit/fix away from you) :) We have updated areas outside DBManager to remove backticks directly into dynamic queries.

@eggsurplus
Copy link
Contributor Author

Yes. Are you saying that the DBManager logic will no longer format with ticks going forward?

@samus-aran
Copy link
Contributor

samus-aran commented Feb 23, 2017

Apologies @eggsurplus I should've been more clear.

The DBManager deals with the backticks by a function.

$this->db->quoteIdentifier($table_alias)

https://github.com/salesagility/SuiteCRM/pull/3165/files#diff-aede7afff7f65db47e05554c029a1ceeR1381

@eggsurplus
Copy link
Contributor Author

I take some responsibility as well. Too much context switching! I made the change as requested.

@samus-aran samus-aran merged commit 2214cf9 into salesagility:hotfix Feb 23, 2017
@chris001
Copy link
Contributor

Right. Microsoft SQL Server and PostgreSQL don't support ticks. MySQL allows ticks yet doesn't require them. Standard SQL says use double quotes!
http://stackoverflow.com/questions/10573922/what-does-the-sql-standard-say-about-usage-of-backtick

@samus-aran
Copy link
Contributor

Thanks for that @chris001.

So at the moment outside of the MySQL DBManager there shouldn't be any backticks implemented into queries.

The function:

$this->db->quoteIdentifier()

provides the appropriate encapsulation. MSSQL = [ ] and MySQl is the backticks. Consideration to standardise this to double quotes is noted.

However just looking it up there could be a consideration on the SQL Server for QUOTED_IDENTIFIER = OFF.

@chris001
Copy link
Contributor

chris001 commented Feb 23, 2017

This should be delved into deeper and determine what other database abstraction layers handle quoting ticks etc, e.g. Doctrine DB Abstraction Layer, it's sort of the state of the art.
https://github.com/doctrine/dbal
# composer require doctrine/dbal
You absolutely do not want to risk getting this wrong, worst case, the consequences would be data loss, or security holes leading to legally protected private personal information theft ie HIPAA, government, legal, financial, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants