Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
itminedu
synnefo
Commits
5ebd5989
Commit
5ebd5989
authored
Dec 02, 2012
by
Sofia Papagiannaki
Browse files
Extend/Update management commands
parent
f30ed7e6
Changes
6
Hide whitespace changes
Inline
Side-by-side
snf-astakos-app/astakos/im/management/commands/group-details.py
0 → 100644
View file @
5ebd5989
# Copyright 2012 GRNET S.A. All rights reserved.
#
# Redistribution and use in source and binary forms, with or
# without modification, are permitted provided that the following
# conditions are met:
#
# 1. Redistributions of source code must retain the above
# copyright notice, this list of conditions and the following
# disclaimer.
#
# 2. Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials
# provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# The views and conclusions contained in the software and
# documentation are those of the authors and should not be
# interpreted as representing official policies, either expressed
# or implied, of GRNET S.A.
from
collections
import
defaultdict
from
django.core.management.base
import
BaseCommand
,
CommandError
from
django.db
import
models
from
astakos.im.models
import
AstakosGroup
class
Command
(
BaseCommand
):
args
=
"<group name>"
help
=
"Show group info"
def
handle
(
self
,
*
args
,
**
options
):
if
len
(
args
)
!=
1
:
raise
CommandError
(
"Please provide a group name"
)
group
=
AstakosGroup
.
objects
name_or_id
=
args
[
0
].
decode
(
'utf8'
)
try
:
if
name_or_id
.
isdigit
():
group
=
group
.
get
(
id
=
int
(
name_or_id
))
else
:
group
=
group
.
get
(
name
=
name_or_id
)
except
AstakosGroup
.
DoesNotExist
:
field
=
'id'
if
name_or_id
.
isdigit
()
else
'name'
msg
=
"Unknown user with %s '%s'"
%
(
field
,
name_or_id
)
raise
CommandError
(
msg
)
attrs
=
(
'id'
,
'name'
,
'kind'
,
'homepage'
,
'desc'
,
'owners'
,
'is_enabled'
,
'max_participants'
,
'moderation_enabled'
,
'creation_date'
,
'issue_date'
,
'expiration_date'
,
'approval_date'
,
'members'
,
'approved_members'
,
'quota'
,
'permissions'
)
for
attr
in
attrs
:
val
=
getattr
(
group
,
attr
)
if
isinstance
(
val
,
defaultdict
):
val
=
dict
(
val
)
if
isinstance
(
val
,
models
.
Manager
):
val
=
val
.
all
()
line
=
'%s: %s
\n
'
%
(
attr
.
rjust
(
22
),
val
)
self
.
stdout
.
write
(
line
.
encode
(
'utf8'
))
self
.
stdout
.
write
(
'
\n
'
)
\ No newline at end of file
snf-astakos-app/astakos/im/management/commands/group-permissions-remove.py
~HEAD
→
snf-astakos-app/astakos/im/management/commands/group-permissions-remove.py
View file @
5ebd5989
File moved
snf-astakos-app/astakos/im/management/commands/service-add.py
View file @
5ebd5989
...
...
@@ -52,8 +52,8 @@ class Command(BaseCommand):
except
Exception
,
e
:
raise
CommandError
(
e
)
else
:
if
r
.
is_success
:
if
r
.
is_success
:
self
.
stdout
.
write
(
'Service created successfully
\n
'
)
else
:
raise
CommandError
(
r
.
reason
)
raise
CommandError
(
r
.
reason
)
snf-astakos-app/astakos/im/management/commands/user-add.py
View file @
5ebd5989
...
...
@@ -49,18 +49,10 @@ def filter_custom_options(options):
class
Command
(
BaseCommand
):
args
=
"<email>"
args
=
"<email>
<first name> <last name>
"
help
=
"Create a user"
option_list
=
BaseCommand
.
option_list
+
(
make_option
(
'--first-name'
,
dest
=
'first_name'
,
metavar
=
'NAME'
,
help
=
"Set user's first name"
),
make_option
(
'--last-name'
,
dest
=
'last_name'
,
metavar
=
'NAME'
,
help
=
"Set user's last name"
),
make_option
(
'--affiliation'
,
dest
=
'affiliation'
,
metavar
=
'AFFILIATION'
,
...
...
@@ -90,34 +82,37 @@ class Command(BaseCommand):
)
def
handle
(
self
,
*
args
,
**
options
):
if
len
(
args
)
!=
1
:
if
len
(
args
)
!=
3
:
raise
CommandError
(
"Invalid number of arguments"
)
email
=
args
[
0
].
decode
(
'utf8'
)
email
,
first_name
,
last_name
=
(
args
[
i
].
decode
(
'utf8'
)
for
i
in
range
(
3
))
try
:
validate_email
(
email
)
except
ValidationError
:
raise
CommandError
(
"Invalid email"
)
u
=
{
'email'
:
email
}
u
=
{
'email'
:
email
,
'first_name'
:
first_name
,
'last_name'
:
last_name
}
u
.
update
(
filter_custom_options
(
options
))
if
not
u
.
get
(
'password'
):
u
[
'password'
]
=
AstakosUser
.
objects
.
make_random_password
()
try
:
c
=
AstakosCallpoint
()
r
=
c
.
create_users
((
u
,))
r
=
c
.
create_users
((
u
,))
.
next
()
except
socket
.
error
,
e
:
raise
CommandError
(
e
)
except
ValidationError
,
e
:
raise
CommandError
(
e
)
else
:
failed
=
(
res
for
res
in
r
if
not
r
es
.
is_success
)
for
r
in
failed
:
if
not
r
.
is_success
:
raise
CommandError
(
r
.
reason
)
if
not
failed
:
self
.
stdout
.
write
(
'
User created successfully'
)
if
not
u
.
get
(
'password'
)
:
self
.
stdout
.
write
(
'
with password: %s'
%
u
[
'password'
]
)
if
not
r
.
is_success
:
raise
CommandError
(
r
.
reason
)
else
:
self
.
stdout
.
write
(
'User created successfully '
)
if
not
options
.
get
(
'password'
)
:
self
.
stdout
.
write
(
'
with password: %s
\n
'
%
u
[
'password'
]
)
else
:
self
.
stdout
.
write
(
'
\n
'
)
\ No newline at end of file
snf-astakos-app/astakos/im/management/commands/
group-permissions
-remove.py
~future
→
snf-astakos-app/astakos/im/management/commands/
user
-remove.py
View file @
5ebd5989
...
...
@@ -31,44 +31,40 @@
# interpreted as representing official policies, either expressed
# or implied, of GRNET S.A.
import
socket
from
optparse
import
make_option
from
django.core.management.base
import
BaseCommand
,
CommandError
from django.co
ntrib.auth.models import Group
from
django.co
re.validators
import
validate_email
from
django.core.exceptions
import
ValidationError
from
astakos.im.models
import
AstakosUser
from ._common import remove_group_permission
from
astakos.im.api.callpoint
import
AstakosCallpoint
def
filter_custom_options
(
options
):
base_dests
=
list
(
getattr
(
o
,
'dest'
,
None
)
for
o
in
BaseCommand
.
option_list
)
return
dict
((
k
,
v
)
for
k
,
v
in
options
.
iteritems
()
if
k
not
in
base_dests
)
class
Command
(
BaseCommand
):
args = "<
groupname> <permission> [<permissions> ...]
"
help = "Remove
group permissions
"
args
=
"<
user ID>
"
help
=
"Remove
a user
"
def
handle
(
self
,
*
args
,
**
options
):
if len(args) < 2:
raise CommandError(
"Please provide a group name and at least one permission")
group = None
try:
if args[0].isdigit():
group = Group.objects.get(id=args[0])
else:
group = Group.objects.get(name=args[0])
except Group.DoesNotExist, e:
raise CommandError("Invalid group")
if
len
(
args
)
!=
1
:
raise
CommandError
(
"Invalid number of arguments"
)
id
=
args
[
0
]
if
not
id
.
isdigit
():
raise
CommandError
(
'ID must me an integer'
)
try
:
for pname in args[1:]:
r = remove_group_permission(group, pname)
if r < 0:
self.stdout.write(
'Invalid permission codename: %s\n' % pname)
elif r == 0:
self.stdout.write('Group has not permission: %s\n' % pname)
elif r > 0:
self.stdout.write(
'Permission: %s removed successfully\n' % pname)
except Exception, e:
raise CommandError(e)
user
=
AstakosUser
.
objects
.
get
(
id
=
int
(
id
))
except
:
msg
=
"Unknown user with id '%s'"
%
id
raise
CommandError
(
msg
)
else
:
user
.
delete
()
self
.
stdout
.
write
(
'User deleted successfully
\n
'
)
\ No newline at end of file
snf-astakos-app/astakos/im/templates/im/.astakosgroup_detail.html.swp
deleted
100644 → 0
View file @
f30ed7e6
File deleted
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