Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mahara
mahara
Commits
555fe0af
Commit
555fe0af
authored
Nov 13, 2008
by
Richard Mansfield
Browse files
Logged-in users have a chance to join groups when linking to forum pages (#2059)
parent
c394e911
Changes
7
Hide whitespace changes
Inline
Side-by-side
htdocs/group/view.php
View file @
555fe0af
...
...
@@ -51,6 +51,7 @@ $group->admins = get_column_sql("SELECT member
$role
=
group_user_access
(
$group
->
id
);
if
(
is_logged_in
())
{
$afterjoin
=
param_variable
(
'next'
,
'view'
);
if
(
$role
)
{
if
(
$role
==
'admin'
)
{
$group
->
membershiptype
=
'admin'
;
...
...
@@ -67,14 +68,14 @@ if (is_logged_in()) {
else
if
(
$group
->
jointype
==
'invite'
and
$invite
=
get_record
(
'group_member_invite'
,
'group'
,
$group
->
id
,
'member'
,
$USER
->
get
(
'id'
)))
{
$group
->
membershiptype
=
'invite'
;
$group
->
invite
=
group_get_accept_form
(
'invite'
,
$group
->
id
,
'view'
);
$group
->
invite
=
group_get_accept_form
(
'invite'
,
$group
->
id
,
$afterjoin
);
}
else
if
(
$group
->
jointype
==
'request'
and
$request
=
get_record
(
'group_member_request'
,
'group'
,
$group
->
id
,
'member'
,
$USER
->
get
(
'id'
)))
{
$group
->
membershiptype
=
'request'
;
}
else
if
(
$group
->
jointype
==
'open'
)
{
$group
->
groupjoin
=
group_get_join_form
(
'joingroup'
,
$group
->
id
);
$group
->
groupjoin
=
group_get_join_form
(
'joingroup'
,
$group
->
id
,
$afterjoin
);
}
}
...
...
htdocs/interaction/forum/index.php
View file @
555fe0af
...
...
@@ -40,7 +40,7 @@ $group = group_current_group();
$membership
=
group_user_access
(
$groupid
);
if
(
!
$membership
&&
!
$group
->
public
)
{
throw
new
AccessDeniedException
(
get_string
(
'cantviewforums'
,
'interaction.forum'
));
throw
new
Group
AccessDeniedException
(
get_string
(
'cantviewforums'
,
'interaction.forum'
));
}
define
(
'TITLE'
,
$group
->
name
.
' - '
.
get_string
(
'nameplural'
,
'interaction.forum'
));
...
...
htdocs/interaction/forum/topic.php
View file @
555fe0af
...
...
@@ -48,18 +48,18 @@ $topic = get_record_sql(
array
(
0
,
$USER
->
get
(
'id'
),
$USER
->
get
(
'id'
),
$topicid
)
);
define
(
'GROUP'
,
$topic
->
groupid
);
if
(
!
$topic
)
{
throw
new
NotFoundException
(
get_string
(
'cantfindtopic'
,
'interaction.forum'
,
$topicid
));
}
define
(
'GROUP'
,
$topic
->
groupid
);
$membership
=
user_can_access_forum
((
int
)
$topic
->
forumid
);
$moderator
=
(
bool
)(
$membership
&
INTERACTION_FORUM_MOD
);
if
(
!
$membership
&&
!
get_field
(
'group'
,
'public'
,
'id'
,
$topic
->
groupid
))
{
throw
new
AccessDeniedException
(
get_string
(
'cantviewtopic'
,
'interaction.forum'
));
throw
new
Group
AccessDeniedException
(
get_string
(
'cantviewtopic'
,
'interaction.forum'
));
}
$topic
->
canedit
=
$moderator
||
user_can_edit_post
(
$topic
->
poster
,
$topic
->
ctime
);
...
...
htdocs/interaction/forum/view.php
View file @
555fe0af
...
...
@@ -65,7 +65,7 @@ $moderator = (bool)($membership & INTERACTION_FORUM_MOD);
if
(
!
$membership
&&
!
get_field
(
'group'
,
'public'
,
'id'
,
$forum
->
groupid
))
{
throw
new
AccessDeniedException
(
get_string
(
'cantviewforums'
,
'interaction.forum'
));
throw
new
Group
AccessDeniedException
(
get_string
(
'cantviewforums'
,
'interaction.forum'
));
}
define
(
'TITLE'
,
$forum
->
groupname
.
' - '
.
$forum
->
title
);
...
...
htdocs/lang/en.utf8/group.php
View file @
555fe0af
...
...
@@ -151,6 +151,7 @@ $string['group'] = 'group';
$string
[
'Group'
]
=
'Group'
;
$string
[
'groups'
]
=
'groups'
;
$string
[
'notamember'
]
=
'You are not a member of this group'
;
$string
[
'notmembermayjoin'
]
=
'You must join the group \'%s\' to see this page.'
;
// friendslist
$string
[
'reasonoptional'
]
=
'Reason (optional)'
;
...
...
htdocs/lib/errors.php
View file @
555fe0af
...
...
@@ -786,6 +786,35 @@ class AccessDeniedException extends UserException {
}
}
/**
* Exception - Access denied to a group page because the user isn't a member
* Give the user a chance to join then continue
*/
class
GroupAccessDeniedException
extends
AccessDeniedException
{
public
function
render_exception
()
{
global
$USER
,
$SESSION
;
if
(
defined
(
'GROUP'
)
&&
$USER
->
is_logged_in
())
{
$roles
=
$USER
->
get
(
'grouproles'
);
log_debug
(
$roles
);
if
(
!
isset
(
$roles
[
GROUP
]))
{
$group
=
group_current_group
();
if
(
$group
->
jointype
==
'open'
||
$group
->
jointype
==
'invite'
&&
get_record
(
'group_member_invite'
,
'group'
,
GROUP
,
'member'
,
$USER
->
get
(
'id'
)))
{
$SESSION
->
add_error_msg
(
get_string
(
'notmembermayjoin'
,
'group'
,
$group
->
name
));
$next
=
substr
(
$_SERVER
[
'REQUEST_URI'
],
strlen
(
get_mahara_install_subdirectory
())
-
1
);
redirect
(
get_config
(
'wwwroot'
)
.
'group/view.php?id='
.
GROUP
.
'&next='
.
urlencode
(
$next
));
}
if
(
$group
->
jointype
==
'request'
&&
!
get_record
(
'group_member_request'
,
'group'
,
GROUP
,
'member'
,
$USER
->
get
(
'id'
)))
{
$SESSION
->
add_error_msg
(
get_string
(
'notamember'
,
'group'
));
redirect
(
get_config
(
'wwwroot'
)
.
'group/requestjoin.php?id='
.
GROUP
.
'&returnto=view'
);
}
}
}
header
(
"HTTP/1.0 403 Forbidden"
,
true
);
return
parent
::
render_exception
();
}
}
/**
* Exception - Access totally denied, the user won't be able to access it even if they log in
* as the administrator
...
...
htdocs/lib/group.php
View file @
555fe0af
...
...
@@ -435,7 +435,7 @@ function group_remove_user($groupid, $userid=null) {
/**
* Form for users to join a given group
*/
function
group_get_join_form
(
$name
,
$groupid
)
{
function
group_get_join_form
(
$name
,
$groupid
,
$returnto
=
'view'
)
{
return
pieform
(
array
(
'name'
=>
$name
,
'successcallback'
=>
'joingroup_submit'
,
...
...
@@ -448,7 +448,11 @@ function group_get_join_form($name, $groupid) {
'group'
=>
array
(
'type'
=>
'hidden'
,
'value'
=>
$groupid
)
),
'returnto'
=>
array
(
'type'
=>
'hidden'
,
'value'
=>
$returnto
),
)
));
}
...
...
@@ -539,7 +543,13 @@ function joingroup_submit(Pieform $form, $values) {
global
$SESSION
,
$USER
;
group_add_user
(
$values
[
'group'
],
$USER
->
get
(
'id'
));
$SESSION
->
add_ok_msg
(
get_string
(
'joinedgroup'
,
'group'
));
redirect
(
'/group/view.php?id='
.
$values
[
'group'
]);
if
(
substr
(
$values
[
'returnto'
],
0
,
1
)
==
'/'
)
{
$next
=
$values
[
'returnto'
];
}
else
{
$next
=
'/group/view.php?id='
.
$values
[
'group'
];
}
redirect
(
$next
);
}
function
group_invite_submit
(
Pieform
$form
,
$values
)
{
...
...
@@ -550,7 +560,13 @@ function group_invite_submit(Pieform $form, $values) {
if
(
isset
(
$values
[
'accept'
]))
{
group_add_user
(
$values
[
'group'
],
$USER
->
get
(
'id'
),
$inviterecord
->
role
);
$SESSION
->
add_ok_msg
(
get_string
(
'groupinviteaccepted'
,
'group'
));
redirect
(
'/group/view.php?id='
.
$values
[
'group'
]);
if
(
substr
(
$values
[
'returnto'
],
0
,
1
)
==
'/'
)
{
$next
=
$values
[
'returnto'
];
}
else
{
$next
=
'/group/view.php?id='
.
$values
[
'group'
];
}
redirect
(
$next
);
}
else
{
$SESSION
->
add_ok_msg
(
get_string
(
'groupinvitedeclined'
,
'group'
));
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment