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

[Export xml Privacy] add language strings for domain #22240

Closed
wants to merge 35 commits into from

Conversation

cyrezdev
Copy link
Contributor

Add domain name and description for xml export of privacy elements.

@mbabker
Copy link
Contributor

mbabker commented Sep 18, 2018

If these are going to be language strings, they should be rendered in the receiving user's language, not the language of the admin who generates this data (which may be different on a multilingual website), see the privacy component's models for how emails are dealt with for this.

Personally, I don't think they actually do need to be strings, but it should be done right if they are.

@cyrezdev
Copy link
Contributor Author

they should be rendered in the receiving user's language

Good point!

Hummm... will check this.

@infograf768
Copy link
Member

Also, please, always alpha order language strings. no need to separate new strings from existing ones.

@infograf768
Copy link
Member

Could someone explain/post a screenshot to understand what form will take these exported logs, i.e. an example where $domain is displayed?
(Sorry, I still have not been able to create a setup using Privacy by lack of knowledge).
In fact I would like to check if we should not use a sprintf here to cope with RTL languages or else.

@infograf768
Copy link
Member

hmm
the method asks for 2 parameters

protected function createDomain($name, $description = '')
	{
		$domain              = new PrivacyExportDomain;
		$domain->name        = $name;
		$domain->description = $description;

		return $domain;
	}

so I guess a sprintf has no utility here.

@cyrezdev
Copy link
Contributor Author

Could someone explain/post a screenshot to understand what form will take these exported logs, i.e. an example where $domain is displayed?

It is displayed in the xml file of all exported data for one user.


<?xml version="1.0"?>
<data-export>
  <domain name="actionlog" description="Logged actions of the user">
    <item>
      <id>1</id>
      <message>User Admin logged in to admin</message>
      <date>2018-09-17 18:27:46</date>
      <extension>Users</extension>
      <name>Super User</name>
      <ip_address>COM_ACTIONLOGS_DISABLED</ip_address>
    </item>
    <item>
      <id>2</id>
      <message>User Admin installed the library iC Library</message>
      <date>2018-09-17 18:29:45</date>
      <extension>Installer</extension>
      <name>Super User</name>
      <ip_address>COM_ACTIONLOGS_DISABLED</ip_address>
    </item>

...

@infograf768
Copy link
Member

infograf768 commented Sep 19, 2018

Thank you. Understand we get an xml, but how is that xml used ?
Is it transformed in a mail text, else? Basically what is the final result for the user or admin, i.e. what will be displayed and where? Is it stored somewhere?

@cyrezdev
Copy link
Contributor Author

Not display today, only an xml file will all data (for as long as i understand the system after testing).

But using language strings may be useful later (if rendering xml data in a HTML view).
Or using an xml render software ?...

@infograf768
Copy link
Member

infograf768 commented Sep 19, 2018

You may guess I was asking that in relation with translation.
If a non-English speaker will read such a xml, all has to be translated.

The sample code to use the correct language, as @mbabker says, is present in the admin export model

if ($userId)
		{
			$receiver = JUser::getInstance($userId);

			/*
			 * We don't know if the user has admin access, so we will check if they have an admin language in their parameters,
			 * falling back to the site language, falling back to the currently active language
			 */

			$langCode = $receiver->getParam('admin_language', '');

			if (!$langCode)
			{
				$langCode = $receiver->getParam('language', $lang->getTag());
			}

			$lang = JLanguage::getInstance($langCode, $lang->getDebug());
		}

		// Ensure the right language files have been loaded
		$lang->load('com_privacy', JPATH_ADMINISTRATOR, null, false, true)
			|| $lang->load('com_privacy', JPATH_ADMINISTRATOR . '/components/com_privacy', null, false, true);

As a similar code would be used for multiple plugins, I wonder if it would not be good to create a specific method, maybe in plugin.php, and then use the method with the $lang variable obtained in the plugins.

@mbabker
Copy link
Contributor

mbabker commented Sep 19, 2018

Maybe by adding an optional third param userId to the method loadLanguage ?

If you're talking about in the plugin class, no. Generally, the behavior we want is to load the language files for the active user's language.

There are a few special cases where we may want to load another language so text is shown correctly for another user, such as sending emails or these data exports. IMO that doesn't warrant coupling any of the existing language loading logic with the user system. Make a separate helper function somewhere if you must. (Another issue with adding it as a param would mean you're loading that user's preferred language into your active session, whereas the code we use now ensures that a separate Language instance for each language/locale is created; we should not be loading strings for multiple languages into one Language instance beyond the existing fallback behavior)

* @var string
* @since 3.9.0
*/
protected $lang = null;
Copy link
Contributor

Choose a reason for hiding this comment

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

Class member variables do not need to be explicitly initialized with a null value, they default to null.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks!
Did the changes

@cyrezdev
Copy link
Contributor Author

If you're talking about in the plugin class, no. Generally, the behavior we want is to load the language files for the active user's language.

I think mainly to let it case by case as it is in this PR. ;-)
(a bit different for privacy contact, where if no userId, contact email is used)

@mbabker
Copy link
Contributor

mbabker commented Sep 19, 2018

You may guess I was asking that in relation with translation.
If a non-English speaker will read such a xml, all has to be translated.

This is a very basic example of what an export looks like.

<?xml version="1.0"?>
<data-export>
  <domain name="users" description="Joomla! users table data">
    <item id="398">
      <id>398</id>
      <name>Super User</name>
      <username>admin</username>
      <email>admin@localhost.test</email>
      <block>0</block>
      <sendEmail>1</sendEmail>
      <registerDate>2018-09-19 13:55:15</registerDate>
      <lastvisitDate>2018-09-19 13:56:23</lastvisitDate>
      <activation>0</activation>
      <params/>
      <lastResetTime>0000-00-00 00:00:00</lastResetTime>
      <resetCount>0</resetCount>
      <requireReset>0</requireReset>
    </item>
  </domain>
  <domain name="user notes" description="Joomla! user notes data"/>
  <domain name="user profile" description="Joomla! user profile data"/>
  <domain name="user custom fields" description="Joomla! user custom fields data"/>
  <domain name="user contact" description="Joomla! user contact data"/>
  <domain name="user content" description="Joomla! user content data"/>
  <domain name="user message" description="Joomla! user message data"/>
</data-export>

The bulk of it is going to be untranslated anyway as it is all related to either the XML document structure or is based on database column names. That's in part why I felt like translating the text of the name and description attributes really wasn't necessary, you're translating a couple of strings when 95% of it is going to be surrounded by a non-translatable English string or non-localized database contents (which could be in any language known to this planet's 7 billion human inhabitants).

@infograf768
Copy link
Member

@mbabker
I guess I just do not understand the use of this export then.
In that case, translating is indeed useless.

@mbabker
Copy link
Contributor

mbabker commented Sep 19, 2018

To fulfill the GDPR related right to request your data, we provide this data in a XML format to allow the most portability for that data (as XML can be easily machine parsed if you want to do something programmatically with it, or read by a human in its basic form). The name and description attributes are there to make it easier to identify the type of data you're looking at in a section (domain), beyond that though the XML schema is mostly defined by the database column names and the actual values in the export are mostly what are stored in the database (at least with core, no telling what sources third parties may use to include data in this export). Without those two attributes, there's really nothing identifying that you're looking at a user record or a com_contact record or anything like that.

@cyrezdev
Copy link
Contributor Author

So, if not to be translated strings, why not using system naming ?

Something to get constant variables to be able to manage data from xml programmatically :

<?xml version="1.0"?>
<data-export>
  <domain name="users" description="joomla_users_table_data">
    <item id="398">
      <id>398</id>
      <name>Super User</name>
      <username>admin</username>
      <email>admin@localhost.test</email>
      <block>0</block>
      <sendEmail>1</sendEmail>
      <registerDate>2018-09-19 13:55:15</registerDate>
      <lastvisitDate>2018-09-19 13:56:23</lastvisitDate>
      <activation>0</activation>
      <params/>
      <lastResetTime>0000-00-00 00:00:00</lastResetTime>
      <resetCount>0</resetCount>
      <requireReset>0</requireReset>
    </item>
  </domain>
  <domain name="user_notes" description="joomla_user_notes_data"/>
  <domain name="user_profile" description="joomla_user_profile_data"/>
  <domain name="user_custom_fields" description="joomla_user_custom_fields_data"/>
  <domain name="user_contact" description="joomla_user_contact_data"/>
  <domain name="user_content" description="joomla_user_content_data"/>
  <domain name="user_message" description="joomla_user_message_data"/>
</data-export>

@mbabker
Copy link
Contributor

mbabker commented Sep 19, 2018

That would work too. When I did this I just went with basic strings to identify things, both as a developer and a potential end user reading this data. Wasn't really looking for a specific naming convention or purpose or anything like that.

@cyrezdev
Copy link
Contributor Author

That would work too. When I did this I just went with basic strings to identify things, both as a developer and a potential end user reading this data. Wasn't really looking for a specific naming convention or purpose or anything like that.

At first sight, i thought of strings, so of translatable information.

But now, with more insights, i wonder the best way to go... (for sure, not translatable strings, but i wonder if we should let it like this or instead to convert to a convention naming to prevent other persons to think like me to translate those strings... ;-) )

@mbabker
Copy link
Contributor

mbabker commented Sep 19, 2018

Using a standardized convention like what you've suggested is good enough to me.

@cyrezdev
Copy link
Contributor Author

Closed in favor of #22253

@cyrezdev cyrezdev closed this Sep 19, 2018
@infograf768
Copy link
Member

Should not the xml header use encoding="UTF-8" ?

@mbabker
Copy link
Contributor

mbabker commented Sep 19, 2018

Umm, probably? If you know how to change the PHP DOMDocument class to include this header, this is the relevant code block to change.

@alikon
Copy link
Contributor

alikon commented Sep 20, 2018

i've made a dirty hack here

$export = new SimpleXMLElement("<data-export />");

from $export = new SimpleXMLElement("<data-export />");

to
$export = new SimpleXMLElement("<?xml version='1.0' encoding='utf-8'?><data-export />");

if @infograf768 can confirm and if it is not considered too much "hacky" i will do a pr

@infograf768
Copy link
Member

I looked over the net and your solution does not look as a hack. It is provided by quite a few posters.
I would though intervert the single and double quotes
$export = new SimpleXMLElement('<?xml version="1.0" encoding="utf-8"?><data-export />');

@infograf768
Copy link
Member

As I still have not set my test site to use Privacy, can't test the above.

@cyrezdev
Copy link
Contributor Author

i've made a dirty hack here

joomla-cms/administrator/components/com_privacy/helpers/privacy.php

Line 66 in 765c600
$export = new SimpleXMLElement("");

from $export = new SimpleXMLElement("<data-export />");

to
$export = new SimpleXMLElement("<?xml version='1.0' encoding='utf-8'?><data-export />");

if @infograf768 can confirm and if it is not considered too much "hacky" i will do a pr

@alikon It will work like this (commonly used), and tested with Japanese, all is ok now! 👍

@alikon
Copy link
Contributor

alikon commented Sep 20, 2018 via email

@alikon
Copy link
Contributor

alikon commented Sep 20, 2018

please test #22285

mbabker pushed a commit that referenced this pull request Sep 22, 2018
…#22253)

* [Privacy XML export] standardized convention for domain name and description

* [Privacy XML export] standardized convention for domain name and description

* [Privacy XML export] standardized convention for domain name and description

* [Privacy XML export] standardized convention for domain name and description

* [Privacy XML export] standardized convention for domain name and description

* [Privacy XML export] standardized convention for domain name and description

* [Privacy XML export] standardized convention for domain name and description

* [Privacy XML export] standardized convention for domain name and description
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Language Change This is for Translators
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants