def test_project_add_change(self): u = fh.create_user() org = fh.create_organization(subdomain=u'one') orguser = org.attach_user(u) self.flush() project = p.Project(name=u"foobar", creator=u, description=u"description", organization=org) Session.add(project) filepath = file_path('ffcc00.gif') change = project.add_change(u, u"/main/project/arnold/foobar.gif", filepath, u"this is a new change") self.flush() act = activity.get_activities(organization=org) assert len(act) == 2 assert act[0].type == activity.NewFile.TYPE assert act[0].get_message() filepath = file_path('ffcc00.gif') change = project.add_change(u, u"/main/project/arnold/foobar.gif", filepath, u"this is a new change") self.flush() act = activity.get_activities(organization=org) assert len(act) == 3 assert act[0].type == activity.NewVersion.TYPE assert act[0].get_message() comment = change.add_comment(u, "This is a comment") self.flush() reply = change.add_comment(u, "This is a reply", in_reply_to=comment) self.flush() act = activity.get_activities(organization=org) assert len(act) == 5 assert act[0].type == activity.NewReply.TYPE assert act[0].get_message() assert act[1].type == activity.NewComment.TYPE assert act[1].get_message() comment.set_completion_status(u, STATUS_COMPLETED) self.flush() comment.set_completion_status(u, STATUS_OPEN) self.flush() act = activity.get_activities(organization=org) assert len(act) == 7 assert act[0].type == activity.CommentComplete.TYPE assert 'uncompleted' in act[0].get_message() assert act[1].type == activity.CommentComplete.TYPE assert 'completed' in act[1].get_message()
def test_project_add_change(self): u = fh.create_user() org = fh.create_organization(subdomain=u'one') orguser = org.attach_user(u) self.flush() project = p.Project(name=u"foobar", creator=u, description=u"description", organization=org) Session.add(project) filepath = file_path('ffcc00.gif') change = project.add_change(u, u"/main/project/arnold/foobar.gif", filepath, u"this is a new change") self.flush() act = activity.get_activities(organization=org) assert len(act) == 2 assert act[0].type == activity.NewFile.TYPE assert act[0].get_message() filepath = file_path('ffcc00.gif') change = project.add_change(u, u"/main/project/arnold/foobar.gif", filepath, u"this is a new change") self.flush() act = activity.get_activities(organization=org) assert len(act) == 3 assert act[0].type == activity.NewVersion.TYPE assert act[0].get_message() comment = change.add_comment(u, "This is a comment") self.flush() reply = change.add_comment(u, "This is a reply", in_reply_to=comment) self.flush() act = activity.get_activities(organization=org) assert len(act) == 5 assert act[0].type == activity.NewReply.TYPE assert act[0].get_message() assert act[1].type == activity.NewComment.TYPE assert act[1].get_message() comment.set_completion_status(u, STATUS_COMPLETED) self.flush() comment.set_completion_status(u, STATUS_OPEN) self.flush() act = activity.get_activities(organization=org) assert len(act) == 7 assert act[0].type == activity.CommentComplete.TYPE assert 'uncompleted' in act[0].get_message() assert act[1].type == activity.CommentComplete.TYPE assert 'completed' in act[1].get_message()
def test_project_creation(self): normal = fh.create_user() u2 = fh.create_user() org = fh.create_organization(subdomain=u'one') orguser = org.attach_user(normal) orguser = org.attach_user(u2) self.flush() project = p.Project(name=u"foobar", creator=normal, description=u"description", organization=org) Session.add(project) self.flush() project2 = p.Project(name=u"meh", creator=u2, description=u"description", organization=org) Session.add(project2) self.flush() act = activity.get_activities(organization=org) assert len(act) == 2 assert act[0].type == activity.NewProject.TYPE assert act[0].project == project2 assert act[0].get_message() assert act[1].type == activity.NewProject.TYPE assert act[1].project == project assert act[1].get_message() act = activity.get_activities(project=project) assert len(act) == 1 assert act[0].type == activity.NewProject.TYPE assert act[0].project == project assert act[0].get_message() act = activity.get_activities(user=normal) assert len(act) == 1 assert act[0].type == activity.NewProject.TYPE assert act[0].project == project assert act[0].get_message()
def test_project_creation(self): normal = fh.create_user() u2 = fh.create_user() org = fh.create_organization(subdomain=u'one') orguser = org.attach_user(normal) orguser = org.attach_user(u2) self.flush() project = p.Project(name=u"foobar", creator=normal, description=u"description", organization=org) Session.add(project) self.flush() project2 = p.Project(name=u"meh", creator=u2, description=u"description", organization=org) Session.add(project2) self.flush() act = activity.get_activities(organization=org) assert len(act) == 2 assert act[0].type == activity.NewProject.TYPE assert act[0].project == project2 assert act[0].get_message() assert act[1].type == activity.NewProject.TYPE assert act[1].project == project assert act[1].get_message() act = activity.get_activities(project=project) assert len(act) == 1 assert act[0].type == activity.NewProject.TYPE assert act[0].project == project assert act[0].get_message() act = activity.get_activities(user=normal) assert len(act) == 1 assert act[0].type == activity.NewProject.TYPE assert act[0].project == project assert act[0].get_message()
def get(real_user, user, organization=None, project=None, entity=None, u=None, offset=None, limit=5): if organization: CanReadOrg().check(real_user, user, organization=organization) if project: CanReadProject().check(real_user, user, project=project) if entity: CanReadEntity().check(real_user, user, entity=entity) act = activity.get_activities(organization=organization, project=project, entity=entity, user=u, offset=offset, limit=limit) return act
def _view_directory(self, entity, project, path, path_components): c.sidepanel_tab = project.name c.project_role = project.get_role(c.user) #all dirs in a project dirs = api.project.get_directories(c.real_user, c.user, c.project) _, all_directories = dirs # all the files in the current dir struc = api.project.get_structure(c.real_user, c.user, c.project, path) if not struc: abort(404) c.structure = v1.project.get_structure(c.real_user, c.user).output(struc) c.tree = v1.project.get_directories().output(dirs) c.path = path # get the most recent files in the sub directories files = project.get_entities(only_type=projects.File.TYPE) setf = set([ os.path.join(d.path, d.name) for d in all_directories if d.path == path ]) c.directory_files = [] c.has_files = False for f in files: if f.path == path: c.has_files = True if f.path.startswith(path) and f.path != path: for d in setf: if f.path.startswith(d): c.directory_files.append((d, f)) setf.remove(d) break c.activity = activity.get_activities(project=c.project, limit=6) #this is pretty slow... c.users = [ projects.ProjectUser(user=u, status=STATUS_APPROVED, role=c.project.get_role(u)) for u in c.project.interested_users ] c.users += c.project.get_user_connections(status=STATUS_PENDING) c.users.sort(key=lambda cu: cu.user.human_name) c.users = c.project.get_invites(has_user=False) + c.users return self.render('/organization/project/view.html')
def index(self): c.title = "All Projects" c.project_data = [(p, p.get_entities(only_type=projects.File.TYPE)[:3]) for p in c.projects] #sort by last time a file in the project was modified c.project_data.sort(lambda l, r: cmp(r[0].last_modified, l[0].last_modified)) c.activity = activity.get_activities(organization=c.organization, limit=6) c.users = [cu for cu in c.organization.get_user_connections(status=None) if cu.status in (STATUS_APPROVED, STATUS_PENDING)] c.users.sort(key=lambda cu: cu.user.human_name) c.users = c.organization.get_invites(has_user=False) + c.users return self.render('/organization/home.html')
def _view_directory(self, entity, project, path, path_components): c.sidepanel_tab = project.name c.project_role = project.get_role(c.user) #all dirs in a project dirs = api.project.get_directories(c.real_user, c.user, c.project) _, all_directories = dirs # all the files in the current dir struc = api.project.get_structure(c.real_user, c.user, c.project, path) if not struc: abort(404) c.structure = v1.project.get_structure(c.real_user, c.user).output(struc) c.tree = v1.project.get_directories().output(dirs) c.path = path # get the most recent files in the sub directories files = project.get_entities(only_type=projects.File.TYPE) setf = set([os.path.join(d.path, d.name) for d in all_directories if d.path == path]) c.directory_files = [] c.has_files = False for f in files: if f.path == path: c.has_files = True if f.path.startswith(path) and f.path != path: for d in setf: if f.path.startswith(d): c.directory_files.append((d, f)) setf.remove(d) break c.activity = activity.get_activities(project=c.project, limit=6) #this is pretty slow... c.users = [projects.ProjectUser(user=u, status=STATUS_APPROVED, role=c.project.get_role(u)) for u in c.project.interested_users] c.users += c.project.get_user_connections(status=STATUS_PENDING) c.users.sort(key=lambda cu: cu.user.human_name) c.users = c.project.get_invites(has_user=False) + c.users return self.render('/organization/project/view.html')
def activity(self, *a, **kw): """ General: Activity Feed A report showing all activity on the site. """ c.title = 'Activity' act = activity.get_activities(limit=100) #last 100 data = [(a.organization, relative_date_str(a.created_date), a.type, a.get_message(), a.user) for a in act] c.params = {} c.params['table'] = { 'columns': ['Org', 'When', 'Type', 'Str', 'User'], 'data': data } return self.render('/admin/report/generic.html')
def index(self): c.title = "All Projects" c.project_data = [(p, p.get_entities(only_type=projects.File.TYPE)[:3]) for p in c.projects] #sort by last time a file in the project was modified c.project_data.sort( lambda l, r: cmp(r[0].last_modified, l[0].last_modified)) c.activity = activity.get_activities(organization=c.organization, limit=6) c.users = [ cu for cu in c.organization.get_user_connections(status=None) if cu.status in (STATUS_APPROVED, STATUS_PENDING) ] c.users.sort(key=lambda cu: cu.user.human_name) c.users = c.organization.get_invites(has_user=False) + c.users return self.render('/organization/home.html')
def get(real_user, user, organization=None, project=None, entity=None, u=None, offset=None, limit=5): if organization: CanReadOrg().check(real_user, user, organization=organization) if project: CanReadProject().check(real_user, user, project=project) if entity: CanReadEntity().check(real_user, user, entity=entity) act = activity.get_activities(organization=organization, project=project, entity=entity, user=u, offset=offset, limit=limit) return act
def test_invite(self): t = (AppException, ) uorg = fh.create_user() uproj = fh.create_user() ufile = fh.create_user() user = fh.create_user() project = fh.create_project(user=user, name=u"helloooo") self.flush() org = project.organization filepath = file_path('ffcc00.gif') change = project.add_change(user, u"/main/project/arnold/foobar.gif", filepath, u"this is a new change") entity = change.entity def fu(email): return Session.query(users.User).filter_by(email=email).first() #invite non-user to org email = '*****@*****.**' inv = users.Invite.create(user, email, org, users.APP_ROLE_WRITE) self.flush() act = activity.get_activities() assert act[0].type == activity.InviteEvent.TYPE assert act[0].get_message() assert inv.invited_email == email assert inv.invited_user == None assert inv.user == user assert inv.role == users.APP_ROLE_WRITE assert inv.type == users.INVITE_TYPE_ORGANIZATION assert inv.object_id == org.id assert inv.status == STATUS_PENDING assert inv.object == org assert self.throws_exception(lambda: inv.accept(), types=t).code == err.INVALID #no user assert self.throws_exception( lambda: inv.accept(uorg), types=t).code == err.INVALID #email no match iu = fh.create_user(username=email, email=email) self.flush() assert org.get_role(iu) == None inv.accept(iu) self.flush() Session.refresh(inv) act = activity.get_activities() assert act[0].type == activity.InviteAccept.TYPE assert org.name in act[0].get_message() assert inv.invited_email == email assert inv.invited_user == iu assert inv.user == user assert inv.type == users.INVITE_TYPE_ORGANIZATION assert inv.object_id == org.id assert inv.status == STATUS_APPROVED assert inv.object == org assert org.get_role(iu) == users.APP_ROLE_WRITE assert self.throws_exception(lambda: users.Invite.create( user, email, org, users.APP_ROLE_WRITE), types=t).code == err.DUPLICATE #invite non-user to project email = '*****@*****.**' inv = users.Invite.create(user, email, project, users.APP_ROLE_ADMIN) self.flush() act = activity.get_activities() assert act[0].type == activity.InviteEvent.TYPE assert project.name in act[0].get_message() assert inv.role == users.APP_ROLE_ADMIN assert inv.type == users.INVITE_TYPE_PROJECT assert inv.object_id == project.id assert inv.object == project iu = fh.create_user(username=email, email=email) self.flush() assert project.get_role(iu) == None inv.accept(iu) self.flush() Session.refresh(inv) act = activity.get_activities() assert act[0].type == activity.InviteAccept.TYPE assert project.name in act[0].get_message() assert inv.invited_user == iu assert project.get_role(iu) == users.APP_ROLE_ADMIN assert org.get_role(iu) == None #invite non-user to entity email = '*****@*****.**' inv = users.Invite.create(user, email, entity, users.APP_ROLE_READ) self.flush() act = activity.get_activities() assert act[0].type == activity.InviteEvent.TYPE assert entity.name in act[0].get_message() assert inv.type == users.INVITE_TYPE_ENTITY assert inv.object_id == entity.id assert inv.object == entity iu = fh.create_user(username=email, email=email) self.flush() assert entity.get_role(iu) == None inv.accept(iu) self.flush() Session.refresh(inv) act = activity.get_activities() assert act[0].type == activity.InviteAccept.TYPE assert entity.name in act[0].get_message() assert inv.invited_user == iu assert entity.get_role(iu) == users.APP_ROLE_READ assert org.get_role(iu) == None assert project.get_role(iu) == None
def test_invite(self): t = (AppException,) uorg = fh.create_user() uproj = fh.create_user() ufile = fh.create_user() user = fh.create_user() project = fh.create_project(user=user, name=u"helloooo") self.flush() org = project.organization filepath = file_path('ffcc00.gif') change = project.add_change(user, u"/main/project/arnold/foobar.gif", filepath, u"this is a new change") entity = change.entity def fu(email): return Session.query(users.User).filter_by(email=email).first() #invite non-user to org email = '*****@*****.**' inv = users.Invite.create(user, email, org, users.APP_ROLE_WRITE) self.flush() act = activity.get_activities() assert act[0].type == activity.InviteEvent.TYPE assert act[0].get_message() assert inv.invited_email == email assert inv.invited_user == None assert inv.user == user assert inv.role == users.APP_ROLE_WRITE assert inv.type == users.INVITE_TYPE_ORGANIZATION assert inv.object_id == org.id assert inv.status == STATUS_PENDING assert inv.object == org assert self.throws_exception(lambda: inv.accept(), types=t).code == err.INVALID #no user assert self.throws_exception(lambda: inv.accept(uorg), types=t).code == err.INVALID #email no match iu = fh.create_user(username=email, email=email) self.flush() assert org.get_role(iu) == None inv.accept(iu) self.flush() Session.refresh(inv) act = activity.get_activities() assert act[0].type == activity.InviteAccept.TYPE assert org.name in act[0].get_message() assert inv.invited_email == email assert inv.invited_user == iu assert inv.user == user assert inv.type == users.INVITE_TYPE_ORGANIZATION assert inv.object_id == org.id assert inv.status == STATUS_APPROVED assert inv.object == org assert org.get_role(iu) == users.APP_ROLE_WRITE assert self.throws_exception(lambda: users.Invite.create(user, email, org, users.APP_ROLE_WRITE), types=t).code == err.DUPLICATE #invite non-user to project email = '*****@*****.**' inv = users.Invite.create(user, email, project, users.APP_ROLE_ADMIN) self.flush() act = activity.get_activities() assert act[0].type == activity.InviteEvent.TYPE assert project.name in act[0].get_message() assert inv.role == users.APP_ROLE_ADMIN assert inv.type == users.INVITE_TYPE_PROJECT assert inv.object_id == project.id assert inv.object == project iu = fh.create_user(username=email, email=email) self.flush() assert project.get_role(iu) == None inv.accept(iu) self.flush() Session.refresh(inv) act = activity.get_activities() assert act[0].type == activity.InviteAccept.TYPE assert project.name in act[0].get_message() assert inv.invited_user == iu assert project.get_role(iu) == users.APP_ROLE_ADMIN assert org.get_role(iu) == None #invite non-user to entity email = '*****@*****.**' inv = users.Invite.create(user, email, entity, users.APP_ROLE_READ) self.flush() act = activity.get_activities() assert act[0].type == activity.InviteEvent.TYPE assert entity.name in act[0].get_message() assert inv.type == users.INVITE_TYPE_ENTITY assert inv.object_id == entity.id assert inv.object == entity iu = fh.create_user(username=email, email=email) self.flush() assert entity.get_role(iu) == None inv.accept(iu) self.flush() Session.refresh(inv) act = activity.get_activities() assert act[0].type == activity.InviteAccept.TYPE assert entity.name in act[0].get_message() assert inv.invited_user == iu assert entity.get_role(iu) == users.APP_ROLE_READ assert org.get_role(iu) == None assert project.get_role(iu) == None