forked from code-dot-org/code-dot-org
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshowProjectAdmin.js
More file actions
145 lines (138 loc) · 4.57 KB
/
Copy pathshowProjectAdmin.js
File metadata and controls
145 lines (138 loc) · 4.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import $ from 'jquery';
/**
* Dynamic generation and event bindings for project admin section of the admin box
* @param {project.js} project
*/
export default project => {
if ($('.project_admin').length) {
if (project.isProjectLevel() && project.isOwner()) {
if (project.isFrozen()) {
$('.project_admin').html(
$(
'<span>❄ Frozen! To use as an example, copy this id: <input type="text" disabled value="' +
project.getCurrentId() +
'"/><div><button id="unfreeze" class="btn btn-default btn-sm">Unfreeze</button><div></span>'
)
);
$('#unfreeze').click(function () {
project.unfreeze(function () {
window.location.reload();
});
});
} else {
$('.project_admin').html(
$(
'<button id="freeze" class="btn btn-default btn-sm">Freeze for use as an exemplar ❄</button>'
)
);
$('#freeze').click(function () {
project.freeze(function () {
window.location.reload();
});
});
}
}
}
if (!project.isPublished()) {
$('#unpublished_warning').show();
}
if ($('#feature_project').length && project.isProjectLevel()) {
$('#feature_project').click(function () {
var url = `/featured_projects/${project.getCurrentId()}/feature`;
$.ajax({
url: url,
type: 'PUT',
dataType: 'json',
success: function (data) {
$('#unfeature_project').show();
$('#feature_project').hide();
},
error: function (data) {
alert("Shucks. Something went wrong - this project wasn't featured.");
},
});
});
$('#unfeature_project').click(function () {
var url = `/featured_projects/${project.getCurrentId()}/unfeature`;
$.ajax({
url: url,
type: 'PUT',
dataType: 'json',
success: function (data) {
$('#unfeature_project').hide();
$('#feature_project').show();
},
error: function (data) {
alert(
'Shucks. Something went wrong - this project is still featured.'
);
},
});
});
}
if (
$('.admin-project-sharing').length &&
(project.isProjectLevel() || !project.shouldHideShareAndRemix())
) {
var sharingDisabled = project.getSharingDisabled();
var privateOrProfane = project.hasPrivacyProfanityViolation();
var abuseScore = project.getAbuseScore();
$('.admin-abuse-score').text(abuseScore);
$('#admin-abuse-reset').click(function () {
project.adminResetAbuseScore(0);
});
$('#admin-abuse-buffer').click(function () {
project.adminResetAbuseScore(-50);
});
var abusive = project.exceedsAbuseThreshold();
if (sharingDisabled || privateOrProfane || abusive) {
$('.blocked').show();
$('.blocked-reasons').show();
$('.unblocked').hide();
if (sharingDisabled) {
$('.admin-sharing').show();
}
if (privateOrProfane) {
$('.privacy-profanity').show();
var textViolationEnglish = project.privacyProfanityDetailsEnglish();
if (textViolationEnglish) {
$('.eng-flagged-text').text(textViolationEnglish);
$('.privacy-profanity-details-english').show();
}
var textViolationsIntl = project.privacyProfanityDetailsIntl();
var secondLanguage = project.privacyProfanitySecondLanguage();
if (textViolationsIntl && secondLanguage) {
$('.intl-flagged-text').text(textViolationsIntl);
$('.intl-flagged-language').text(secondLanguage);
$('.privacy-profanity-details-intl').show();
}
}
if (abusive) {
// The image moderation service sets the abuse score to 15 to
// differentiate from manual reports.
if (abuseScore === 15) {
$('.abusive-image').show();
$('.image-mod-controls').show();
} else {
$('.reported-abuse').show();
}
}
} else {
$('.unblocked').show();
$('.blocked').hide();
$('.blocked-reasons').hide();
}
}
$('#disable-auto-moderation').click(async function () {
await project.disableAutoContentModeration();
$('#disable-auto-moderation').hide();
$('#moderation-explanation').hide();
$('#enable-auto-moderation').show();
});
$('#enable-auto-moderation').click(async function () {
await project.enableAutoContentModeration();
$('#disable-auto-moderation').show();
$('#moderation-explanation').show();
$('#enable-auto-moderation').hide();
});
};