Skip to content

Rnd discourse#6151

Open
acshi wants to merge 90 commits intoCenterForOpenScience:developfrom
acshi:rnd-discourse
Open

Rnd discourse#6151
acshi wants to merge 90 commits intoCenterForOpenScience:developfrom
acshi:rnd-discourse

Conversation

@acshi
Copy link
Copy Markdown
Contributor

@acshi acshi commented Aug 12, 2016

Purpose

This PR is being made to link the ongoing Discourse Integration project code to the main OSF.

Changes

framework.discourse module for interaction. Discourse IDs and hooks added to project, file, and wiki node classes. Single-Sign-On for Discourse through the OSF. Completely different comment-pane. Forum-feed Mithril component. See the README.md file in framework/discourse for more.

Example screenshots:
discoursedemo1

discoursedemo2

Side effects

Replacing of standard comments with Discourse. Comments will work differently. The APIv2 comment functionality would be broken.

@brianjgeiger
Copy link
Copy Markdown
Collaborator

It's Autumn Cleaning time, so I'm closing this PR. Feel free to re-open when development becomes active again.

@acshi
Copy link
Copy Markdown
Contributor Author

acshi commented Oct 4, 2016

Hmmm... This was opened originally at Steve Loria's request so that my
personal branch would be tied to the COS. Also, it is under active
development! But I'm not sure if the PR needs to be open or if anything
else should be happening with that.

On Tue, Oct 4, 2016 at 9:59 AM, Brian J. Geiger notifications@github.com
wrote:

It's Autumn Cleaning time, so I'm closing this PR. Feel free to re-open
when development becomes active again.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_CenterForOpenScience_osf.io_pull_6151-23issuecomment-2D251395753&d=CwMCaQ&c=-dg2m7zWuuDZ0MUcV7Sdqw&r=7fC-iE5nc1K0x8FY3MV5uEZng4gqi25wl7nIyZPmvbE&m=sjWQ-KTVWMgR017nGuihAvuEdanv_eigVtYu_iQZgtM&s=YCf6WgGlbVweswNZcehKpOMreiPEVitwY_ZqXVFQ5qw&e=,
or mute the thread
https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_notifications_unsubscribe-2Dauth_ABYf9sYS-2DkKzakDkI9ZIEKqKONelNtqKks5qwluygaJpZM4JjUZZ&d=CwMCaQ&c=-dg2m7zWuuDZ0MUcV7Sdqw&r=7fC-iE5nc1K0x8FY3MV5uEZng4gqi25wl7nIyZPmvbE&m=sjWQ-KTVWMgR017nGuihAvuEdanv_eigVtYu_iQZgtM&s=evS5dueN9Mk-qJ3dp7dL-wjiDlK65mmuEXhxhv37x6E&e=
.

@brianjgeiger
Copy link
Copy Markdown
Collaborator

Cool. When you're ready to do another push, go ahead and re-open it then. For now, we should still have access to it for what we need. We just had a lot of open PRs that I was asked to clean out.

@brianjgeiger
Copy link
Copy Markdown
Collaborator

Ah, it was only 7 days since the last push. Okay, I'll re-open. From the way Github showed it, I thought it had been months.

Copy link
Copy Markdown
Contributor

@alexschiller alexschiller left a comment

Choose a reason for hiding this comment

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

Notes:
100 in line comments, some redundant pointing out similar problems. Consider questions to be hypothetical and not requiring answers, but you should probably know the answer. Happy to discuss any comments further if anything unclear.

General punchlist of common suggestions

  1. Fix import orders in all files
  2. Fix importing of symbols-- import modules and call module.symbol instead
  3. Add empty blank line to the ends of files
  4. Use dictionary literals instead of manually adding via dict[key] = value
  5. Use single quotes instead of double quotes
  6. When possible, handle errors inside of functions instead of catching output when the function output fails
  7. Don't use general try-except Exceptions, make sure you are handling only the exceptions you expect
  8. Use triple equals in javascript

General

  1. Some refactoring of functions can occur to simplify things-- some functions were only used once and can easily be made a single line. In those cases it is more readable not to have to look up what that function does.
  2. The difference between a node, filenode, wikinode, project, parent all need to match how things are done in the OSF. Some of your relationships uses were different than I expected.
  3. The mithril and javascript sections would benefit from a refactor. The python was generally easy to read but the javascript was not always.

Comment thread api/sso/__init__.py Outdated
@@ -0,0 +1,29 @@
from website import settings
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

See these for import ordering, this applies to all imports you modified/added in all files.
https://www.python.org/dev/peps/pep-0008/#imports / http://cosdev.readthedocs.io/en/latest/style_guides/python.html#imports

Comment thread api/sso/__init__.py Outdated
out_dict = {}
for k, v in in_dict.iteritems():
if isinstance(v, unicode):
v = v.encode('utf8')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Encode/decode is generally written as 'utf-8' in the osf instead of just 'utf8'-- both work though.

Comment thread framework/auth/__init__.py Outdated
"""Clear users' session(s) and log them out of OSF."""

for key in ['auth_user_username', 'auth_user_id', 'auth_user_fullname', 'auth_user_access_token']:
for key in ['auth_user_username', 'auth_user_id', 'auth_user_fullname',
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If you're going to split the line, each should probably go on its own line (see line 15 of same file)

Comment thread framework/auth/views.py Outdated
try:
discourse.logout()
except (discourse.DiscourseException, requests.exceptions.ConnectionError):
logger.exception('Error logging user out of Discourse')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hypothetical questions that I don't need answers to:

  1. What happens if the user is not logged out of discourse but is logged out of the osf?
  2. What happens when they try to log back in?
  3. Should logout fail (I doubt we should force someone to remain logged in, but the fact that this error catch needs to exist does raise a few questions)?

Comment thread framework/discourse/__init__.py Outdated
@@ -0,0 +1,7 @@
import framework.discourse.common
# import here so they can all be imported through the module
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It would be better if you pulled in discourse and simply called the function from where it actually lives. This is a lot of importing symbols when you should be keeping them name spaced better. There is a reason you had to noqa everything

e.g.,

from framework import discourse

discourse.project.sync_projects(...)

Comment thread website/templates/nav.mako Outdated
url: "${settings.DISCOURSE_SERVER_URL}/session/current.json",
xhrFields: { withCredentials: true }}
).then(function(json) {
if (json.current_user && json.current_user.username == contextVars.currentUser.id) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

use triple equals

Comment thread website/templates/nav.mako Outdated

function discourseAutoLogin() {
if (contextVars.currentUser.id) {
if (typeof(Storage) !== "undefined" && sessionStorage.discourseLoggedIn == "true") {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

use triple equals, single quotes

Comment thread website/templates/nav.mako Outdated
}
};

if (window.addEventListener) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is there a reason this cannot be run with the mithril controller is getting everything set up? I may be missing what it is supposed to be doing, but a lot of this looks like things that can be configured in the controller.

Comment thread website/templates/project/project.mako Outdated

<!-- Forum Feed (Latest Topics) -->
% if not node['anonymous']:
<div class="panel panel-default">
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

indent

Comment thread website/templates/project/project.mako Outdated
% if not node['anonymous']:
<div class="panel panel-default">
<div class="panel-heading clearfix">
<h3 class="panel-title">Latest Forum Topics</h3>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@acshi acshi force-pushed the rnd-discourse branch 2 times, most recently from bb37e0d to 8134590 Compare January 19, 2017 02:35
acshi added 18 commits March 21, 2017 21:49
…configure_discourse_server function was added as well, and may be used after the discourse settings are properly set in local settings.
…more data from the correct project and file nodes, and to add the discourse comment plugin to file pages, automatically making the correct groups, categories, and topics
…edded the discourse comments into the comments side panel
acshi added 22 commits March 21, 2017 21:54
…d a minimum number of times. Fixed the SSO get method signature. Added automatic configuration of the welcome-to-discourse topic contents
…ttempt to use it triggers an additional try. gave it a 0.25s timeout, since it should be local
…dpoint on Discourse for creating projects and dealing with them only by project_guid. fixed tests to make sure they all pass. added some documentation.
…kis, deleting projects/components, and made auto discourse log-in smarter
@brianjgeiger
Copy link
Copy Markdown
Collaborator

I'm trying to install this on my local setup (finally!), and when I invoke the server I'm getting:

  File "/Users/bgeiger/cos/osf/osf/models/user.py", line 368, in OSFUser
    discourse_apikey_date_created = NonNaiveDatetimeField(default=None, null=True, blank=True)
NameError: name 'NonNaiveDatetimeField' is not defined

I've invoked all the requirements that I could (using the -q flag). Is there anything that maybe isn't in a requirements file?

@acshi
Copy link
Copy Markdown
Contributor Author

acshi commented Apr 3, 2017

@brianjgeiger Sorry about the delay in a response. I think this must be from some recent change to the develop branch of osf.io. I recently did a rebase, but haven't gone through running all the code again. I am a little reluctant to, because my environment has diverged substantially since I can't run docker in the specified way. (I don't have a recent-year mac). By and large, I aimed to use the same conventions as the OSF already was. That specific datetime field type is not important as long as it is consistent.

@brianjgeiger
Copy link
Copy Markdown
Collaborator

This should definitely not try to be merged with develop. The branch itself should be, for the purposes of this review, its own island. If it's in a partway state, then I'm not going to be able to get it running. Can this be rolled back to a last-known working state?

@acshi
Copy link
Copy Markdown
Contributor Author

acshi commented Apr 7, 2017

Well, NonNaiveDatetimeField is actually just a typo. It should be NonNaiveDateTimeField.
For me to really be sure it is working on either an older rollback or this version might take a little (I'm not super familiar with undoing a rebase), so be patient with me as I try to find time to look more at this now.

@acshi
Copy link
Copy Markdown
Contributor Author

acshi commented Apr 7, 2017

@brianjgeiger I've fixed the typo and I can get it to run locally. However, the amount of testing I can do is limited right now since I'm having trouble being able to create an account on my new instance. I get the error: "Invalid Token This confirmation link is invalid." when trying to make a new account.

@brianjgeiger
Copy link
Copy Markdown
Collaborator

Cool, thanks! I'll pull and give it a go again.

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.

3 participants