Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Fix behaviour when submitting non locking pages twice #19

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

hughdavenport
Copy link

Issue #2 describes an issue where if you have your plugin set up in a
non locking manner, and submit the same page to multiple assignments,
then only the latest link will work.

The reason for this is the Mahara generates a token in an mt parameter
that changes on every submit. The non locking behaviour allows multiple
submissions, but to do that, it submits then releases, hence generating
a new token.

This patch, along with a patch in Mahara, allows sending a lock
parameter to Mahara, and then appending the url with the moodle
assignment and the mahara view/collection. Mahara will then send a
request back to Moodle to test whether you have permission to view that
view, and if so, stores the result in the session. This allows all
submission urls to work.

For upgrade paths, as this changes the get_view_url method, no change to
existing submissions is needed.

This patch makes a requirement on either a 4 line core Moodle patch, or
a local plugin, as there are issues with subplugin MNet publishers.

fixes #2

Issue #2 describes an issue where if you have your plugin set up in a
non locking manner, and submit the same page to multiple assignments,
then only the latest link will work.

The reason for this is the Mahara generates a token in an mt parameter
that changes on every submit. The non locking behaviour allows multiple
submissions, but to do that, it submits then releases, hence generating
a new token.

This patch, along with a patch in Mahara, allows sending a lock
parameter to Mahara, and then appending the url with the moodle
assignment and the mahara view/collection. Mahara will then send a
request back to Moodle to test whether you have permission to view that
view, and if so, stores the result in the session. This allows all
submission urls to work.

For upgrade paths, as this changes the get_view_url method, no change to
existing submissions is needed.

This patch makes a requirement on either a 4 line core Moodle patch, or
a local plugin, as there are issues with subplugin MNet publishers.
@hughdavenport
Copy link
Author

4 line Moodle core patch would be:

diff --git a/lib/upgradelib.php b/lib/upgradelib.php
index bf22448..414c35e 100644
--- a/lib/upgradelib.php
+++ b/lib/upgradelib.php
@@ -1736,7 +1736,11 @@ function upgrade_plugin_mnet_functions($component) {
                 $dataobject->classname     = $method['classname'];
                 $dataobject->filename      = $method['filename'];
             }
-            $dataobject->xmlrpcpath = $type.'/'.$plugin.'/'.$dataobject->filename.'/'.$method;
+            $xmlrpcpath = $path;
+            if (strstr($xmlrpcpath, $CFG->dirroot) == 0) {
+                $xmlrpcpath = substr($xmlrpcpath, strlen($CFG->dirroot) + 1);
+            }
+            $dataobject->xmlrpcpath = $xmlrpcpath.'/'.$dataobject->filename.'/'.$method;
             $dataobject->static = false;

             require_once($path . '/' . $dataobject->filename);

hughdavenport pushed a commit to catalyst/moodle-local_mahara that referenced this pull request Nov 12, 2015
To be used along side the pull request MaharaProject/moodle-assignsubmission_mahara#19
which fixes MaharaProject/moodle-assignsubmission_mahara#2.

This plugin is simply a wrapper for mnet functions with the assign
submission plugin. This is due to Moodle not supporting publishing
methods in subplugin architecture.
@hughdavenport
Copy link
Author

Local plugin required: catalyst/moodle-local_mahara@177a8b8

@kabalin
Copy link

kabalin commented Nov 12, 2015

Hmm, moodle-local_plugin is de-facto deprecated and not required for any version of Moodle above 2.5 (see requirements section https://moodle.org/plugins/view/assignsubmission_mahara). I am not sure if we can easily respawn it, as in current implementation may conflict with what moodle-assignsubmission_mahara delivers.

@kabalin
Copy link

kabalin commented Nov 12, 2015

I see, you removed all old stuff from moodle-local_plugin. Might worth then creating a master branch for moodle-local_plugin and keeping 2.3 branch as it is. Have you submitted a patch to Moodle core as well?

@agwells
Copy link

agwells commented Nov 12, 2015

Hi Ruslan,

I told Hugh to start his local repo by forking the old one, because it'll make the code management strategy easier, particularly in the Moodle Plugin Database site.

I figured it would be less confusing in the Moodle Plugin site if I add these as later releases to the existing Mahara local plugin rather than creating a second Mahara local plugin. Even though the two plugins are really completely unrelated.

But, the Moodle Plugin site only allows a plugin to have one source control URL. So, my plan was:

  1. Hugh forks from the old local plugin repo
  2. I fork from Hugh's repo into a new local plugin repo in the MaharaProject github
  3. I set the MaharaProject local plugin repo (which now contains source code for the old local plugin and the new one) as the source control for the local plugin, in the Moodle Plugin site.

We will just have to make sure that if you're updating directly from Moodle 2.5 -> 2.8, the old local plugin gets properly done away with.

@agwells
Copy link

agwells commented Nov 12, 2015

But you're probably right that it should be on a different branch in the repo. :)

@kabalin
Copy link

kabalin commented Nov 12, 2015

Can we avoid local plugin completely? Either by making the change into Moodle core and releasing the feature with corresponding plugin version update (along with Moodle version release), or by reimplementing the same change in the moodle-assignsubmission_mahara?

@agwells
Copy link

agwells commented Nov 12, 2015

The problem Hugh ran into, is that Moodle's code for allowing a plugin to publish an MNet function, does not support "subplugins" like assign/submission. It only works correctly for top-level plugin types. So, bringing the "local" plugin back to life seems like the best workaround for right now. Literally the only thing it does is publish the existence of that MNet function.

Hugh also experimented with inserting the necessary records directly into the appropriate Moodle tables, but he found that didn't work. Quoting him from an IRC discussion we had yesterday: "ok, can't be done with upgrade/install path, cos they are both called before the mnet function, and that does a require_once on mnet.php to load methodnames (so won't load it second time around), and if it isn't there, it disables that function"

Getting Moodle to upstream the patch would be ideal, but we're somewhat doubtful of whether they'll accept any new MNet-related patches, or of how quickly we'd be able to make that happen, or whether they'd be willing to backport it to the current stable versions of Moodle.

@kabalin
Copy link

kabalin commented Nov 12, 2015

I see, thanks for detailed answer. Ok, local plugin back to life then. And start rewriting plugin to use webservices instead of MNet, hehe :)

BTW, thanks for your work on this @hughdavenport!

@agwells
Copy link

agwells commented Nov 12, 2015

Indeed!

@agwells
Copy link

agwells commented Nov 16, 2015

This code change also requires a corresponding code change in Mahara (which I'm reviewing at the same time): https://reviews.mahara.org/#/c/5704/

@agwells
Copy link

agwells commented Nov 16, 2015

And here's the Moodle patch request: https://tracker.moodle.org/browse/MDL-52172

1. Have updated Mahara so that it signals that it respected
the "lock=false" param, by making the "accesskey" be null. So
I changed the corresponding code on the Moodle side to look
for that.

2. Renamed "get_view_url" to "mnetify_url" to make it clearer
what it does. Removed the code that generates the "gradebook"
URL with "&mnetviewid=X&assignment=X" and put it in view(),
since that's the only place that does that.

3. Updated the comments on the status constants to indicate
their dual usage in new & old Mahara interfaces. Updated status
usage so that if we never lock a Mahara page, we just leave
the status on "STATUS_SELECTED".
I'm the one who created these constants, and I'd nearly
forgotten what they were for! Renaming them to and
recommenting, to indicate that these represent our
current understanding of the page's status, with regards
to whether it's locked or unlocked.
Also make the local_mahara a required dependency,
and other miscellaneous cleanup
@agwells
Copy link

agwells commented Dec 7, 2015

Just an update on this one. It has passed testing, so I'll try to merge it in and clean up the documentation and all, in the next couple of days.

I would like to wait on publishing the new version until the Mahara patch for it gets released in the next Mahara minor release, though. So that we don't have to distribute a patch file with it, and complicate the README with patching instructions again.

https://reviews.mahara.org/#/c/5704/

The code in issue2-fix branch is meant to be 100% back-compatible with non-upgraded Mahara sites, though. In the case that it's interfacing with a non-upgraded site, it'll just fall back to using the old "mt=" access URLs. Likewise, the Mahara patch is 100% back-compatible with a non-upgraded Moodle assignment submission plugin.

In Hugh's original implementation, the Moodle & Mahara sides used somewhat indirect methods to determine whether they were dealing with an upgraded or non-upgraded site on the opposite end. I wound up rewriting that to instead include an "apilevel" parameter, which should also help make it easier to implement future changes to the API between these plugins.

agwells pushed a commit to MaharaProject/mahara that referenced this pull request Mar 6, 2016
Bug 1516823

The moodle plugin for mahara assignment submissions [1] had an issue [2]
where is the plugin was configured in non locking mode, multiple
submissions of the same view would result in only the latest submitted
link working.

This was due to the page getting locked then released, which resulted in
a new mt token, which made all the old ones not work. This patch changes
that by accepting a new parameter which checks whether you are locking
and if not, then don't generate and send a token back.

When viewing a view, check for the new parameter mnetviewid or mnetcollid
along with the parameter assignment. If these are present, then Mahara
sends an MNet request back to Moodle which tells Mahara whether the user
has the permission to view the page.

This requires an update to the Moodle plugin, which is sent for review
currently [3]. Mahara detects whether this plugin is upgraded and
publishing the new MNet function. If it isn't, it falls back to original
behaviour gracefully. This is done by attempting to send a MNet request.

[1] https://github.com/MaharaProject/moodle-assignsubmission_mahara
[2] MaharaProject/moodle-assignsubmission_mahara#2
[3] MaharaProject/moodle-assignsubmission_mahara#19

behatnotneeded: Can't yet test MNet issues in Behat

Change-Id: I80739181b58bf7cf9c326e7b0a588b6239f864f1
@agwells
Copy link

agwells commented Jun 16, 2016

Oh dear, I never got around to merging this one! Well, no time like the present I guess.

@agwells
Copy link

agwells commented Jun 16, 2016

Hm, shoot, the Moodle compatibility patch (https://tracker.moodle.org/browse/MDL-52172) still hasn't been merged yet. Well, I'll have to give this some more thought then. :( I really don't want to have to go back to bundling a local plugin again, or requiring a patch. Maybe I can get some traction on the Moodle bug.

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

Successfully merging this pull request may close these issues.

Multiple submissions of the same page to different assignments breaks previous assignments' access
3 participants