Registrierung fertig
This commit is contained in:
parent
f09f047f43
commit
2623b2db4d
|
|
@ -260,8 +260,6 @@ def NCAddUser(request):
|
|||
@api_view(['GET'],)
|
||||
def getTMInfos(request, uid, secretkey):
|
||||
if request.method == "GET":
|
||||
print("HI! asdsadassad")
|
||||
|
||||
return JsonResponse({"status" : "DATA " + uid + " " + secretkey})
|
||||
|
||||
return JsonResponse({"status" : "NO AUTH"})
|
||||
|
|
@ -287,8 +285,8 @@ def NCAddGroupFolder(request):
|
|||
# Groupfolder
|
||||
r = requests.post(settings.NEXTCLOUD_URL + "apps/agency/createagf", data=data, headers=headers)
|
||||
|
||||
# Standar Folder
|
||||
r = requests.request("MKCOL", settings.NEXTCLOUD_URL + "remote.php/dav/files/admin/Agenturdaten_" + str(agency.pk)+ '/Standards Uploadbereich/', auth=(settings.NEXTCLOUD_USER_API, settings.NEXTCLOUD_PW_API))
|
||||
# Standard Folder
|
||||
r = requests.request("MKCOL", settings.NEXTCLOUD_URL + "remote.php/dav/files/" + settings.NEXTCLOUD_USER_API + "/Agenturdaten_" + str(agency.pk)+ '/Standards Uploadbereich/', auth=(settings.NEXTCLOUD_USER_API, settings.NEXTCLOUD_PW_API))
|
||||
|
||||
return JsonResponse({'status' : True, 'message': 'Gruppenordner und Standard-Ordner angelegt!' + r.text})
|
||||
|
||||
|
|
@ -412,10 +410,13 @@ def NCTest(request):
|
|||
# Setting the Users Data for logging
|
||||
@api_view(['POST'], )
|
||||
def SetUserData(request):
|
||||
try:
|
||||
user = User.objects.get(username=request.POST.get('uid'))
|
||||
user.profile.nc_sid = request.POST.get('sid')
|
||||
user.save()
|
||||
return JsonResponse({'message' : 'A user was found in request, sid set!'})
|
||||
except:
|
||||
return JsonResponse({'message' : 'USER NOT FOUND'})
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -187,6 +187,7 @@ def save_profile(sender, instance, **kwargs):
|
|||
|
||||
# SIGNALS FOR GROUPS
|
||||
# Signal für das Ändern von Gruppenrechten
|
||||
'''
|
||||
@receiver(signal=m2m_changed, sender=Group.permissions.through)
|
||||
def adjust_group_notifications_permission(instance, action, reverse, model, pk_set, using, *args, **kwargs):
|
||||
group_touched = AgencyGroup.objects.get(group=instance)
|
||||
|
|
@ -217,10 +218,12 @@ def adjust_group_notifications_permission(instance, action, reverse, model, pk_s
|
|||
|
||||
#channel_layer = channels.layers.get_channel_layer()
|
||||
#async_to_sync(channel_layer.group_send)("user_" + str(user.pk), {'type' : 'pushhandler', 'pushtext' : "pushnotification__Gruppenaktivität | Der Gruppe " + group_touched.agencygroupname + " wurden Rechte entzogen."})
|
||||
|
||||
'''
|
||||
# Signal, wenn ein Nutzer aus der Gruppe entfernt/hinzugefügt wird
|
||||
'''
|
||||
@receiver(signal=m2m_changed, sender=User.groups.through)
|
||||
def adjust_group_notifications(instance, action, reverse, model, pk_set, using, *args, **kwargs):
|
||||
|
||||
if isinstance(instance, Group):
|
||||
group_touched = AgencyGroup.objects.get(group=instance)
|
||||
userid = list(pk_set)[0]
|
||||
|
|
@ -275,7 +278,7 @@ def adjust_group_notifications(instance, action, reverse, model, pk_set, using,
|
|||
html_message=msg_html,
|
||||
fail_silently=True
|
||||
)
|
||||
|
||||
'''
|
||||
|
||||
# SIGNALS FOR STANDARDS
|
||||
# DELETE
|
||||
|
|
@ -284,6 +287,7 @@ def delete_standard(sender, instance, **kwargs):
|
|||
newNotifiyPush(2, instance, " es wurde ein neuer Agenturstandard gelöscht: ", "Agenturstandard gelöscht: ", "Standards | ", "", "")
|
||||
|
||||
# SAVE AND UPDATE
|
||||
'''
|
||||
@receiver(post_save, sender=Standards)
|
||||
def save_standard(sender, instance, **kwargs):
|
||||
targeturl = settings.BASE_URL + "standards/standard/" + str(instance.pk) + "/single"
|
||||
|
|
@ -309,9 +313,10 @@ def save_standard(sender, instance, **kwargs):
|
|||
# Standard wurde aktualisiert
|
||||
else:
|
||||
newNotifiyPush(1, instance, " es wurde ein neuer Agenturstandard aktualisiert: ", "Agenturstandard aktualisiert: ", "Standards | ", "newstandard", targeturl)
|
||||
|
||||
'''
|
||||
|
||||
# SIGNAL FOR NEWS
|
||||
'''
|
||||
@receiver(post_save, sender=News)
|
||||
def save_news(sender, instance, **kwargs):
|
||||
if(kwargs["created"]):
|
||||
|
|
@ -323,9 +328,10 @@ def save_news(sender, instance, **kwargs):
|
|||
else:
|
||||
instance.agnotify = False
|
||||
instance.save()
|
||||
|
||||
'''
|
||||
|
||||
# SIGNALS FOR TASK
|
||||
'''
|
||||
@receiver(signal=m2m_changed, sender=Tasks.usersfield.through)
|
||||
def adjust_group_notifications_task(instance, action, reverse, model, pk_set, using, *args, **kwargs):
|
||||
|
||||
|
|
@ -361,6 +367,7 @@ def adjust_group_notifications_task(instance, action, reverse, model, pk_set, us
|
|||
elif(action == 'post_add'):
|
||||
notificationtext = "Sie wurden der Tätigkeit " + taskname + " zugeordnet."
|
||||
sendMailNoti(notificationtext, user_touched)
|
||||
'''
|
||||
|
||||
|
||||
|
||||
|
|
@ -384,10 +391,9 @@ def adjust_group_notifications_task(instance, action, reverse, model, pk_set, us
|
|||
'''
|
||||
def newNotifiyPush(mode, instance, mailtext, notifytext, pushtext, notifytype, targeturl=""):
|
||||
usersofagency = User.objects.filter(profile__agency__pk=instance.agency.pk)
|
||||
|
||||
'''
|
||||
# CREATED
|
||||
for user in usersofagency:
|
||||
|
||||
# LOAD USERNOTIFICATIONS
|
||||
created_mail = False
|
||||
created_push = False
|
||||
|
|
@ -476,7 +482,7 @@ def newNotifiyPush(mode, instance, mailtext, notifytext, pushtext, notifytype, t
|
|||
|
||||
#channel_layer = channels.layers.get_channel_layer()
|
||||
#async_to_sync(channel_layer.group_send)("user_" + str(user.pk), {'type' : 'pushhandler', 'pushtext' : "pushnotification__" + pushtext + notifytext + instance.name})
|
||||
|
||||
'''
|
||||
# DIRS
|
||||
@receiver(post_save, sender=DataDir)
|
||||
def save_dir(sender, instance, **kwargs):
|
||||
|
|
|
|||
|
|
@ -204,6 +204,4 @@ $(document).ready(function(){
|
|||
</div>
|
||||
</div>
|
||||
<!-- YOUTUBE PART ENDE -->
|
||||
|
||||
|
||||
{% endblock content %}
|
||||
|
|
|
|||
|
|
@ -1 +1,11 @@
|
|||
<h3>{{error}}</h3>
|
||||
|
||||
<script>
|
||||
/*
|
||||
$(document).ready(function(){
|
||||
setTimeout(function(){
|
||||
var ele = $("ul").find(`[data-id='logout']`);
|
||||
ele[0]['children'][0].click();
|
||||
}, 5000);
|
||||
})*/
|
||||
</script>
|
||||
148
users/views.py
148
users/views.py
|
|
@ -46,7 +46,7 @@ import base64
|
|||
import filetype
|
||||
from django.db.models.signals import m2m_changed
|
||||
from django.contrib.auth.models import User, Group
|
||||
from users.signals import adjust_group_notifications_permission
|
||||
#from users.signals import adjust_group_notifications_permission
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
from digitaleagentur.utils import *
|
||||
from digitaleagentur.timemanagement_utils import *
|
||||
|
|
@ -82,15 +82,143 @@ from django.contrib.auth import login, logout
|
|||
from django.core.mail import send_mail
|
||||
from django.views.generic import TemplateView
|
||||
|
||||
def get_random_number(length = 6):
|
||||
result_str = ''.join(random.choice("0123456789") for i in range(length))
|
||||
return result_str
|
||||
|
||||
def create_group_id(agencygroupname, agency):
|
||||
newgroupid = ""
|
||||
pregroupstr = "agencymaingroupid_"
|
||||
if(agencygroupname == "Mitarbeiter"):
|
||||
newgroupid = pregroupstr + str(agency.pk)
|
||||
# NORMAL GROUOPS
|
||||
elif(agencygroupname == "Administratoren"):
|
||||
newgroupid = pregroupstr + str(agency.pk) + "_defaultadmingroup"
|
||||
elif(agencygroupname == "Notfallhilfe"):
|
||||
newgroupid = pregroupstr + str(agency.pk) + "_recover"
|
||||
else:
|
||||
newgroupid = pregroupstr + str(agency.pk) + "_subgroup_" + get_random_number()
|
||||
|
||||
return newgroupid
|
||||
|
||||
def createNewAgencyByNC(request, uid):
|
||||
print("CREATE NEW AGENCY")
|
||||
# Creating Agency and prepare basic-Structure
|
||||
email = uid
|
||||
agency = Agency()
|
||||
agency.name = email + "'s Agentur"
|
||||
agency.vve = ""
|
||||
agency.save()
|
||||
pr=Profile()
|
||||
pr.agency=agency
|
||||
|
||||
# Create new User
|
||||
try:
|
||||
print("CREATE NEW USER IN DJANGO")
|
||||
user=User.objects.create_user(email, email, randomString(30))
|
||||
|
||||
except:
|
||||
print("PREDICTED EXCEPT - CONTINUE")
|
||||
user = User.objects.get(username=email)
|
||||
user.first_name = email
|
||||
user.last_name = email
|
||||
user.usernotification = UserNotification()
|
||||
#user.usertime = UserTime()
|
||||
pr.user=user
|
||||
pr.save()
|
||||
user.profile = pr
|
||||
user.save()
|
||||
print("USER DONE")
|
||||
request.user = user
|
||||
|
||||
# Creating all Standard-Django-Stuff
|
||||
toUpdate(request)
|
||||
loadPreStructure(agency)
|
||||
|
||||
# Creating all NC-Stuff
|
||||
# Agency-Groupfolder and Standard-Folder
|
||||
data = {
|
||||
"gid" : "agencymaingroupid_" + str(agency.pk),
|
||||
"aid" : str(agency.pk),
|
||||
"newagency" : True
|
||||
}
|
||||
|
||||
print("CREATING GROUPFOLDER")
|
||||
r = requests.post(settings.NEXTCLOUD_URL + "ocs/v2.php/apps/da_agency/api/v1/creategf?format=json", auth=(settings.NEXTCLOUD_USER_API, settings.NEXTCLOUD_PW_API), data=data)
|
||||
print(r.text)
|
||||
|
||||
|
||||
print("CREATING GROUPS IN NC FROM DJANGO")
|
||||
groups = AgencyGroup.objects.filter(agency=agency)
|
||||
for g in groups:
|
||||
newgroupid = create_group_id(g.agencygroupname, agency)
|
||||
headers = {
|
||||
'Accept' : 'application/json',
|
||||
'Access-Control-Allow-Headers' : 'OCS-APIRequest',
|
||||
'OCS-APIRequest' : 'true'
|
||||
}
|
||||
data = {
|
||||
"groupid" : newgroupid
|
||||
}
|
||||
print("CREATE GROUP " + g.agencygroupname)
|
||||
r = requests.post(settings.NEXTCLOUD_URL + "ocs/v1.php/cloud/groups", data=data, headers=headers, auth=(settings.NEXTCLOUD_USER_API, settings.NEXTCLOUD_PW_API))
|
||||
print(r.text)
|
||||
|
||||
r_status = json.loads(r.text)
|
||||
if(r_status['ocs']['meta']['statuscode'] == 100):
|
||||
# Group created, save new group id in Django
|
||||
g.nc_name = newgroupid
|
||||
g.save()
|
||||
|
||||
# Group created, set display name in NC
|
||||
data = {
|
||||
"name": g.agencygroupname,
|
||||
"id" : newgroupid
|
||||
}
|
||||
print("GROUP OK - CHANGE DISPLAY NAME")
|
||||
r = requests.post(settings.NEXTCLOUD_URL + "ocs/v2.php/apps/da_agency/api/v1/renameagg?format=json", auth=(settings.NEXTCLOUD_USER_API, settings.NEXTCLOUD_PW_API), data=data)
|
||||
print(r.text)
|
||||
|
||||
# Add current user to all Groups!
|
||||
print("ADDING CURRENT USER TO ALL GROUPS")
|
||||
headers = {
|
||||
'Accept' : 'application/json',
|
||||
'Access-Control-Allow-Headers' : 'OCS-APIRequest',
|
||||
'OCS-APIRequest' : 'true'
|
||||
}
|
||||
data_nc = {
|
||||
"groupid" : g.nc_name,
|
||||
}
|
||||
r = requests.post(settings.NEXTCLOUD_URL + "/ocs/v1.php/cloud/users/" + user.username + "/groups",headers=headers, auth=(settings.NEXTCLOUD_USER_API, settings.NEXTCLOUD_PW_API), data=data_nc)
|
||||
print(r.text)
|
||||
|
||||
print("CREATING STANDARDFOLDER")
|
||||
r_2 = requests.request("MKCOL", settings.NEXTCLOUD_URL + "remote.php/dav/files/" + user.username + "/Agenturdaten/Standards Uploadbereich", auth=(settings.NEXTCLOUD_USER_API, settings.NEXTCLOUD_PW_API))
|
||||
print(r_2.text)
|
||||
|
||||
print("DONE! Redirecting to nclogin")
|
||||
#return redirect(settings.NEXTCLOUD_URL)
|
||||
#return redirect('nclog', uid)
|
||||
|
||||
|
||||
|
||||
# Entry-Point for NC
|
||||
def ncLogin(request, uid):
|
||||
logout(request)
|
||||
print(uid)
|
||||
try:
|
||||
user = User.objects.get(username=uid)
|
||||
if(getNCLoggedUserBySession(user.profile.nc_sid) == uid):
|
||||
login(request, user)
|
||||
return redirect('users-dashboard')
|
||||
return render(request, 'users/nclog.html',{'error' : "Bereite daten vor...bitte die Seite neu laden!"})
|
||||
return render(request, 'users/nclog.html',{'error' : "Die Agenturdaten wurden aktualisiert. Bitte melden Sie sich ab und wieder an. Sollten Sie diese Meldung weiterhin sehen, kontaktieren Sie den Support."})
|
||||
except:
|
||||
print("NO USER FOUND - NEW AGENCY REGISTRATION!")
|
||||
try:
|
||||
createNewAgencyByNC(request, uid)
|
||||
except:
|
||||
return render(request, 'users/nclog.html',{'error' : "Die Agenturdaten wurden aktualisiert. Bitte melden Sie sich ab und wieder an. Sollten Sie diese Meldung weiterhin sehen, kontaktieren Sie den Support."})
|
||||
return render(request, 'users/nclog.html',{'error' : "Die Agenturdaten wurden aktualisiert. Bitte melden Sie sich ab und wieder an. Sollten Sie diese Meldung weiterhin sehen, kontaktieren Sie den Support."})
|
||||
|
||||
def getICSFile(request, ag):
|
||||
if 'HTTP_AUTHORIZATION' in request.META:
|
||||
|
|
@ -377,6 +505,14 @@ def toUpdate(request):
|
|||
temgroup_verwaltung_ag = AgencyGroup(savefordel=True, is_admin=True, group=temgroup_verwaltung, agency=request.user.profile.agency, agencygroupname="Administratoren")
|
||||
temgroup_verwaltung_ag.save()
|
||||
|
||||
temgroup_Notfallhilfe = Group(name=str(request.user.profile.agency.pk) + "_" + randomString(8))
|
||||
temgroup_Notfallhilfe.save()
|
||||
temgroup_Notfallhilfe_ag = AgencyGroup(savefordel=True, group=temgroup_Notfallhilfe, agency=request.user.profile.agency, agencygroupname="Notfallhilfe")
|
||||
temgroup_Notfallhilfe_ag.save()
|
||||
|
||||
recoverdirmanagingperm = Permission.objects.get(codename='recoverdirmanager')
|
||||
temgroup_Notfallhilfe_ag.group.permissions.add(recoverdirmanagingperm)
|
||||
|
||||
#print("default groups created...adding users...")
|
||||
users_of_agency = User.objects.filter(profile__agency__pk=request.user.profile.agency.pk)
|
||||
for user in users_of_agency:
|
||||
|
|
@ -411,7 +547,7 @@ def toUpdate(request):
|
|||
#print("recoverdirgroup added and perms set")
|
||||
|
||||
# CHECK FOR ALL POSSIBLE RIGHTS ON ADMINGROUP
|
||||
m2m_changed.disconnect(adjust_group_notifications_permission, sender=Group.permissions.through)
|
||||
#m2m_changed.disconnect(adjust_group_notifications_permission, sender=Group.permissions.through)
|
||||
|
||||
ag_admingroup = list(AgencyGroup.objects.filter(agency=request.user.profile.agency, is_admin=True))[0]
|
||||
perms = AgencyGroup._meta.permissions
|
||||
|
|
@ -420,7 +556,7 @@ def toUpdate(request):
|
|||
ag_admingroup.group.permissions.add(tempperm)
|
||||
|
||||
|
||||
|
||||
'''
|
||||
# INITIAL ROOT DIR
|
||||
rootdir = DataDir.objects.filter(is_root=True, agency__pk=request.user.profile.agency.pk)
|
||||
|
||||
|
|
@ -456,7 +592,7 @@ def toUpdate(request):
|
|||
#print("AGENCY DEF STANDARD DIR - FILESMODULE READY")
|
||||
pass
|
||||
|
||||
|
||||
'''
|
||||
# CHANGE RIGHTS ORGNAIZER
|
||||
admingroups = AgencyGroup.objects.filter(is_admin=True)
|
||||
for a in admingroups:
|
||||
|
|
@ -464,7 +600,7 @@ def toUpdate(request):
|
|||
a.group.permissions.add(Permission.objects.get(codename="agencynetwork"))
|
||||
|
||||
|
||||
m2m_changed.connect(adjust_group_notifications_permission, sender=Group.permissions.through)
|
||||
#m2m_changed.connect(adjust_group_notifications_permission, sender=Group.permissions.through)
|
||||
|
||||
# USER TIME MODEL
|
||||
usersofagency = User.objects.filter(profile__agency=request.user.profile.agency)
|
||||
|
|
|
|||
Loading…
Reference in New Issue