Skip to content

Commit

Permalink
Allow sharing options for the documents inside a group BT#10769
Browse files Browse the repository at this point in the history
//ALTER TABLE c_group_info ADD document_access INT DEFAULT 0 NOT NULL;
//$_configuration['group_document_access'] = false;
  • Loading branch information
jmontoyaa committed Apr 18, 2018
1 parent 9bbf9e2 commit c056499
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 5 deletions.
5 changes: 5 additions & 0 deletions main/document/document.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,11 @@
$groupMemberWithUploadRights = true;
}
}

// Group mode
if (!GroupManager::allowUploadEditDocument($userId , $courseId, $group_properties)) {
$groupMemberWithUploadRights = false;
}
Session::write('group_member_with_upload_rights', $groupMemberWithUploadRights);
} else {
Session::write('group_member_with_upload_rights', false);
Expand Down
2 changes: 2 additions & 0 deletions main/document/edit_document.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@

if (api_is_in_group()) {
$group_properties = GroupManager::get_group_properties($group_id);

GroupManager::allowUploadEditDocument(api_get_user_id() , api_get_course_int_id(), $group_properties, true);
}

$dir = '/';
Expand Down
2 changes: 2 additions & 0 deletions main/document/upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ function setFocus() {
} else {
api_not_allowed(true);
}

GroupManager::allowUploadEditDocument(api_get_user_id() , api_get_course_int_id(), $group_properties, true);
} elseif ($is_allowed_to_edit ||
DocumentManager::is_my_shared_folder(api_get_user_id(), $path, api_get_session_id())) {
} else {
Expand Down
37 changes: 34 additions & 3 deletions main/group/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,39 @@
false
);

$allowDocumentGroupAccess = api_get_configuration_value('group_document_access');
if ($allowDocumentGroupAccess) {
$group = [
$form->createElement(
'radio',
'document_access',
get_lang('GroupDocument'),
get_lang('DocumentGroupCollaborationMode'),
0
),
$form->createElement('radio', 'document_access', null, get_lang('DocumentGroupReadOnlyMode'), 1),
];
$form->addGroup(
$group,
'',
Display::return_icon(
'folder.png',
get_lang('GroupDocumentAccess')
).'<span>'.get_lang('GroupDocumentAccess').'</span>',
null,
false
);
}

// Work settings
$group = [
$form->createElement('radio', 'work_state', get_lang('GroupWork'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE),
$form->createElement(
'radio',
'work_state',
get_lang('GroupWork'),
get_lang('NotAvailable'),
GroupManager::TOOL_NOT_AVAILABLE
),
$form->createElement('radio', 'work_state', null, get_lang('Public'), GroupManager::TOOL_PUBLIC),
$form->createElement('radio', 'work_state', null, get_lang('Private'), GroupManager::TOOL_PRIVATE),
];
Expand Down Expand Up @@ -221,7 +251,8 @@
$values['chat_state'],
$self_registration_allowed,
$self_unregistration_allowed,
$categoryId
$categoryId,
isset($values['document_access']) ? $values['document_access'] : 0
);
if (isset($_POST['group_members']) &&
count($_POST['group_members']) > $max_member &&
Expand Down Expand Up @@ -256,7 +287,7 @@
echo '<br/>'.get_lang('SearchResultsFor').' <span style="font-style: italic ;"> '.$keyword_name.' </span><br>';
}

Display :: display_header($nameTools, 'Group');
Display::display_header($nameTools, 'Group');

$form->setDefaults($defaults);
echo GroupManager::getSettingBar('settings');
Expand Down
3 changes: 3 additions & 0 deletions main/inc/ajax/document.ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
$groupInfo = GroupManager::get_group_properties(api_get_group_id());
// Only course admin or group members allowed
if ($is_allowed_to_edit || GroupManager::is_user_in_group(api_get_user_id(), $groupInfo)) {
if (!GroupManager::allowUploadEditDocument(api_get_user_id() , api_get_course_int_id(), $groupInfo)) {
exit;
}
} else {
exit;
}
Expand Down
3 changes: 2 additions & 1 deletion main/inc/lib/course.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -5567,7 +5567,8 @@ public static function getCourseSettingVariables(AppPlugin $appPlugin)
'email_to_teachers_on_new_work_feedback',
];

if (!empty(ExerciseLib::getScoreModels())) {
$courseModels = ExerciseLib::getScoreModels();
if (!empty($courseModels)) {
$courseSettings[] = 'score_model_id';
}

Expand Down
42 changes: 41 additions & 1 deletion main/inc/lib/groupmanager.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,7 @@ public static function get_group_properties($group_id, $useIid = false)
self::get_subscribed_tutors($result)
);
$result['count_all'] = $result['count_users'] + $result['count_tutor'];
$result['document_access'] = isset($db_object->document_access) ? $db_object->document_access : 0;
}

return $result;
Expand Down Expand Up @@ -620,6 +621,7 @@ public static function getGroupListFilterByName($name, $categoryId, $courseId)
* @param bool Whether self registration is allowed or not
* @param bool Whether self unregistration is allowed or not
* @param int $categoryId
* @param int $documentAccess
*
* @return bool TRUE if properties are successfully changed, false otherwise
*/
Expand All @@ -637,14 +639,22 @@ public static function set_group_properties(
$chat_state,
$self_registration_allowed,
$self_unregistration_allowed,
$categoryId = null
$categoryId = null,
$documentAccess = 0
) {
$table_group = Database::get_course_table(TABLE_GROUP);
$table_forum = Database::get_course_table(TABLE_FORUM);
$categoryId = intval($categoryId);
$group_id = intval($group_id);
$course_id = api_get_course_int_id();

$allowDocumentAccess = api_get_configuration_value('group_document_access');
$documentCondition = '';
if ($allowDocumentAccess) {
$documentAccess = (int) $documentAccess;
$documentCondition = " document_access = $documentAccess, ";
}

$sql = "UPDATE ".$table_group." SET
name='".Database::escape_string(trim($name))."',
doc_state = '".Database::escape_string($doc_state)."',
Expand All @@ -658,10 +668,12 @@ public static function set_group_properties(
max_student = '".Database::escape_string($maximum_number_of_students)."',
self_registration_allowed = '".Database::escape_string($self_registration_allowed)."',
self_unregistration_allowed = '".Database::escape_string($self_unregistration_allowed)."',
$documentCondition
category_id = ".intval($categoryId)."
WHERE c_id = $course_id AND id=".$group_id;
$result = Database::query($sql);


/* Here we are updating a field in the table forum_forum that perhaps
duplicates the table group_info.forum_state cvargas*/
$forum_state = (int) $forum_state;
Expand Down Expand Up @@ -2955,4 +2967,32 @@ public static function setInvisible($groupId)
{
self::setStatus($groupId, 0);
}

/**
* @param int $userId
* @param int $courseId
* @param array $groupInfo
* @param bool $blockPage
*/
public static function allowUploadEditDocument($userId, $courseId, $groupInfo, $blockPage = false)
{
$allow = api_get_configuration_value('group_document_access');
if (!$allow) {
return true;
}

if (isset($groupInfo['document_access']) &&
$groupInfo['document_access'] == 1 &&
(!api_is_allowed_to_edit() ||
(!api_is_allowed_to_edit() && !GroupManager::is_tutor_of_group($userId, $groupInfo, $courseId))
)
) {
if ($blockPage) {
api_not_allowed(true);
}
return false;
}

return true;
}
}
4 changes: 4 additions & 0 deletions main/install/configuration.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,10 @@
// Allow teachers to access student skills BT#14161 (skills setting must be enabled in the platform)
//$_configuration['allow_teacher_access_student_skills'] = false;

// Allow sharing options for the documents inside a group
//ALTER TABLE c_group_info ADD document_access INT DEFAULT 0 NOT NULL;
//$_configuration['group_document_access'] = false;

// ------ Custom DB changes (keep this at the end)
// Add user activation by confirmation email
// This option prevents the new user to login in the platform if your account is not confirmed via email
Expand Down
7 changes: 7 additions & 0 deletions src/Chamilo/CourseBundle/Entity/CGroupInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,13 @@ class CGroupInfo
*/
private $sessionId;

/**
* @var int needed for setting $_configuration['group_document_access']
*
* ORM\Column(name="doc_access", type="integer", nullable=false, options={"default":0})
*/
//private $docAccess;

/**
* Set name.
*
Expand Down

0 comments on commit c056499

Please sign in to comment.