Skip to content

Commit 5584daf

Browse files
committed
community/: Add a form for uploading google forms
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
1 parent 29b7600 commit 5584daf

File tree

7 files changed

+306
-12
lines changed

7 files changed

+306
-12
lines changed

community/forms.py

+24
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,27 @@ class JoinCommunityForm(forms.Form):
8080
}
8181
)
8282
)
83+
84+
85+
class CommunityGoogleForm(forms.Form):
86+
user = forms.CharField(
87+
max_length=50, label='GitHub Username',
88+
widget=forms.TextInput(attrs={'autocomplete': 'off'})
89+
)
90+
title = forms.CharField(
91+
max_length=100, label='Title',
92+
widget=forms.TextInput(attrs={'autocomplete': 'off'})
93+
)
94+
description = forms.CharField(
95+
max_length=1000, label='Form Description', required=False,
96+
widget=forms.Textarea(attrs={'autocomplete': 'off'})
97+
)
98+
url = forms.URLField(
99+
label='Google Form URL',
100+
widget=forms.TextInput(attrs={'autocomplete': 'off'})
101+
)
102+
expiry_date = forms.DateTimeField(
103+
label='Expiry date and time', required=False,
104+
help_text='DateTime Format should be YYYY-MM-DD HH:MM:SS',
105+
widget=forms.TextInput(attrs={'autocomplete': 'off'})
106+
)

community/views.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
get_org_name,
1313
get_remote_url
1414
)
15-
from .forms import JoinCommunityForm
15+
from .forms import JoinCommunityForm, CommunityGoogleForm
1616
from data.models import Team
1717
from gamification.models import Participant as GamificationParticipant
1818
from meta_review.models import Participant as MetaReviewer
@@ -42,10 +42,19 @@ def initialize_org_context_details():
4242
return org_details
4343

4444

45+
def get_community_google_form_variables(context):
46+
context['community_google_form'] = CommunityGoogleForm()
47+
context['community_google_form_name'] = os.environ.get(
48+
'OSFORMS_NETLIFY_FORM_NAME', None
49+
)
50+
return context
51+
52+
4553
def get_header_and_footer(context):
4654
context['isTravis'] = Travis.TRAVIS
4755
context['travisLink'] = Travis.TRAVIS_BUILD_WEB_URL
4856
context['org'] = initialize_org_context_details()
57+
context = get_community_google_form_variables(context)
4958
print('Running on Travis: {}, build link: {}'.format(context['isTravis'],
5059
context['travisLink']
5160
))

static/css/main.css

+54
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,46 @@ body {
3838
justify-content: center;
3939
}
4040

41+
.community-form {
42+
position: absolute;
43+
width: 70%;
44+
min-width: 330px;
45+
top: 15%;
46+
left: 15%;
47+
border-radius: 20px;
48+
box-shadow: 0 -5px 15px black;
49+
background-color: #edf5af;
50+
padding: 20px;
51+
height: 80%;
52+
overflow-x: auto;
53+
}
54+
55+
.community-form form {
56+
padding-bottom: inherit;
57+
58+
}
59+
.community-form form label {
60+
font-weight: bold;
61+
font-size: 1.5rem;
62+
color: darkcyan;
63+
}
64+
65+
.community-form form p{
66+
margin: 0;
67+
}
68+
69+
.community-form form textarea{
70+
margin-top: 10px;
71+
}
72+
73+
.community-form form .row{
74+
margin-bottom: 0;
75+
}
76+
77+
.community-form ::placeholder {
78+
color: black;
79+
}
80+
4181
.evenly-spread-content {
4282
justify-content: space-evenly;
4383
}
@@ -53,6 +93,10 @@ body {
5393
padding: 5px 10px;
5494
}
5595

96+
.display-none {
97+
display: none;
98+
}
99+
56100
.form-popup,
57101
.form-submission-popup {
58102
width: 100%;
@@ -220,6 +264,10 @@ strong {
220264
list-style: none;
221265
}
222266

267+
.text-center {
268+
text-align: center;
269+
}
270+
223271
#user-dropdown li.user-profile,
224272
#user-dropdown li.user-logout {
225273
display: none;
@@ -248,3 +296,9 @@ strong {
248296
margin: 0;
249297
}
250298
}
299+
300+
@media only screen and (max-width: 400px) {
301+
.community-form {
302+
left: 10px;
303+
}
304+
}

static/js/forms.js

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/* globals Cookies */
2+
$(document).ready(function () {
3+
4+
var community_google_form_op = $('.community-google-form-op');
5+
var newcomer_promotion_form_op = $('.newcomer-promotion-form-op');
6+
var calendar_event_form_op = $('.calendar-event-form-op');
7+
var get_issue_assigned_form_op = $('.get-issue-assigned-form-op');
8+
var participated_in_gsoc_form_op = $('.participated-in-gsoc-form-op');
9+
var mentor_students_form_op = $('.mentor-students-form-op');
10+
11+
var community_google_form = $('.community-google-form');
12+
var newcomer_promotion_form = $('.newcomer-promotion-form');
13+
var calendar_event_form = $('.calendar-event-form');
14+
var get_issue_assigned_form = $('.get-issue-assigned-form');
15+
var participated_in_gsoc_form = $('.participated-in-gsoc-form');
16+
var mentor_students_form = $('.mentor-students-form');
17+
18+
var is_user_authenticated = Cookies.get('authenticated');
19+
var authenticated_username = Cookies.get('username');
20+
21+
var username_input = $('[name=user]');
22+
username_input.attr('value', authenticated_username || 'Anonymous User');
23+
username_input.attr('disabled', true);
24+
25+
$('form').attr(
26+
'action',window.location.pathname +
27+
'?form_submitted=True&form_type=community'
28+
);
29+
30+
$.getJSON("/static/contributors-data.json", function (data) {
31+
var contributor_data = data[authenticated_username];
32+
var teams = contributor_data.teams;
33+
if(teams.length === 1){
34+
community_google_form_op.get(0).remove();
35+
calendar_event_form_op.get(0).remove();
36+
mentor_students_form_op.get(0).remove();
37+
community_google_form.get(0).remove();
38+
calendar_event_form.get(0).remove();
39+
mentor_students_form.get(0).remove();
40+
}
41+
});
42+
43+
function display_error_message(message){
44+
if(message){
45+
$('.important-message').text(message);
46+
}
47+
else {
48+
$('.important-message').text('You tried to open a form, which is ' +
49+
'available to only authenticated users. Please join the community' +
50+
' or Login(if already a member of organization)');
51+
}
52+
$('.form-submission-popup').css('display', 'block');
53+
}
54+
55+
function display_form_or_error(form_object){
56+
if(is_user_authenticated && authenticated_username){
57+
$('.community-form').css('display', 'block');
58+
form_object.css('display', 'block');
59+
}
60+
else {
61+
display_error_message();
62+
}
63+
}
64+
65+
community_google_form_op.on('click', function () {
66+
display_form_or_error(community_google_form);
67+
});
68+
69+
newcomer_promotion_form_op.on('click', function () {
70+
display_form_or_error(newcomer_promotion_form);
71+
});
72+
73+
calendar_event_form_op.on('click', function () {
74+
display_form_or_error(calendar_event_form);
75+
});
76+
77+
get_issue_assigned_form_op.on('click', function () {
78+
display_form_or_error(get_issue_assigned_form);
79+
});
80+
81+
participated_in_gsoc_form_op.on('click', function () {
82+
display_form_or_error(participated_in_gsoc_form);
83+
});
84+
85+
mentor_students_form_op.on('click', function () {
86+
display_form_or_error(mentor_students_form);
87+
});
88+
89+
$(':input').focusin(function () {
90+
if (is_user_authenticated===undefined &&
91+
authenticated_username===undefined) {
92+
$('.community-form').css('display', 'none');
93+
display_error_message();
94+
}
95+
});
96+
97+
$('.user_disabled_input').focusin(function () {
98+
display_error_message('Sorry! But you are not allowed to change this' +
99+
' field value.');
100+
});
101+
});

static/js/main.js

+23-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,23 @@ $(document).ready(function(){
66

77
var urlParams = new URLSearchParams(location.search);
88
var formSubmitted = urlParams.get('form_submitted');
9+
var formType = urlParams.get('form_type');
910
if(formSubmitted==='True'){
11+
var message = '';
12+
if(formType==='login'){
13+
message = 'You request to join community, form has been' +
14+
' submitted! You will receive an invite email within 24hrs, if' +
15+
' all the validation checks are passed. Else, you will receive' +
16+
' an email with the information regarding what all checks got' +
17+
' failed!';
18+
}
19+
else if(formType==='community'){
20+
message = 'Your request has been received and will be soon' +
21+
' processed. You will receive an email notifying you whether' +
22+
' the validation checks are passed or not. If not, the email' +
23+
' will contain the validation errors. Correct them, if any';
24+
}
25+
$('.important-message').text(message);
1026
$('.form-submission-popup').css('display', 'block');
1127
}
1228

@@ -23,7 +39,7 @@ $(document).ready(function(){
2339

2440
function check_user_authenticated_or_not() {
2541
if(Cookies.get('authenticated')){
26-
modify_html_elements('none', 'none','block', 'block');
42+
modify_html_elements('none', 'none','block', 'block', 'block');
2743
}
2844
}
2945

@@ -39,11 +55,13 @@ $(document).ready(function(){
3955

4056
function modify_html_elements(popup_form_display, login_option_display,
4157
profile_option_display,
42-
logout__option_display) {
58+
logout__option_display,
59+
form_option_display) {
4360
$('.form-popup').css('display', popup_form_display);
4461
login_user_el.css('display', login_option_display);
4562
$('.user-profile').css('display', profile_option_display);
4663
logout_user_el.css('display', logout__option_display);
64+
$('.forms-dropdown-option').css('display', form_option_display);
4765
}
4866

4967
function manipulate_web_page_data(oauth_provider, http_response_text) {
@@ -52,7 +70,7 @@ $(document).ready(function(){
5270
// Cookies expires in 3 days
5371
Cookies.set('authenticated', true, {expires: 3});
5472
Cookies.set('username', json_data.user, {expires: 3});
55-
modify_html_elements('none', 'none','block', 'block');
73+
modify_html_elements('none', 'none','block', 'block', 'block');
5674
}
5775
else {
5876
display_error_message(oauth_provider, json_data.message);
@@ -110,12 +128,13 @@ $(document).ready(function(){
110128
$('.form-popup').css('display', 'none');
111129
$('.form-submission-popup').css('display', 'none');
112130
$('.oauth-error').css('display', 'none');
131+
$('.community-form').css('display', 'none');
113132
});
114133

115134
logout_user_el.click(function () {
116135
Cookies.remove('authenticated');
117136
Cookies.remove('username');
118-
modify_html_elements('none', 'block','none', 'none');
137+
modify_html_elements('none', 'block','none', 'none', 'none');
119138
});
120139

121140
$('.login-with-github').click(function(e) {

0 commit comments

Comments
 (0)