Send institution messages for new users in the correct language

Bug #1705162 reported by Kristina Hoeppner
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Mahara
Fix Released
Low
Unassigned

Bug Description

1. When a site admin registers a new user, the account information message, i.e. the one that contains the username and password, is sent in the language of the admin but should be sent in the institution's language (as the user doesn't yet exist and therefore doesn't yet have a language preference).

2. When a site admin or institution admin invites a user to another institution, that message should be sent in the language of the user that is being invited rather than the admin's language or the site language.

If the user hasn't set a language specifically, the new institution's language should be used (See bug 1703608).

Tags: translations
description: updated
Revision history for this message
Nelson (nmoller-c) wrote :

To correctly treat that, you need to do a similar treatment as the one done in https://bugs.launchpad.net/mahara/+bug/1703608

for the methods get_subject and get message in the class ActivityTypeInstitutionmessage (line 1071 lib/activity.php).

The institution is available in $this->institution (passed throught $data at parent::_construct )

That kind of logic could be encapsulated in a helper class or even in institution class...

If I manage to get something working, I'll try to send you a proposal.

Revision history for this message
Nelson (nmoller-c) wrote :

I'll propose something like:

class ActivityTypeInstitutionmessage extends ActivityType {

    protected $messagetype;
    protected $institution;
    protected $username;
    protected $fullname;

    public function __construct($data, $cron=false) {
        parent::__construct($data, $cron);
        if ($this->messagetype == 'request') {
            $this->url = 'admin/users/institutionusers.php';
            $this->users = activity_get_users($this->get_id(), null, null, null,
                                              array($this->institution->name));
            $this->add_urltext(array('key' => 'institutionmembers', 'section' => 'admin'));
        } else if ($this->messagetype == 'invite') {
            $this->url = 'account/institutions.php';
            $this->users = activity_get_users($this->get_id(), $this->users);
            $this->add_urltext(array('key' => 'institutionmembership', 'section' => 'mahara'));
        }
        $this->institution = new Institution($this->institution->name);
    }

    private function get_language($user, $institution) {
        if (!isset($user->lang) || $user->lang === '' || $user->lang === 'default') {
            if (!isset($institution->lang) || $institution->lang === '' || $institution->lang === 'default') {
                return get_config('lang') ? get_config('lang') : '';
            }
            else return $institution->lang;
        }
        else return $user->lang;
    }

    public function get_subject($user) {
        $lang = $this->get_language($user, $this->institution);
        if ($this->messagetype == 'request') {
            $userstring = $this->fullname . ' (' . $this->username . ')';
            return get_string_from_language($lang, 'institutionrequestsubject', 'activity', $userstring,
                                            $this->institution->displayname);
        } else if ($this->messagetype == 'invite') {
            return get_string_from_language($lang, 'institutioninvitesubject', 'activity',
                                            $this->institution->displayname);
        }
    }

    public function get_message($user) {
        $lang = $this->get_language($user, $this->institution);
        if ($this->messagetype == 'request') {
            return $this->get_subject($user) .' '. get_string_from_language($lang, 'institutionrequestmessage', 'activity', $this->url);
        } else if ($this->messagetype == 'invite') {
            return $this->get_subject($user) .' '. get_string_from_language($lang, 'institutioninvitemessage', 'activity', $this->url);
        }
    }

    public function get_required_parameters() {
        return array('messagetype', 'institution');
    }
}

Revision history for this message
Nelson (nmoller-c) wrote :

@Kristina: I've follow the setup for gerrit (I've added my public key there before :)) and I get:
{code}
10:55 $ git remote add gerrit ssh://<email address hidden>:29418/mahara
✔ ~/dev/mahara/dev [master|✔]
10:55 $ git fetch gerrit
ssh: connect to host reviews.mahara.org port 29418: Connection refused
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
{code}

As it is really at the beginning of the process... I'm kind of embarrassed.

Revision history for this message
Mahara Bot (dev-mahara) wrote : A patch has been submitted for review

Patch for "master" branch: https://reviews.mahara.org/7881

Revision history for this message
Kristina Hoeppner (kris-hoeppner) wrote :

Thank you for the change, Nelson. We'll take a look. It seems you could connect to Gerrit in the end. :-) How did you solve the problem?

I updated your commit message so it will pass Jenkins when it gets to that stage.

Revision history for this message
Mahara Bot (dev-mahara) wrote : A change has been merged

Reviewed: https://reviews.mahara.org/7881
Committed: https://git.mahara.org/mahara/mahara/commit/bf501442d37ccb862b7868426b2f15a8d81262b7
Submitter: Robert Lyon (<email address hidden>)
Branch: master

commit bf501442d37ccb862b7868426b2f15a8d81262b7
Author: Nelson Moller <email address hidden>
Date: Wed Jul 19 12:59:40 2017 -0400

Bug #1705162 Send institution invitations in correct language.

A new method is added to treat the institution lang when an
invitation is sent to the user.

behatnotneeded

Change-Id: I0da8d8341f0dc15f13db9f80dc6f560ca924df3c

Robert Lyon (robertl-9)
Changed in mahara:
status: Confirmed → Fix Committed
milestone: none → 17.10.0
Robert Lyon (robertl-9)
Changed in mahara:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.