예제 #1
0
파일: domain.py 프로젝트: SURFscz/SBS
class User(Base, db.Model):
    __tablename__ = "users"
    id = db.Column("id", db.Integer(), primary_key=True, nullable=False, autoincrement=True)
    uid = db.Column("uid", db.String(length=512), nullable=False)
    name = db.Column("name", db.String(length=255), nullable=True)
    username = db.Column("username", db.String(length=255), nullable=True)
    nick_name = db.Column("nick_name", db.String(length=255), nullable=True)
    edu_members = db.Column("edu_members", db.Text(), nullable=True)
    address = db.Column("address", db.String(length=255), nullable=True)
    affiliation = db.Column("affiliation", db.Text(), nullable=True)
    scoped_affiliation = db.Column("scoped_affiliation", db.Text(), nullable=True)
    entitlement = db.Column("entitlement", db.Text(), nullable=True)
    schac_home_organisation = db.Column("schac_home_organisation", db.String(length=255), nullable=True)
    family_name = db.Column("family_name", db.String(length=255), nullable=True)
    given_name = db.Column("given_name", db.String(length=255), nullable=True)
    email = db.Column("email", db.String(length=255), nullable=True)
    second_factor_auth = db.Column("second_factor_auth", db.String(length=255), nullable=True)
    ssh_keys = db.relationship("SshKey", back_populates="user", cascade="all, delete-orphan", passive_deletes=True,
                               lazy="selectin")
    user_ip_networks = db.relationship("UserIpNetwork", cascade="all, delete-orphan", passive_deletes=True,
                                       lazy="selectin")
    created_by = db.Column("created_by", db.String(length=512), nullable=False)
    created_at = db.Column("created_at", db.DateTime(timezone=True), server_default=db.text("CURRENT_TIMESTAMP"),
                           nullable=False)
    updated_by = db.Column("updated_by", db.String(length=512), nullable=False)
    organisation_memberships = db.relationship("OrganisationMembership", back_populates="user",
                                               cascade_backrefs=False, passive_deletes=True)
    collaboration_memberships = db.relationship("CollaborationMembership", back_populates="user",
                                                cascade_backrefs=False, passive_deletes=True)
    collaboration_requests = db.relationship("CollaborationRequest", back_populates="requester",
                                             cascade_backrefs=False, passive_deletes=True)
    service_memberships = db.relationship("ServiceMembership", back_populates="user",
                                          cascade_backrefs=False, passive_deletes=True)
    join_requests = db.relationship("JoinRequest", back_populates="user", cascade_backrefs=False, passive_deletes=True)
    aups = db.relationship("Aup", back_populates="user", cascade="all, delete-orphan", passive_deletes=True)
    service_aups = db.relationship("ServiceAup", back_populates="user", cascade="all, delete-orphan",
                                   passive_deletes=True)
    user_tokens = db.relationship("UserToken", back_populates="user", cascade="all, delete-orphan",
                                  passive_deletes=True)
    confirmed_super_user = db.Column("confirmed_super_user", db.Boolean(), nullable=True, default=False)
    eduperson_principal_name = db.Column("eduperson_principal_name", db.String(length=255), nullable=True)
    application_uid = db.Column("application_uid", db.String(length=255), nullable=True)
    last_accessed_date = db.Column("last_accessed_date", db.DateTime(timezone=True), nullable=False)
    last_login_date = db.Column("last_login_date", db.DateTime(timezone=True), nullable=False)
    suspended = db.Column("suspended", db.Boolean(), nullable=True, default=False)
    suspend_notifications = db.relationship("SuspendNotification", back_populates="user", cascade="all, delete-orphan",
                                            passive_deletes=True)
    mfa_reset_token = db.Column("mfa_reset_token", db.String(length=512), nullable=True)
    second_fa_uuid = db.Column("second_fa_uuid", db.String(length=512), nullable=True)
    user_mails = db.relationship("UserMail", back_populates="user", cascade="all, delete-orphan", passive_deletes=True)

    def has_agreed_with_aup(self):
        return len([aup for aup in self.aups if aup.au_version == str(current_app.app_config.aup.version)]) > 0
예제 #2
0
파일: domain.py 프로젝트: SURFscz/SBS
class Service(Base, db.Model, LogoMixin):
    __tablename__ = "services"
    id = db.Column("id", db.Integer(), primary_key=True, nullable=False, autoincrement=True)
    entity_id = db.Column("entity_id", db.String(length=255), nullable=False)
    name = db.Column("name", db.String(length=255), nullable=False)
    description = db.Column("description", db.Text(), nullable=True)
    logo = db.Column("logo", db.Text(), nullable=True)
    uuid4 = db.Column("uuid4", db.String(length=255), nullable=False, default=gen_uuid4)
    address = db.Column("address", db.Text(), nullable=True)
    identity_type = db.Column("identity_type", db.String(length=255), nullable=True)
    abbreviation = db.Column("abbreviation", db.String(length=255), nullable=False)
    uri = db.Column("uri", db.String(length=255), nullable=True)
    privacy_policy = db.Column("privacy_policy", db.String(length=255), nullable=False)
    accepted_user_policy = db.Column("accepted_user_policy", db.Text(), nullable=True)
    ldap_password = db.Column("ldap_password", db.String(length=255), nullable=True)
    contact_email = db.Column("contact_email", db.String(length=255), nullable=True)
    support_email = db.Column("support_email", db.String(length=255), nullable=True)
    security_email = db.Column("security_email", db.String(length=255), nullable=True)
    public_visible = db.Column("public_visible", db.Boolean(), nullable=True, default=True)
    automatic_connection_allowed = db.Column("automatic_connection_allowed", db.Boolean(), nullable=True, default=True)
    access_allowed_for_all = db.Column("access_allowed_for_all", db.Boolean(), nullable=True, default=False)
    white_listed = db.Column("white_listed", db.Boolean(), nullable=True, default=False)
    non_member_users_access_allowed = db.Column("non_member_users_access_allowed", db.Boolean(), nullable=True,
                                                default=False)
    research_scholarship_compliant = db.Column("research_scholarship_compliant", db.Boolean(),
                                               nullable=True,
                                               default=False)
    code_of_conduct_compliant = db.Column("code_of_conduct_compliant", db.Boolean(), nullable=True, default=False)
    sirtfi_compliant = db.Column("sirtfi_compliant", db.Boolean(), nullable=True, default=False)
    token_enabled = db.Column("token_enabled", db.Boolean(), nullable=True, default=False)
    hashed_token = db.Column("hashed_token", db.String(length=255), nullable=True, default=None)
    token_validity_days = db.Column("token_validity_days", db.Integer(), nullable=True, default=0)
    collaborations = db.relationship("Collaboration", secondary=services_collaborations_association, lazy="select",
                                     back_populates="services")
    allowed_organisations = db.relationship("Organisation", secondary=organisations_services_association, lazy="select")
    organisations = db.relationship("Organisation", secondary=services_organisations_association, lazy="select",
                                    back_populates="services")
    ip_networks = db.relationship("IpNetwork", cascade="all, delete-orphan", passive_deletes=True)
    service_connection_requests = db.relationship("ServiceConnectionRequest", back_populates="service",
                                                  cascade="all, delete-orphan", passive_deletes=True)
    service_groups = db.relationship("ServiceGroup", back_populates="service", cascade="all, delete-orphan",
                                     passive_deletes=True)
    service_memberships = db.relationship("ServiceMembership", back_populates="service",
                                          cascade="all, delete-orphan", passive_deletes=True)
    service_invitations = db.relationship("ServiceInvitation", back_populates="service",
                                          cascade="all, delete-orphan", passive_deletes=True)
    service_aups = db.relationship("ServiceAup", back_populates="service", cascade="all, delete-orphan",
                                   passive_deletes=True)
    user_tokens = db.relationship("UserToken", back_populates="service", cascade="all, delete-orphan",
                                  passive_deletes=True)
    created_by = db.Column("created_by", db.String(length=512), nullable=True)
    updated_by = db.Column("updated_by", db.String(length=512), nullable=True)
    created_at = db.Column("created_at", db.DateTime(timezone=True), server_default=db.text("CURRENT_TIMESTAMP"),
                           nullable=False)

    def is_member(self, user_id):
        return len(list(filter(lambda membership: membership.user_id == user_id, self.service_memberships))) > 0
예제 #3
0
파일: domain.py 프로젝트: SURFscz/SBS
class SuspendNotification(Base, db.Model):
    __tablename__ = "suspend_notifications"
    id = db.Column("id", db.Integer(), primary_key=True, nullable=False, autoincrement=True)
    user_id = db.Column(db.Integer(), db.ForeignKey("users.id"))
    user = db.relationship("User", back_populates="suspend_notifications")
    sent_at = db.Column("sent_at", db.DateTime(timezone=True), server_default=db.text("CURRENT_TIMESTAMP"),
                        nullable=False)
    is_primary = db.Column("is_primary", db.Boolean(), nullable=True, default=False)
예제 #4
0
파일: domain.py 프로젝트: SURFscz/SBS
class Organisation(Base, db.Model, LogoMixin):
    __tablename__ = "organisations"
    id = db.Column("id", db.Integer(), primary_key=True, nullable=False, autoincrement=True)
    name = db.Column("name", db.String(length=255), nullable=False)
    identifier = db.Column("identifier", db.String(length=255), nullable=False)
    short_name = db.Column("short_name", db.String(length=255), nullable=True)
    category = db.Column("category", db.String(length=255), nullable=True)
    description = db.Column("description", db.Text(), nullable=True)
    logo = db.Column("logo", db.Text(), nullable=True)
    uuid4 = db.Column("uuid4", db.String(length=255), nullable=False, default=gen_uuid4)
    on_boarding_msg = db.Column("on_boarding_msg", db.Text(), nullable=True)
    schac_home_organisations = db.relationship("SchacHomeOrganisation", cascade="all, delete-orphan",
                                               passive_deletes=True, lazy="selectin")
    services_restricted = db.Column("services_restricted", db.Boolean(), nullable=True, default=False)
    created_by = db.Column("created_by", db.String(length=512), nullable=False)
    created_at = db.Column("created_at", db.DateTime(timezone=True), server_default=db.text("CURRENT_TIMESTAMP"),
                           nullable=False)
    updated_by = db.Column("updated_by", db.String(length=512), nullable=False)
    collaboration_creation_allowed = db.Column("collaboration_creation_allowed", db.Boolean(), nullable=True,
                                               default=False)
    collaborations = db.relationship("Collaboration", back_populates="organisation", cascade="all, delete-orphan",
                                     passive_deletes=True)
    services = db.relationship("Service", secondary=services_organisations_association, lazy="select",
                               back_populates="organisations")
    collaboration_requests = db.relationship("CollaborationRequest", back_populates="organisation",
                                             cascade="all, delete-orphan",
                                             passive_deletes=True)
    organisation_memberships = db.relationship("OrganisationMembership", back_populates="organisation",
                                               cascade="all, delete-orphan", passive_deletes=True)
    organisation_invitations = db.relationship("OrganisationInvitation", back_populates="organisation",
                                               cascade="all, delete-orphan",
                                               passive_deletes=True)
    api_keys = db.relationship("ApiKey", back_populates="organisation",
                               cascade="delete, delete-orphan",
                               passive_deletes=True)
    collaborations_count = column_property(select([func.count(Collaboration.id)])
                                           .where(Collaboration.organisation_id == id)
                                           .correlate_except(Collaboration)
                                           .scalar_subquery())
    organisation_memberships_count = column_property(select([func.count(OrganisationMembership.id)])
                                                     .where(OrganisationMembership.organisation_id == id)
                                                     .correlate_except(OrganisationMembership)
                                                     .scalar_subquery())

    def is_member(self, user_id):
        return len(list(filter(lambda membership: membership.user_id == user_id, self.organisation_memberships))) > 0
예제 #5
0
파일: domain.py 프로젝트: SURFscz/SBS
class ServiceGroup(Base, db.Model):
    __tablename__ = "service_groups"
    id = db.Column("id", db.Integer(), primary_key=True, nullable=False, autoincrement=True)
    name = db.Column("name", db.String(length=255), nullable=False)
    short_name = db.Column("short_name", db.String(length=255), nullable=True)
    description = db.Column("description", db.Text(), nullable=True)
    auto_provision_members = db.Column("auto_provision_members", db.Boolean(), nullable=True, default=False)
    service_id = db.Column(db.Integer(), db.ForeignKey("services.id"))
    service = db.relationship("Service", back_populates="service_groups")
    created_by = db.Column("created_by", db.String(length=512), nullable=False)
    updated_by = db.Column("updated_by", db.String(length=512), nullable=False)
    created_at = db.Column("created_at", db.DateTime(timezone=True), server_default=db.text("CURRENT_TIMESTAMP"),
                           nullable=False)
예제 #6
0
파일: domain.py 프로젝트: SURFscz/SBS
class ServiceConnectionRequest(Base, db.Model):
    __tablename__ = "service_connection_requests"
    id = db.Column("id", db.Integer(), primary_key=True, nullable=False, autoincrement=True)
    message = db.Column("message", db.Text(), nullable=True)
    hash = db.Column("hash", db.String(length=512), nullable=False)
    is_member_request = db.Column("is_member_request", db.Boolean(), nullable=True, default=False)
    requester_id = db.Column(db.Integer(), db.ForeignKey("users.id"))
    requester = db.relationship("User")
    service_id = db.Column(db.Integer(), db.ForeignKey("services.id"))
    service = db.relationship("Service", back_populates="service_connection_requests")
    collaboration_id = db.Column(db.Integer(), db.ForeignKey("collaborations.id"))
    collaboration = db.relationship("Collaboration", back_populates="service_connection_requests")
    created_by = db.Column("created_by", db.String(length=512), nullable=False)
    updated_by = db.Column("updated_by", db.String(length=512), nullable=False)
    created_at = db.Column("created_at", db.DateTime(timezone=True), server_default=db.text("CURRENT_TIMESTAMP"),
                           nullable=False)
예제 #7
0
파일: domain.py 프로젝트: SURFscz/SBS
class Group(Base, db.Model):
    __tablename__ = "groups"
    id = db.Column("id", db.Integer(), primary_key=True, nullable=False, autoincrement=True)
    name = db.Column("name", db.String(length=255), nullable=False)
    identifier = db.Column("identifier", db.String(length=255), nullable=False)
    short_name = db.Column("short_name", db.String(length=255), nullable=True)
    global_urn = db.Column("global_urn", db.Text, nullable=True)
    description = db.Column("description", db.Text(), nullable=True)
    auto_provision_members = db.Column("auto_provision_members", db.Boolean(), nullable=True, default=False)
    collaboration_id = db.Column(db.Integer(), db.ForeignKey("collaborations.id"))
    collaboration = db.relationship("Collaboration", back_populates="groups")
    collaboration_memberships = db.relationship("CollaborationMembership",
                                                secondary=collaboration_memberships_groups_association,
                                                back_populates="groups",
                                                lazy="select")
    invitations = db.relationship("Invitation", secondary=groups_invitations_association, lazy="select",
                                  back_populates="groups")
    created_by = db.Column("created_by", db.String(length=512), nullable=False)
    updated_by = db.Column("updated_by", db.String(length=512), nullable=False)
    created_at = db.Column("created_at", db.DateTime(timezone=True), server_default=db.text("CURRENT_TIMESTAMP"),
                           nullable=False)

    def is_member(self, user_id):
        return len(list(filter(lambda membership: membership.user_id == user_id, self.collaboration_memberships))) > 0
예제 #8
0
파일: domain.py 프로젝트: SURFscz/SBS
class Collaboration(Base, db.Model, LogoMixin):
    __tablename__ = "collaborations"
    id = db.Column("id", db.Integer(), primary_key=True, nullable=False, autoincrement=True)
    identifier = db.Column("identifier", db.String(length=255), nullable=False)
    name = db.Column("name", db.String(length=255), nullable=False)
    description = db.Column("description", db.Text(), nullable=True)
    logo = db.Column("logo", db.Text(), nullable=True)
    uuid4 = db.Column("uuid4", db.String(length=255), nullable=False, default=gen_uuid4)
    short_name = db.Column("short_name", db.String(length=255), nullable=True)
    global_urn = db.Column("global_urn", db.Text, nullable=True)
    accepted_user_policy = db.Column("accepted_user_policy", db.Text(), nullable=True)
    status = db.Column("status", db.String(length=255), nullable=False, default=STATUS_ACTIVE)
    last_activity_date = db.Column("last_activity_date", db.DateTime(timezone=True), nullable=False,
                                   server_default=db.text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"))
    expiry_date = db.Column("expiry_date", db.DateTime(timezone=True), nullable=True)
    organisation_id = db.Column(db.Integer(), db.ForeignKey("organisations.id"))
    organisation = db.relationship("Organisation", back_populates="collaborations")
    created_by = db.Column("created_by", db.String(length=512), nullable=False)
    updated_by = db.Column("updated_by", db.String(length=512), nullable=False)
    created_at = db.Column("created_at", db.DateTime(timezone=True), server_default=db.text("CURRENT_TIMESTAMP"),
                           nullable=False)
    services = db.relationship("Service", secondary=services_collaborations_association, lazy="select",
                               back_populates="collaborations")
    collaboration_memberships = db.relationship("CollaborationMembership", back_populates="collaboration",
                                                cascade="all, delete-orphan", passive_deletes=True)
    groups = db.relationship("Group", back_populates="collaboration",
                             cascade="all, delete-orphan", passive_deletes=True)
    join_requests = db.relationship("JoinRequest", back_populates="collaboration",
                                    cascade="all, delete-orphan", passive_deletes=True)
    invitations = db.relationship("Invitation", back_populates="collaboration", cascade="all, delete-orphan",
                                  passive_deletes=True)
    service_connection_requests = db.relationship("ServiceConnectionRequest", back_populates="collaboration",
                                                  cascade="all, delete-orphan", passive_deletes=True)
    disable_join_requests = db.Column("disable_join_requests", db.Boolean(), nullable=True, default=False)
    disclose_member_information = db.Column("disclose_member_information", db.Boolean(), nullable=True, default=False)
    disclose_email_information = db.Column("disclose_email_information", db.Boolean(), nullable=True, default=False)
    website_url = db.Column("website_url", db.String(length=512), nullable=True)
    invitations_count = column_property(select([func.count(Invitation.id)])
                                        .where(Invitation.collaboration_id == id)
                                        .correlate_except(Invitation)
                                        .scalar_subquery())
    collaboration_memberships_count = column_property(select([func.count(CollaborationMembership.id)])
                                                      .where(CollaborationMembership.collaboration_id == id)
                                                      .correlate_except(CollaborationMembership)
                                                      .scalar_subquery())

    def is_member(self, user_id):
        return len(list(filter(lambda membership: membership.user_id == user_id, self.collaboration_memberships))) > 0

    def is_admin(self, user_id):
        for membership in self.collaboration_memberships:
            if membership.user_id == user_id and membership.role == "admin":
                return True
        return False

    def service_emails(self):
        services = self.services + self.organisation.services
        res = {}
        for service in services:
            if service.contact_email:
                res[service.id] = [service.contact_email]
            else:
                res[service.id] = [membership.user.email for membership in service.service_memberships]
        return res