Skip to content

Commit

Permalink
[frontend] remove social share feature (#933)
Browse files Browse the repository at this point in the history
* Remove share feature for social media

* Update minified files

* remove "method" field from auth_storage.

* Clean code
  • Loading branch information
Drumor committed Apr 6, 2023
1 parent c2f58fe commit ddb8ad1
Show file tree
Hide file tree
Showing 14 changed files with 17 additions and 179 deletions.
3 changes: 1 addition & 2 deletions inginious/frontend/flask/mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from inginious.frontend.pages.preferences.utils import PrefRedirectPage
from inginious.frontend.pages.utils import SignInPage, LogOutPage
from inginious.frontend.pages.register import RegistrationPage
from inginious.frontend.pages.social import AuthenticationPage, CallbackPage, SharePage
from inginious.frontend.pages.social import AuthenticationPage, CallbackPage
from inginious.frontend.pages.course_register import CourseRegisterPage
from inginious.frontend.pages.course import CoursePage
from inginious.frontend.pages.tasks import TaskPage, TaskPageStaticDownload
Expand Down Expand Up @@ -90,7 +90,6 @@ def init_flask_mapping(flask_app):
view_func=AuthenticationPage.as_view('authenticationpage'))
flask_app.add_url_rule('/<cookieless:sessionid>auth/callback/<auth_id>',
view_func=CallbackPage.as_view('callbackpage'))
flask_app.add_url_rule('/<cookieless:sessionid>auth/share/<auth_id>', view_func=SharePage.as_view('sharepage'))
flask_app.add_url_rule('/<cookieless:sessionid>pages/<pageid>', view_func=INGIniousStaticPage.as_view('staticpage'))
flask_app.add_url_rule('/<cookieless:sessionid>courselist', view_func=CourseListPage.as_view('courselistpage'))
flask_app.add_url_rule('/<cookieless:sessionid>mycourses', view_func=MyCoursesPage.as_view('mycoursespage'))
Expand Down
41 changes: 4 additions & 37 deletions inginious/frontend/pages/social.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ def process_signin(self,auth_id):

auth_storage = self.user_manager.session_auth_storage().setdefault(auth_id, {})
auth_storage["redir_url"] = flask.request.referrer or '/'
auth_storage["method"] = "signin"
auth_link = auth_method.get_auth_link(auth_storage)
return redirect(auth_link)

Expand All @@ -40,19 +39,10 @@ def process_callback(self, auth_id):

auth_storage = self.user_manager.session_auth_storage().setdefault(auth_id, {})
user = auth_method.callback(auth_storage)
if user and auth_storage.get("method", "") == "signin":
if not self.user_manager.bind_user(auth_id, user):
return redirect("/signin?binderror")
elif user and auth_storage.get("method", "") == "share":
submission = self.submission_manager.get_submission(auth_storage["submissionid"], True)
if submission:
course = self.course_factory.get_course(submission["courseid"])
task = course.get_task(submission["taskid"])
auth_method.share(auth_storage, course, task, submission, self.user_manager.session_language())
else:
raise NotFound(description=_("Submission doesn't exist."))
else:
if not user:
return redirect("/signin?callbackerror")
if not self.user_manager.bind_user(auth_id, user):
return redirect("/signin?binderror")

return redirect(auth_storage.get("redir_url", "/"))

Expand All @@ -62,27 +52,4 @@ def GET(self, auth_id):
return self.process_callback(auth_id)

def POST(self, auth_id):
return self.process_callback(auth_id)


class SharePage(INGIniousAuthPage):
def process_share(self, auth_id):
auth_method = self.user_manager.get_auth_method(auth_id)
if not auth_method:
raise NotFound(description=_("Auth method not found."))

auth_storage = self.user_manager.session_auth_storage().setdefault(auth_id, {})
auth_storage["redir_url"] = flask.request.referrer or '/'
auth_storage["method"] = "share"
auth_storage["submissionid"] = flask.request.args.get("submissionid", "") or flask.request.form.get("submissionid", "")
auth_link = auth_method.get_auth_link(auth_storage, True)
return redirect(auth_link)

def GET(self, auth_id):
if self.user_manager.session_cookieless():
return redirect("/auth/share/" + auth_id)

return self.process_share(auth_id)

def POST(self, auth_id):
return self.process_share(auth_id)
return self.process_callback(auth_id)
28 changes: 2 additions & 26 deletions inginious/frontend/plugins/auth/facebook_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class FacebookAuthMethod(AuthMethod):
"""
Facebook auth method
"""
def get_auth_link(self, auth_storage, share=False):
facebook = OAuth2Session(self._client_id, scope=scope + (["publish_actions"] if share else []), redirect_uri=flask.request.url_root + self._callback_page)
def get_auth_link(self, auth_storage):
facebook = OAuth2Session(self._client_id, scope=scope, redirect_uri=flask.request.url_root + self._callback_page)
facebook = facebook_compliance_fix(facebook)
authorization_url, state = facebook.authorization_url(authorization_base_url)
auth_storage["oauth_state"] = state
Expand All @@ -42,30 +42,6 @@ def callback(self, auth_storage):
except:
return None

def share(self, auth_storage, course, task, submission, language):
facebook = OAuth2Session(self._client_id, state=auth_storage["oauth_state"], redirect_uri=flask.request.url_root + self._callback_page)
if facebook:
r = facebook.post("https://graph.facebook.com/me/objects/website",
{
"object": json.dumps({
"og:title": _("INGInious | {course} - {task}").format(
course=course.get_name(language),
task=task.get_name(language)
),
"og:description": _("Check out INGInious course {course} and beat my score of {score}% on task {task} !").format(
course=course.get_name(language),
task=task.get_name(language),
score=submission["grade"]
),
"og:url": flask.request.url_root + "course/" + course.get_id() + "/" + task.get_id(),
"og:image": "http://www.inginious.org/assets/img/header.png"})
})
result = json.loads(r.content.decode('utf-8'))
return "id" in result

def allow_share(self):
return True

def get_id(self):
return self._id

Expand Down
8 changes: 1 addition & 7 deletions inginious/frontend/plugins/auth/github_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class GithubAuthMethod(AuthMethod):
"""
Github auth method
"""
def get_auth_link(self, auth_storage, share=False):
def get_auth_link(self, auth_storage):
github = OAuth2Session(self._client_id, scope=scope, redirect_uri=flask.request.url_root + self._callback_page)
authorization_url, state = github.authorization_url(authorization_base_url)
auth_storage["oauth_state"] = state
Expand All @@ -41,12 +41,6 @@ def callback(self, auth_storage):
except:
return None

def share(self, auth_storage, course, task, submission, language):
return False

def allow_share(self):
return False

def __init__(self, id, name, client_id, client_secret):
self._name = name
self._id = id
Expand Down
8 changes: 1 addition & 7 deletions inginious/frontend/plugins/auth/google_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class GoogleAuthMethod(AuthMethod):
Google auth method
"""

def get_auth_link(self, auth_storage, share=False):
def get_auth_link(self, auth_storage):
google = OAuth2Session(self._client_id, scope=scope, redirect_uri=flask.request.url_root + self._callback_page)
authorization_url, state = google.authorization_url(authorization_base_url, hd=self._domain)
auth_storage["oauth_state"] = state
Expand All @@ -47,12 +47,6 @@ def callback(self, auth_storage):
except Exception as e:
return None

def share(self, auth_storage, course, task, submission, language):
return redirect("https://plus.google.com/share?url=" + flask.request.url_root + "/course/" + course.get_id() + "/" + task.get_id())

def allow_share(self):
return True

def get_id(self):
return self._id

Expand Down
8 changes: 1 addition & 7 deletions inginious/frontend/plugins/auth/ldap_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,12 @@ def get_imlink(self):
else:
return '<i class="fa fa-address-book" style="font-size:50px; color:#000000;"></i>'

def get_auth_link(self, auth_storage, share=False):
def get_auth_link(self, auth_storage):
return "/auth/page/" + self._id

def callback(self, auth_storage):
return None

def share(self, auth_storage, course, task, submission, language):
return False

def allow_share(self):
return False

def get_settings(self):
return self._settings

Expand Down
10 changes: 2 additions & 8 deletions inginious/frontend/plugins/auth/linkedin_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class LinkedInAuthMethod(AuthMethod):
"""
LinkedIn auth method
"""
def get_auth_link(self, auth_storage, share=False):
linkedin = OAuth2Session(self._client_id, scope=scope + (["w_share"] if share else []), redirect_uri=flask.request.url_root + self._callback_page)
def get_auth_link(self, auth_storage):
linkedin = OAuth2Session(self._client_id, scope=scope, redirect_uri=flask.request.url_root + self._callback_page)
authorization_url, state = linkedin.authorization_url(authorization_base_url)
auth_storage["oauth_state"] = state
return authorization_url
Expand All @@ -45,12 +45,6 @@ def callback(self, auth_storage):
except Exception as e:
return None

def share(self, auth_storage, course, task, submission, language):
return False

def allow_share(self):
return False

def get_id(self):
return self._id

Expand Down
8 changes: 1 addition & 7 deletions inginious/frontend/plugins/auth/saml2_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def get_imlink(self):
else:
return '<i class="fa fa-id-card" style="font-size:50px; color:#000000;"></i>'

def get_auth_link(self, auth_storage, share=False):
def get_auth_link(self, auth_storage):
auth = OneLogin_Saml2_Auth(prepare_request(self._settings), self._settings)
return auth.login(json.dumps(auth_storage))

Expand Down Expand Up @@ -124,12 +124,6 @@ def callback(self, auth_storage):
", ".join(errors))
return None

def share(self, auth_storage, course, task, submission, language):
return False

def allow_share(self):
return False

def get_settings(self):
return self._settings

Expand Down
22 changes: 2 additions & 20 deletions inginious/frontend/plugins/auth/twitter_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class TwitterAuthMethod(AuthMethod):
"""
Twitter auth method
"""
def get_auth_link(self, auth_storage, share=False):
client_id = self._share_client_id if share else self._client_id
def get_auth_link(self, auth_storage):
client_id = self._client_id
client_secret = self._clients[client_id]
twitter = OAuth1Session(client_id, client_secret=client_secret,
callback_uri=flask.request.url_root + self._callback_page)
Expand All @@ -47,24 +47,6 @@ def callback(self, auth_storage):
except:
return None

def share(self, auth_storage, course, task, submission, language):
twitter = auth_storage.get("session", None)
if twitter:
r = twitter.post(
"https://api.twitter.com/1.1/statuses/update.json",
{"status": _("Check out INGInious course {course} and beat my score of {score}% on task {task} !").format(
course=course.get_name(language),
task=task.get_name(language),
score=submission["grade"]
) + " " + flask.request.url_root + "course/" + course.get_id() + "/" + task.get_id() + " #inginious" + ((" via @" + self._twitter_user) if self._twitter_user else "")
}
)
result = json.loads(r.content.decode('utf-8'))
return "id" in result

def allow_share(self):
return True

def get_id(self):
return self._id

Expand Down
2 changes: 1 addition & 1 deletion inginious/frontend/static/js/all-minified-rtl.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion inginious/frontend/static/js/all-minified.js

Large diffs are not rendered by default.

9 changes: 0 additions & 9 deletions inginious/frontend/static/js/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ function displayEvaluatedSubmission(id, fade) {
$("#my_submission").replaceWith(submission_link);
}

$("#share_my_submission").removeClass("hidden");
}

updateTaskStatus(item.hasClass("list-group-item-success") ? "Succeeded" : "Failed", parseFloat(item.text().split("-")[1]));
Expand Down Expand Up @@ -800,14 +799,6 @@ function load_input_match(submissionid, key, input) {
$(field).prop('value', "");
}

// Share eval submission result on social networks
function share_submission(method_id)
{
var submissionid = $('#my_submission').attr('data-submission-id');
window.location.replace("/auth/share/" + method_id + "?submissionid=" + submissionid)

}

/*
* Update tags visual of HTML nodes that represent tags.
* The choice of the color depends of data present in data["tests"]
Expand Down
32 changes: 0 additions & 32 deletions inginious/frontend/templates/task.html
Original file line number Diff line number Diff line change
Expand Up @@ -190,20 +190,6 @@ <h3> {{ _("For evaluation") }}</h3>
{% else %}
<div id="my_submission" class="list-group-item list-group-item-info"><i class="fa fa-chevron-right fa-fw"></i> {{ _("No submission") }}</div>
{% endif %}

{% set ns = namespace(disp_share=False) %}
{% for key, method in user_manager.get_auth_methods().items() %}
{% if method.allow_share() %}
{% set ns.disp_share = True %}
{% endif %}
{% endfor %}

{% if ns.disp_share %}
<a id="share_my_submission" href="#" class="list-group-item list-group-item-action list-group-item-info {{ 'hidden' if not eval_submission else '' }}" data-toggle='modal' data-target='#share'>
<i class="fa fa-share-alt fa-fw"></i>
{{ _("Share my result") }}
</a>
{% endif %}
</div>

<h3>{{ _("Submission history") }}</h3>
Expand Down Expand Up @@ -438,24 +424,6 @@ <h5 class="card-header">
<!-- Modals -->
{% set auth_methods = user_manager.get_auth_methods() %}

<div class="modal fade" id="share" tabindex="-1" role="dialog" aria-labelledby="socialModalLabel">
<div class="modal-dialog modal-sm" role="document">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="socialModalLabel">{{ _("Share my result on: ") }}</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
</div>
<div class="modal-body">
{% for key, method in auth_methods.items() %}
{% if method.allow_share() %}
<a href="#" onclick="share_submission('{{ method.get_id() }}')" class="btn btn-block btn-default">{{ method.get_name() }}</a>
{% endif %}
{% endfor %}
</div>
</div>
</div>
</div>

<script type="text/javascript">
var problems_types = {{ pdict | safe }};
var is_input_list = {{ is_input_list | safe }};
Expand Down
15 changes: 0 additions & 15 deletions inginious/frontend/user_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,6 @@ def callback(self, auth_storage):
"""
return None

@abstractmethod
def share(self, auth_storage, course, task, submission, language):
"""
:param auth_storage: The session auth method storage dict
:return: False if error
"""
return False

@abstractmethod
def allow_share(self):
"""
:return: True if the auth method allow sharing, else false
"""
return False

@abstractmethod
def get_name(self):
"""
Expand Down

0 comments on commit ddb8ad1

Please sign in to comment.