Skip to content

Conversation

@violoncelloCH
Copy link
Member

@violoncelloCH violoncelloCH commented Dec 27, 2018

as of #6

  • change discouraged operators
  • change deprecated logging method
  • make appinfo.xml compliant
  • OC_DB static method of private class must not be called and private class must not be imported with a use statement

cc @nextcloud/user_external

  1. occ check-code says for the appinfo.xml that the element types would not be expected. In NC12 documentation I can find types, in any newer version it's gone and I can't find any information with what I could replace / change this.

  2. I would also need help with OC_DB - private class must not be imported with a use statement and OC_DB - Static method of private class must not be called. What has to be changed there?

@violoncelloCH
Copy link
Member Author

@MorrisJobke @rullzer @nickvergessen could someone help me with these two points?

@violoncelloCH violoncelloCH added help wanted Extra attention is needed high labels Jan 2, 2019
@violoncelloCH violoncelloCH added this to the 0.5 milestone Jan 2, 2019
@MorrisJobke
Copy link
Member

2. I would also need help with OC_DB - private class must not be imported with a use statement and OC_DB - Static method of private class must not be called. What has to be changed there?

Go with a OCP\DB\IController instead ;)

Signed-off-by: Jonas Sulzer <jonas@violoncello.ch>
Signed-off-by: Jonas Sulzer <jonas@violoncello.ch>
Signed-off-by: Jonas Sulzer <jonas@violoncello.ch>
@violoncelloCH violoncelloCH force-pushed the fix/6/check-code-fixes branch from a99e0b2 to 4eea136 Compare January 4, 2019 22:57
Signed-off-by: Jonas Sulzer <jonas@violoncello.ch>
@violoncelloCH
Copy link
Member Author

So what would be your suggestion @nickvergessen ? (as you reacted on #30 (comment))

@nickvergessen
Copy link
Member

Ah, sorry to create confusion. The interface name was wrong: OCP\IDBConnection is what you should use. Not OCP\DB\IController because our databases dont have a controller class 💃

@MorrisJobke
Copy link
Member

Ah, sorry to create confusion. The interface name was wrong: OCP\IDBConnection is what you should use. Not OCP\DB\IController because our databases dont have a controller class 💃

Yes - it was late and I mixed up the terms :/ @nickvergessen is right 👍

@violoncelloCH
Copy link
Member Author

violoncelloCH commented Jan 9, 2019

thank you for the clarification!
I tried using it with use OCP\IDBConnection; and then the following later on in the code:

		OCP\IDBConnection::executeQuery(
			'DELETE FROM `*PREFIX*users_external` WHERE `uid` = ? AND `backend` = ?',
			array($uid, $this->backend)
		);

but this fails with Message: Class 'OCA\user_external\OCP\IDBConnection' not found -- any idea?

@nickvergessen
Copy link
Member

For now use \OC::$server->getDatabaseConnection()->executeQuery(…)

@violoncelloCH
Copy link
Member Author

thank you @nickvergessen this worked in three places!
however everywhere ->fetchRow() is called or $limit and $offset are passed this doesn't work; e.g.:

$user = OC_DB::executeAudited(
'SELECT `displayname` FROM `*PREFIX*users_external`'
. ' WHERE `uid` = ? AND `backend` = ?',
array($uid, $this->backend)
)->fetchRow();

$result = OC_DB::executeAudited(
array(
'sql' => 'SELECT `uid`, `displayname` FROM `*PREFIX*users_external`'
. ' WHERE (LOWER(`displayname`) LIKE LOWER(?) '
. ' OR LOWER(`uid`) LIKE LOWER(?)) AND `backend` = ?',
'limit' => $limit,
'offset' => $offset
),
array('%' . $search . '%', '%' . $search . '%', $this->backend)
);

user_external/lib/base.php

Lines 173 to 178 in 05fb0e2

$result = OC_DB::executeAudited(
'SELECT COUNT(*) FROM `*PREFIX*users_external`'
. ' WHERE LOWER(`uid`) = LOWER(?) AND `backend` = ?',
array($uid, $this->backend)
);
return $result->fetchOne() > 0;

what can I use there?

@nickvergessen
Copy link
Member

Can you push your changes here? Then I will have a look

Signed-off-by: Jonas Sulzer <jonas@violoncello.ch>
@violoncelloCH
Copy link
Member Author

I pushed the changes for where \OC::$server->getDatabaseConnection()->executeQuery() works :)

@nickvergessen
Copy link
Member

You should be able to change those calls from OC_DB::executeAudited( to \OC::$server->getDatabaseConnection()->executeQuery( and fetchRow( to fetch(

…) where possible

Signed-off-by: Jonas Sulzer <jonas@violoncello.ch>
@violoncelloCH
Copy link
Member Author

violoncelloCH commented Jan 10, 2019

thank you! I changed this, where it worked for me this way. However there are still to places where this fails; these are the functions in which it fails:

public function getDisplayNames($search = '', $limit = null, $offset = null) {

public function getUsers($search = '', $limit = null, $offset = null) {

it fails on the second one on loading the user list (if a user from user_external should be loaded) and errors with: {"reqId":"BruTN3o0cCaCpdjXBLfC","level":3,"time":"2019-01-10T22:19:46+00:00","remoteAddr":"127.0.0.1","user":"jonas","app":"PHP","method":"GET","url":"\/nextcloud\/ocs\/v2.php\/cloud\/users\/details?offset=0&limit=25&search=","message":"Error: Call to a member function execute() on boolean at \/home\/jonas\/nextcloud\/3rdparty\/doctrine\/dbal\/lib\/Doctrine\/DBAL\/Connection.php#849","userAgent":"Mozilla\/5.0 (X11; Ubuntu; Linux x86_64; rv:64.0) Gecko\/20100101 Firefox\/64.0","version":"16.0.0.0"}

@nickvergessen
Copy link
Member

Ah, opsy
change:

		$result = OC_DB::executeAudited(
			array(
				'sql' => 'SELECT `uid`, `displayname` FROM `*PREFIX*users_external`'
					. ' WHERE (LOWER(`displayname`) LIKE LOWER(?) '
					. ' OR LOWER(`uid`) LIKE LOWER(?)) AND `backend` = ?',
				'limit'  => $limit,
				'offset' => $offset
			),
			array('%' . $search . '%', '%' . $search . '%', $this->backend)
		);
		$displayNames = array();
		while ($row = $result->fetchRow()) {
			$displayNames[$row['uid']] = $row['displayname'];
		}

to

		$stmt = \OC::$server->getDatabaseConnection()->prepare(
			'SELECT `uid`, `displayname` FROM `*PREFIX*users_external`'
			. ' WHERE (LOWER(`displayname`) LIKE LOWER(?) '
			. ' OR LOWER(`uid`) LIKE LOWER(?)) AND `backend` = ?',
			$limit, $offset
		);

		$stmt->execute(['%' . $search . '%', '%' . $search . '%', $this->backend]);

		$displayNames = array();
		while ($row = $stmt->fetch()) {
			$displayNames[$row['uid']] = $row['displayname'];
		}

and similar for the second one.

…remaining two

Signed-off-by: Jonas Sulzer <jonas@violoncello.ch>
@violoncelloCH
Copy link
Member Author

thank you very much @nickvergessen ! This is now finally completely working!

remains my first question (for this to be complete):

  1. occ check-code says for the appinfo.xml that the element types would not be expected. In NC12 documentation I can find types, in any newer version it's gone and I can't find any information with what I could replace / change this.

Signed-off-by: Joas Schilling <coding@schilljs.com>
@nickvergessen
Copy link
Member

fixed

@violoncelloCH
Copy link
Member Author

ahh, that simply needs to be after "author"... thanks!

Signed-off-by: Joas Schilling <coding@schilljs.com>
lib/imap.php Outdated
// Check if we only want logins from ONE domain and strip the domain part from UID
}elseif($this->domain != '') {
// Check if we only want logins from ONE domain and strip the domain part from UID
}elseif($this->domain !== '') {
Copy link
Member

Choose a reason for hiding this comment

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

this code is really strange, when there is not exactly one user, the database result is being ignored. Is this intended?

Copy link
Member Author

Choose a reason for hiding this comment

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

hmm, maybe @kosli can help us here?

Copy link
Member Author

Choose a reason for hiding this comment

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

or maybe @pierreozoux ?

Copy link
Member Author

@violoncelloCH violoncelloCH Jan 11, 2019

Choose a reason for hiding this comment

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

@nickvergessen the database returns as many users as there are with the same email address (if this emailaddress is entered in the login form), so this should be zero or one normally, shouldn't it?
It makes it possible to login for normal users with their email address even though in config.php for imap backend another domain is specified. This code as it is written now wouldn't work if there are multiple users with the same email address anyway. If we would change it to if(count($users) >= 1) it would always try to login the first user with the given email address... so I think it's better leave it as it is now and not to try to log in the user at all, if the email address is assigned to multiple users. How does Nextcloud's own user backend handle this case? Shouldn't it be restricted that only one user can have a specific email address?

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

I don't suggest to use if(count($users) >= 1), I just wanted to know if that is intended behaviour. Also as per the code I liked above, the imap user backend should not need to do this. It will be done by the user manager. So actually this method (checkPassword) will be called twice already for email alike logins, so the user_external app does not need to check this.

Copy link
Member

Choose a reason for hiding this comment

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

I commited accordingly, if you still want to keep this, just rebase and drop the commit

Copy link
Member Author

Choose a reason for hiding this comment

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

okay, thank you for clarifying! I'm fine with removing it; login with email for a normal user with another domain still works...

Signed-off-by: Joas Schilling <coding@schilljs.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants