Skip to content

Commit c056499

Browse files
committed
Allow sharing options for the documents inside a group BT#10769
//ALTER TABLE c_group_info ADD document_access INT DEFAULT 0 NOT NULL; //$_configuration['group_document_access'] = false;
1 parent 9bbf9e2 commit c056499

File tree

9 files changed

+100
-5
lines changed

9 files changed

+100
-5
lines changed

main/document/document.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,11 @@
198198
$groupMemberWithUploadRights = true;
199199
}
200200
}
201+
202+
// Group mode
203+
if (!GroupManager::allowUploadEditDocument($userId , $courseId, $group_properties)) {
204+
$groupMemberWithUploadRights = false;
205+
}
201206
Session::write('group_member_with_upload_rights', $groupMemberWithUploadRights);
202207
} else {
203208
Session::write('group_member_with_upload_rights', false);

main/document/edit_document.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@
6161

6262
if (api_is_in_group()) {
6363
$group_properties = GroupManager::get_group_properties($group_id);
64+
65+
GroupManager::allowUploadEditDocument(api_get_user_id() , api_get_course_int_id(), $group_properties, true);
6466
}
6567

6668
$dir = '/';

main/document/upload.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ function setFocus() {
120120
} else {
121121
api_not_allowed(true);
122122
}
123+
124+
GroupManager::allowUploadEditDocument(api_get_user_id() , api_get_course_int_id(), $group_properties, true);
123125
} elseif ($is_allowed_to_edit ||
124126
DocumentManager::is_my_shared_folder(api_get_user_id(), $path, api_get_session_id())) {
125127
} else {

main/group/settings.php

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,39 @@
103103
false
104104
);
105105

106+
$allowDocumentGroupAccess = api_get_configuration_value('group_document_access');
107+
if ($allowDocumentGroupAccess) {
108+
$group = [
109+
$form->createElement(
110+
'radio',
111+
'document_access',
112+
get_lang('GroupDocument'),
113+
get_lang('DocumentGroupCollaborationMode'),
114+
0
115+
),
116+
$form->createElement('radio', 'document_access', null, get_lang('DocumentGroupReadOnlyMode'), 1),
117+
];
118+
$form->addGroup(
119+
$group,
120+
'',
121+
Display::return_icon(
122+
'folder.png',
123+
get_lang('GroupDocumentAccess')
124+
).'<span>'.get_lang('GroupDocumentAccess').'</span>',
125+
null,
126+
false
127+
);
128+
}
129+
106130
// Work settings
107131
$group = [
108-
$form->createElement('radio', 'work_state', get_lang('GroupWork'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE),
132+
$form->createElement(
133+
'radio',
134+
'work_state',
135+
get_lang('GroupWork'),
136+
get_lang('NotAvailable'),
137+
GroupManager::TOOL_NOT_AVAILABLE
138+
),
109139
$form->createElement('radio', 'work_state', null, get_lang('Public'), GroupManager::TOOL_PUBLIC),
110140
$form->createElement('radio', 'work_state', null, get_lang('Private'), GroupManager::TOOL_PRIVATE),
111141
];
@@ -221,7 +251,8 @@
221251
$values['chat_state'],
222252
$self_registration_allowed,
223253
$self_unregistration_allowed,
224-
$categoryId
254+
$categoryId,
255+
isset($values['document_access']) ? $values['document_access'] : 0
225256
);
226257
if (isset($_POST['group_members']) &&
227258
count($_POST['group_members']) > $max_member &&
@@ -256,7 +287,7 @@
256287
echo '<br/>'.get_lang('SearchResultsFor').' <span style="font-style: italic ;"> '.$keyword_name.' </span><br>';
257288
}
258289

259-
Display :: display_header($nameTools, 'Group');
290+
Display::display_header($nameTools, 'Group');
260291

261292
$form->setDefaults($defaults);
262293
echo GroupManager::getSettingBar('settings');

main/inc/ajax/document.ajax.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@
4040
$groupInfo = GroupManager::get_group_properties(api_get_group_id());
4141
// Only course admin or group members allowed
4242
if ($is_allowed_to_edit || GroupManager::is_user_in_group(api_get_user_id(), $groupInfo)) {
43+
if (!GroupManager::allowUploadEditDocument(api_get_user_id() , api_get_course_int_id(), $groupInfo)) {
44+
exit;
45+
}
4346
} else {
4447
exit;
4548
}

main/inc/lib/course.lib.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5567,7 +5567,8 @@ public static function getCourseSettingVariables(AppPlugin $appPlugin)
55675567
'email_to_teachers_on_new_work_feedback',
55685568
];
55695569

5570-
if (!empty(ExerciseLib::getScoreModels())) {
5570+
$courseModels = ExerciseLib::getScoreModels();
5571+
if (!empty($courseModels)) {
55715572
$courseSettings[] = 'score_model_id';
55725573
}
55735574

main/inc/lib/groupmanager.lib.php

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,7 @@ public static function get_group_properties($group_id, $useIid = false)
531531
self::get_subscribed_tutors($result)
532532
);
533533
$result['count_all'] = $result['count_users'] + $result['count_tutor'];
534+
$result['document_access'] = isset($db_object->document_access) ? $db_object->document_access : 0;
534535
}
535536

536537
return $result;
@@ -620,6 +621,7 @@ public static function getGroupListFilterByName($name, $categoryId, $courseId)
620621
* @param bool Whether self registration is allowed or not
621622
* @param bool Whether self unregistration is allowed or not
622623
* @param int $categoryId
624+
* @param int $documentAccess
623625
*
624626
* @return bool TRUE if properties are successfully changed, false otherwise
625627
*/
@@ -637,14 +639,22 @@ public static function set_group_properties(
637639
$chat_state,
638640
$self_registration_allowed,
639641
$self_unregistration_allowed,
640-
$categoryId = null
642+
$categoryId = null,
643+
$documentAccess = 0
641644
) {
642645
$table_group = Database::get_course_table(TABLE_GROUP);
643646
$table_forum = Database::get_course_table(TABLE_FORUM);
644647
$categoryId = intval($categoryId);
645648
$group_id = intval($group_id);
646649
$course_id = api_get_course_int_id();
647650

651+
$allowDocumentAccess = api_get_configuration_value('group_document_access');
652+
$documentCondition = '';
653+
if ($allowDocumentAccess) {
654+
$documentAccess = (int) $documentAccess;
655+
$documentCondition = " document_access = $documentAccess, ";
656+
}
657+
648658
$sql = "UPDATE ".$table_group." SET
649659
name='".Database::escape_string(trim($name))."',
650660
doc_state = '".Database::escape_string($doc_state)."',
@@ -658,10 +668,12 @@ public static function set_group_properties(
658668
max_student = '".Database::escape_string($maximum_number_of_students)."',
659669
self_registration_allowed = '".Database::escape_string($self_registration_allowed)."',
660670
self_unregistration_allowed = '".Database::escape_string($self_unregistration_allowed)."',
671+
$documentCondition
661672
category_id = ".intval($categoryId)."
662673
WHERE c_id = $course_id AND id=".$group_id;
663674
$result = Database::query($sql);
664675

676+
665677
/* Here we are updating a field in the table forum_forum that perhaps
666678
duplicates the table group_info.forum_state cvargas*/
667679
$forum_state = (int) $forum_state;
@@ -2955,4 +2967,32 @@ public static function setInvisible($groupId)
29552967
{
29562968
self::setStatus($groupId, 0);
29572969
}
2970+
2971+
/**
2972+
* @param int $userId
2973+
* @param int $courseId
2974+
* @param array $groupInfo
2975+
* @param bool $blockPage
2976+
*/
2977+
public static function allowUploadEditDocument($userId, $courseId, $groupInfo, $blockPage = false)
2978+
{
2979+
$allow = api_get_configuration_value('group_document_access');
2980+
if (!$allow) {
2981+
return true;
2982+
}
2983+
2984+
if (isset($groupInfo['document_access']) &&
2985+
$groupInfo['document_access'] == 1 &&
2986+
(!api_is_allowed_to_edit() ||
2987+
(!api_is_allowed_to_edit() && !GroupManager::is_tutor_of_group($userId, $groupInfo, $courseId))
2988+
)
2989+
) {
2990+
if ($blockPage) {
2991+
api_not_allowed(true);
2992+
}
2993+
return false;
2994+
}
2995+
2996+
return true;
2997+
}
29582998
}

main/install/configuration.dist.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,10 @@
815815
// Allow teachers to access student skills BT#14161 (skills setting must be enabled in the platform)
816816
//$_configuration['allow_teacher_access_student_skills'] = false;
817817

818+
// Allow sharing options for the documents inside a group
819+
//ALTER TABLE c_group_info ADD document_access INT DEFAULT 0 NOT NULL;
820+
//$_configuration['group_document_access'] = false;
821+
818822
// ------ Custom DB changes (keep this at the end)
819823
// Add user activation by confirmation email
820824
// This option prevents the new user to login in the platform if your account is not confirmed via email

src/Chamilo/CourseBundle/Entity/CGroupInfo.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,13 @@ class CGroupInfo
154154
*/
155155
private $sessionId;
156156

157+
/**
158+
* @var int needed for setting $_configuration['group_document_access']
159+
*
160+
* ORM\Column(name="doc_access", type="integer", nullable=false, options={"default":0})
161+
*/
162+
//private $docAccess;
163+
157164
/**
158165
* Set name.
159166
*

0 commit comments

Comments
 (0)