Skip to content

Commit

Permalink
community/: Add a form for uploading google forms
Browse files Browse the repository at this point in the history
Not everyone, will be able to fill forms.
Only the logged in users will be able to
fill them and some of the forms, can only
be filled by developers or contributors
who are a part of more than one team.
At every step, the check is performed whether
the user is authenticated or not, to avoid
false form submissions.

Closes #265
  • Loading branch information
KVGarg committed Aug 5, 2019
1 parent a012693 commit 9e6eb58
Show file tree
Hide file tree
Showing 7 changed files with 306 additions and 13 deletions.
24 changes: 24 additions & 0 deletions community/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,27 @@ class JoinCommunityForm(forms.Form):
}
)
)


class CommunityGoogleForm(forms.Form):
user = forms.CharField(
max_length=50, label='GitHub Username',
widget=forms.TextInput(attrs={'autocomplete': 'off'})
)
title = forms.CharField(
max_length=100, label='Title',
widget=forms.TextInput(attrs={'autocomplete': 'off'})
)
description = forms.CharField(
max_length=1000, label='Form Description', required=False,
widget=forms.Textarea(attrs={'autocomplete': 'off'})
)
url = forms.URLField(
label='Google Form URL',
widget=forms.TextInput(attrs={'autocomplete': 'off'})
)
expiry_date = forms.DateTimeField(
label='Expiry date and time', required=False,
help_text='DateTime Format should be YYYY-MM-DD HH:MM:SS',
widget=forms.TextInput(attrs={'autocomplete': 'off'})
)
11 changes: 10 additions & 1 deletion community/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
get_org_name,
get_remote_url
)
from .forms import JoinCommunityForm
from .forms import JoinCommunityForm, CommunityGoogleForm
from data.models import Team
from gamification.models import Participant as GamificationParticipant
from meta_review.models import Participant as MetaReviewer
Expand Down Expand Up @@ -42,10 +42,19 @@ def initialize_org_context_details():
return org_details


def get_community_google_form_variables(context):
context['community_google_form'] = CommunityGoogleForm()
context['community_google_form_name'] = os.environ.get(
'OSFORMS_NETLIFY_FORM_NAME', None
)
return context


def get_header_and_footer(context):
context['isTravis'] = Travis.TRAVIS
context['travisLink'] = Travis.TRAVIS_BUILD_WEB_URL
context['org'] = initialize_org_context_details()
context = get_community_google_form_variables(context)
print('Running on Travis: {}, build link: {}'.format(context['isTravis'],
context['travisLink']
))
Expand Down
54 changes: 54 additions & 0 deletions static/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,46 @@ body {
justify-content: center;
}

.community-form {
position: fixed;
width: 70%;
min-width: 330px;
top: 15%;
left: 15%;
border-radius: 20px;
box-shadow: 0 -5px 15px black;
background-color: #edf5af;
padding: 20px;
height: 80%;
overflow-x: auto;
}

.community-form form {
padding-bottom: inherit;

}
.community-form form label {
font-weight: bold;
font-size: 1.5rem;
color: darkcyan;
}

.community-form form p{
margin: 0;
}

.community-form form textarea{
margin-top: 10px;
}

.community-form form .row{
margin-bottom: 0;
}

.community-form ::placeholder {
color: black;
}

.evenly-spread-content {
justify-content: space-evenly;
}
Expand All @@ -53,6 +93,10 @@ body {
padding: 5px 10px;
}

.display-none {
display: none;
}

.form-popup,
.form-submission-popup {
width: 100%;
Expand Down Expand Up @@ -221,6 +265,10 @@ strong {
list-style: none;
}

.text-center {
text-align: center;
}

#user-dropdown li.user-logout {
display: none;
}
Expand Down Expand Up @@ -248,3 +296,9 @@ strong {
margin: 0;
}
}

@media only screen and (max-width: 400px) {
.community-form {
left: 10px;
}
}
101 changes: 101 additions & 0 deletions static/js/forms.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/* globals Cookies */
$(document).ready(function () {

var community_google_form_op = $('.community-google-form-op');
var newcomer_promotion_form_op = $('.newcomer-promotion-form-op');
var calendar_event_form_op = $('.calendar-event-form-op');
var get_issue_assigned_form_op = $('.get-issue-assigned-form-op');
var participated_in_gsoc_form_op = $('.participated-in-gsoc-form-op');
var mentor_students_form_op = $('.mentor-students-form-op');

var community_google_form = $('.community-google-form');
var newcomer_promotion_form = $('.newcomer-promotion-form');
var calendar_event_form = $('.calendar-event-form');
var get_issue_assigned_form = $('.get-issue-assigned-form');
var participated_in_gsoc_form = $('.participated-in-gsoc-form');
var mentor_students_form = $('.mentor-students-form');

var is_user_authenticated = Cookies.get('authenticated');
var authenticated_username = Cookies.get('username');

var username_input = $('[name=user]');
username_input.attr('value', authenticated_username || 'Anonymous User');
username_input.attr('disabled', true);

$('form').attr(
'action',window.location.pathname +
'?form_submitted=True&form_type=community'
);

$.getJSON("/static/contributors-data.json", function (data) {
var contributor_data = data[authenticated_username];
var teams = contributor_data.teams;
if(teams.length === 1){
community_google_form_op.get(0).remove();
calendar_event_form_op.get(0).remove();
mentor_students_form_op.get(0).remove();
community_google_form.get(0).remove();
calendar_event_form.get(0).remove();
mentor_students_form.get(0).remove();
}
});

function display_error_message(message){
if(message){
$('.important-message').text(message);
}
else {
$('.important-message').text('You tried to open a form, which is ' +
'available to only authenticated users. Please join the community' +
' or Login(if already a member of organization)');
}
$('.form-submission-popup').css('display', 'flex');
}

function display_form_or_error(form_object){
if(is_user_authenticated && authenticated_username){
$('.community-form').css('display', 'flex');
form_object.css('display', 'block');
}
else {
display_error_message();
}
}

community_google_form_op.on('click', function () {
display_form_or_error(community_google_form);
});

newcomer_promotion_form_op.on('click', function () {
display_form_or_error(newcomer_promotion_form);
});

calendar_event_form_op.on('click', function () {
display_form_or_error(calendar_event_form);
});

get_issue_assigned_form_op.on('click', function () {
display_form_or_error(get_issue_assigned_form);
});

participated_in_gsoc_form_op.on('click', function () {
display_form_or_error(participated_in_gsoc_form);
});

mentor_students_form_op.on('click', function () {
display_form_or_error(mentor_students_form);
});

$(':input').focusin(function () {
if (is_user_authenticated===undefined &&
authenticated_username===undefined) {
$('.community-form').css('display', 'none');
display_error_message();
}
});

$('.user_disabled_input').focusin(function () {
display_error_message('Sorry! But you are not allowed to change this' +
' field value.');
});
});
28 changes: 24 additions & 4 deletions static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,24 @@ $(document).ready(function(){

var urlParams = new URLSearchParams(location.search);
var formSubmitted = urlParams.get('form_submitted');
var formType = urlParams.get('form_type');

if(formSubmitted==='True'){
var message = '';
if(formType==='login'){
message = 'You request to join community, form has been' +
' submitted! You will receive an invite email within 24hrs, if' +
' all the validation checks are passed. Else, you will receive' +
' an email with the information regarding what all checks got' +
' failed!';
}
else if(formType==='community'){
message = 'Your request has been received and will be soon' +
' processed. You will receive an email notifying you whether' +
' the validation checks are passed or not. If not, the email' +
' will contain the validation errors. Correct them, if any';
}
$('.important-message').text(message);
$('.form-submission-popup').css('display', 'block');
}

Expand All @@ -23,7 +40,7 @@ $(document).ready(function(){

function check_user_authenticated_or_not() {
if(Cookies.get('authenticated')){
modify_html_elements('none', 'none', 'block');
modify_html_elements('none', 'none','block', 'block');
}
}

Expand All @@ -38,10 +55,12 @@ $(document).ready(function(){
}

function modify_html_elements(popup_form_display, login_option_display,
logout__option_display) {
logout__option_display,
form_option_display) {
$('.form-popup').css('display', popup_form_display);
login_user_el.css('display', login_option_display);
logout_user_el.css('display', logout__option_display);
$('.forms-dropdown-option').css('display', form_option_display);
}

function manipulate_web_page_data(oauth_provider, http_response_text) {
Expand All @@ -50,7 +69,7 @@ $(document).ready(function(){
// Cookies expires in 3 days
Cookies.set('authenticated', true, {expires: 3});
Cookies.set('username', json_data.user, {expires: 3});
modify_html_elements('none', 'none', 'block');
modify_html_elements('none', 'none','block', 'block');
}
else {
display_error_message(oauth_provider, json_data.message);
Expand Down Expand Up @@ -108,12 +127,13 @@ $(document).ready(function(){
$('.form-popup').css('display', 'none');
$('.form-submission-popup').css('display', 'none');
$('.oauth-error').css('display', 'none');
$('.community-form').css('display', 'none');
});

logout_user_el.click(function () {
Cookies.remove('authenticated');
Cookies.remove('username');
modify_html_elements('none', 'block','none');
modify_html_elements('none', 'block','none', 'none');
});

$('.login-with-github').click(function(e) {
Expand Down
Loading

0 comments on commit 9e6eb58

Please sign in to comment.