Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
our_own_cloud_project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
die_coolen_jungs
our_own_cloud_project
Commits
a70330e9
Commit
a70330e9
authored
14 years ago
by
Jakob Sack
Browse files
Options
Downloads
Patches
Plain Diff
Improved documentation for group management
parent
866d01f5
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
admin/users.php
+1
-1
1 addition, 1 deletion
admin/users.php
lib/Group/backend.php
+39
-24
39 additions, 24 deletions
lib/Group/backend.php
lib/Group/database.php
+55
-33
55 additions, 33 deletions
lib/Group/database.php
lib/group.php
+43
-27
43 additions, 27 deletions
lib/group.php
with
138 additions
and
85 deletions
admin/users.php
+
1
−
1
View file @
a70330e9
...
...
@@ -46,7 +46,7 @@ foreach( OC_USER::getUsers() as $i ){
foreach
(
OC_GROUP
::
getGroups
()
as
$i
){
// Do some more work here soon
$groups
[]
=
array
(
"name"
=>
$i
[
"gid"
]
);
$groups
[]
=
array
(
"name"
=>
$i
);
}
$tmpl
=
new
OC_TEMPLATE
(
"admin"
,
"users"
,
"admin"
);
...
...
This diff is collapsed.
Click to expand it.
lib/Group/backend.php
+
39
−
24
View file @
a70330e9
...
...
@@ -24,58 +24,73 @@
/**
* Base class for user management
*
* Abstract base class for user management
*/
abstract
class
OC_GROUP_BACKEND
{
/**
* Try to create a new group
* @brief Try to create a new group
* @param $gid The name of the group to create
* @returns true/false
*
* @param string $groupName The name of the group to create
* Trys to create a new group. If the group name already exists, false will
* be returned.
*/
public
static
function
createGroup
(
$g
roupName
){}
public
static
function
createGroup
(
$g
id
){}
/**
* Try to delete Group
* @brief delete a group
* @param $gid gid of the group to delete
* @returns true/false
*
*
@param string $groupName The name of the group to delet
e
*
Deletes a group and removes it from the group_user-tabl
e
*/
public
static
function
delet
eGroup
(
$g
roupName
){}
public
static
function
remov
eGroup
(
$g
id
){}
/**
* Check if a user belongs to a group
* @brief is user in group?
* @param $uid uid of the user
* @param $gid gid of the group
* @returns true/false
*
* @param string $username Name of the user to check
* @param string $groupName Name of the group
* Checks whether the user is member of a group or not.
*/
public
static
function
inGroup
(
$u
sername
,
$groupName
){}
public
static
function
inGroup
(
$u
id
,
$gid
){}
/**
* Add a user to a group
* @brief Add a user to a group
* @param $uid Name of the user to add to group
* @param $gid Name of the group in which add the user
* @returns true/false
*
* @param string $username Name of the user to add to group
* @param string $groupName Name of the group in which add the user
* Adds a user to a group.
*/
public
static
function
addToGroup
(
$u
sername
,
$groupName
){}
public
static
function
addToGroup
(
$u
id
,
$gid
){}
/**
* Remove a user from a group
* @brief Removes a user from a group
* @param $uid Name of the user to remove from group
* @param $gid Name of the group from which remove the user
* @returns true/false
*
* @param string $username Name of the user to remove from group
* @param string $groupName Name of the group from which remove the user
* removes the user from a group.
*/
public
static
function
removeFromGroup
(
$u
sername
,
$groupName
){}
public
static
function
removeFromGroup
(
$u
id
,
$gid
){}
/**
* Get all groups the user belongs to
* @brief Get all groups a user belongs to
* @param $uid Name of the user
* @returns array with group names
*
* @param string $username Name of the user
* This function fetches all groups a user belongs to. It does not check
* if the user exists at all.
*/
public
static
function
getUserGroups
(
$u
sername
){}
public
static
function
getUserGroups
(
$u
id
){}
/**
* get a list of all groups
* @brief get a list of all groups
* @returns array with group names
*
* Returns a list with all groups
*/
public
static
function
getGroups
(){}
}
This diff is collapsed.
Click to expand it.
lib/Group/database.php
+
55
−
33
View file @
a70330e9
...
...
@@ -41,24 +41,29 @@ require_once( 'Group/backend.php' );
/**
* Class for group management in a SQL Database (e.g. MySQL, SQLite)
*
*/
class
OC_GROUP_DATABASE
extends
OC_GROUP_BACKEND
{
static
private
$userGroupCache
=
array
();
/**
* Try to create a new group
* @brief Try to create a new group
* @param $gid The name of the group to create
* @returns true/false
*
* @param string $groupName The name of the group to create
* Trys to create a new group. If the group name already exists, false will
* be returned.
*/
public
static
function
createGroup
(
$gid
){
// Check for existence
$query
=
OC_DB
::
prepare
(
"SELECT * FROM `*PREFIX*groups` WHERE gid = ?"
);
$result
=
$query
->
execute
(
array
(
$gid
));
if
(
$result
->
numRows
()
>
0
){
// Can not add an existing group
return
false
;
}
else
{
// Add group and exit
$query
=
OC_DB
::
prepare
(
"INSERT INTO `*PREFIX*groups` ( `gid` ) VALUES( ? )"
);
$result
=
$query
->
execute
(
array
(
$gid
));
...
...
@@ -67,67 +72,82 @@ class OC_GROUP_DATABASE extends OC_GROUP_BACKEND {
}
/**
* Try to delete a group
* @brief delete a group
* @param $gid gid of the group to delete
* @returns true/false
*
*
@param string $groupName The name of the group to delet
e
*
Deletes a group and removes it from the group_user-tabl
e
*/
public
static
function
deleteGroup
(
$gid
){
// Delete the group
$query
=
OC_DB
::
prepare
(
"DELETE FROM `*PREFIX*groups` WHERE gid = ?"
);
$result
=
$query
->
execute
(
array
(
$gid
));
// Delete the group-user relation
$query
=
OC_DB
::
prepare
(
"DELETE FROM `*PREFIX*group_user` WHERE gid = ?"
);
$result
=
$query
->
execute
(
array
(
$gid
));
return
true
;
}
/**
* Check if a user belongs to a group
* @brief is user in group?
* @param $uid uid of the user
* @param $gid gid of the group
* @returns true/false
*
* @param string $username Name of the user to check
* @param string $groupName Name of the group
* Checks whether the user is member of a group or not.
*/
public
static
function
inGroup
(
$username
,
$groupName
){
public
static
function
inGroup
(
$uid
,
$gid
){
// check
$query
=
OC_DB
::
prepare
(
"SELECT * FROM `*PREFIX*group_user` WHERE gid = ? AND uid = ?"
);
$result
=
$query
->
execute
(
array
(
$groupName
,
$username
));
if
(
PEAR
::
isError
(
$result
))
{
$entry
=
'DB Error: "'
.
$result
->
getMessage
()
.
'"<br />'
;
$entry
.
=
'Offending command was: '
.
$result
->
getDebugInfo
()
.
'<br />'
;
error_log
(
$entry
);
die
(
$entry
);
}
$result
=
$query
->
execute
(
array
(
$gid
,
$uid
));
return
$result
->
numRows
()
>
0
?
true
:
false
;
}
/**
* Add a user to a group
* @brief Add a user to a group
* @param $uid Name of the user to add to group
* @param $gid Name of the group in which add the user
* @returns true/false
*
* @param string $username Name of the user to add to group
* @param string $groupName Name of the group in which add the user
* Adds a user to a group.
*/
public
static
function
addToGroup
(
$username
,
$groupName
){
if
(
!
self
::
inGroup
(
$username
,
$groupName
)){
public
static
function
addToGroup
(
$uid
,
$gid
){
// No duplicate entries!
if
(
!
self
::
inGroup
(
$uid
,
$gid
)){
$query
=
OC_DB
::
prepare
(
"INSERT INTO `*PREFIX*group_user` ( `uid`, `gid` ) VALUES( ?, ? )"
);
$result
=
$query
->
execute
(
array
(
$u
sername
,
$groupName
));
$result
=
$query
->
execute
(
array
(
$u
id
,
$gid
));
}
return
true
;
}
/**
* Remove a user from a group
* @brief Removes a user from a group
* @param $uid Name of the user to remove from group
* @param $gid Name of the group from which remove the user
* @returns true/false
*
* @param string $username Name of the user to remove from group
* @param string $groupName Name of the group from which remove the user
* removes the user from a group.
*/
public
static
function
removeFromGroup
(
$u
sername
,
$groupName
){
public
static
function
removeFromGroup
(
$u
id
,
$gid
){
$query
=
OC_DB
::
prepare
(
"DELETE FROM `*PREFIX*group_user` WHERE `uid` = ? AND `gid` = ?"
);
$result
=
$query
->
execute
(
array
(
$u
sername
,
$groupName
));
$result
=
$query
->
execute
(
array
(
$u
id
,
$gid
));
}
/**
* Get all groups the user belongs to
* @brief Get all groups a user belongs to
* @param $uid Name of the user
* @returns array with group names
*
* @param string $username Name of the user
* This function fetches all groups a user belongs to. It does not check
* if the user exists at all.
*/
public
static
function
getUserGroups
(
$username
){
public
static
function
getUserGroups
(
$uid
){
// No magic!
$query
=
OC_DB
::
prepare
(
"SELECT * FROM `*PREFIX*group_user` WHERE uid = ?"
);
$result
=
$query
->
execute
(
array
(
$u
sername
));
$result
=
$query
->
execute
(
array
(
$u
id
));
$groups
=
array
();
while
(
$row
=
$result
->
fetchRow
()){
...
...
@@ -138,8 +158,10 @@ class OC_GROUP_DATABASE extends OC_GROUP_BACKEND {
}
/**
* get a list of all groups
* @brief get a list of all groups
* @returns array with group names
*
* Returns a list with all groups
*/
public
static
function
getGroups
(){
$query
=
OC_DB
::
prepare
(
"SELECT * FROM `*PREFIX*groups`"
);
...
...
@@ -147,7 +169,7 @@ class OC_GROUP_DATABASE extends OC_GROUP_BACKEND {
$groups
=
array
();
while
(
$row
=
$result
->
fetchRow
()){
$groups
[]
=
$row
;
$groups
[]
=
$row
[
"gid"
]
;
}
return
$groups
;
...
...
This diff is collapsed.
Click to expand it.
lib/group.php
+
43
−
27
View file @
a70330e9
...
...
@@ -79,65 +79,81 @@ class OC_GROUP {
}
/**
* Try to create a new group
* @brief Try to create a new group
* @param $gid The name of the group to create
* @returns true/false
*
* @param string $groupName The name of the group to create
* Trys to create a new group. If the group name already exists, false will
* be returned.
*/
public
static
function
createGroup
(
$gid
){
return
self
::
$_backend
->
createGroup
(
$gid
);
}
/**
* Try to delete Group
* @brief delete a group
* @param $gid gid of the group to delete
* @returns true/false
*
*
@param string $groupName The name of the group to delet
e
*
Deletes a group and removes it from the group_user-tabl
e
*/
public
static
function
deleteGroup
(
$gid
){
return
self
::
$_backend
->
deleteGroup
(
$gid
);
}
/**
* Check if a user belongs to a group
* @brief is user in group?
* @param $uid uid of the user
* @param $gid gid of the group
* @returns true/false
*
* @param string $username Name of the user to check
* @param string $groupName Name of the group
* Checks whether the user is member of a group or not.
*/
public
static
function
inGroup
(
$u
sername
,
$groupName
)
{
return
self
::
$_backend
->
inGroup
(
$u
sername
,
$groupName
);
public
static
function
inGroup
(
$u
id
,
$gid
)
{
return
self
::
$_backend
->
inGroup
(
$u
id
,
$gid
);
}
/**
* Add a user to a group
* @brief Add a user to a group
* @param $uid Name of the user to add to group
* @param $gid Name of the group in which add the user
* @returns true/false
*
* @param string $username Name of the user to add to group
* @param string $groupName Name of the group in which add the user
* Adds a user to a group.
*/
public
static
function
addToGroup
(
$u
sername
,
$groupName
)
{
return
self
::
$_backend
->
addToGroup
(
$u
sername
,
$groupName
);
public
static
function
addToGroup
(
$u
id
,
$gid
)
{
return
self
::
$_backend
->
addToGroup
(
$u
id
,
$gid
);
}
/**
* Remove a user from a group
* @brief Removes a user from a group
* @param $uid Name of the user to remove from group
* @param $gid Name of the group from which remove the user
* @returns true/false
*
* @param string $username Name of the user to remove from group
* @param string $groupName Name of the group from which remove the user
* removes the user from a group.
*/
public
static
function
removeFromGroup
(
$u
sername
,
$groupName
){
return
self
::
$_backend
->
removeFromGroup
(
$u
sername
,
$groupName
);
public
static
function
removeFromGroup
(
$u
id
,
$gid
){
return
self
::
$_backend
->
removeFromGroup
(
$u
id
,
$gid
);
}
/**
* Get all groups the user belongs to
* @brief Get all groups a user belongs to
* @param $uid Name of the user
* @returns array with group names
*
* @param string $username Name of the user
* This function fetches all groups a user belongs to. It does not check
* if the user exists at all.
*/
public
static
function
getUserGroups
(
$u
sername
)
{
return
self
::
$_backend
->
getUserGroups
(
$u
sername
);
public
static
function
getUserGroups
(
$u
id
)
{
return
self
::
$_backend
->
getUserGroups
(
$u
id
);
}
/**
* get a list of all groups
* @brief get a list of all groups
* @returns array with group names
*
* Returns a list with all groups
*/
public
static
function
getGroups
(){
return
self
::
$_backend
->
getGroups
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment