Search in sources :

Example 46 with PersonDAO

use of fi.otavanopisto.pyramus.dao.base.PersonDAO in project pyramus by otavanopisto.

the class EditStudentViewController method checkAccess.

@Override
protected boolean checkAccess(RequestContext requestContext) {
    UserDAO userDAO = DAOFactory.getInstance().getUserDAO();
    PersonDAO personDAO = DAOFactory.getInstance().getPersonDAO();
    Long loggedUserId = requestContext.getLoggedUserId();
    User user = userDAO.findById(loggedUserId);
    if (!Permissions.instance().hasEnvironmentPermission(user, PyramusViewPermissions.EDIT_STUDENT)) {
        return false;
    } else {
        if (UserUtils.canAccessAllOrganizations(user)) {
            return true;
        } else {
            Long personId = requestContext.getLong("person");
            Person person = personDAO.findById(personId);
            for (Student student : person.getStudents()) {
                if (UserUtils.isMemberOf(user, student.getOrganization())) {
                    // Having one common organization is enough - though the view may not allow editing all
                    return true;
                }
            }
            return false;
        }
    }
}
Also used : PersonDAO(fi.otavanopisto.pyramus.dao.base.PersonDAO) User(fi.otavanopisto.pyramus.domainmodel.users.User) UserDAO(fi.otavanopisto.pyramus.dao.users.UserDAO) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) Person(fi.otavanopisto.pyramus.domainmodel.base.Person)

Example 47 with PersonDAO

use of fi.otavanopisto.pyramus.dao.base.PersonDAO in project pyramus by otavanopisto.

the class AdminPasswordSetupWizardViewController method save.

@Override
public void save(PageRequestContext requestContext) throws SetupWizardException {
    String username = requestContext.getString("username");
    String password = requestContext.getString("password1");
    String firstName = requestContext.getString("firstName");
    String lastName = requestContext.getString("lastName");
    String passwordMD5 = DigestUtils.md5Hex(password);
    StaffMemberDAO userDAO = DAOFactory.getInstance().getStaffMemberDAO();
    InternalAuthDAO internalAuthDAO = DAOFactory.getInstance().getInternalAuthDAO();
    PersonDAO personDAO = DAOFactory.getInstance().getPersonDAO();
    UserIdentificationDAO userIdentificationDAO = DAOFactory.getInstance().getUserIdentificationDAO();
    DefaultsDAO defaultsDAO = DAOFactory.getInstance().getDefaultsDAO();
    Defaults defaults = defaultsDAO.getDefaults();
    InternalAuth internalAuth = internalAuthDAO.create(username, passwordMD5);
    Person person = personDAO.create(null, null, null, null, Boolean.FALSE);
    userIdentificationDAO.create(person, "internal", String.valueOf(internalAuth.getId()));
    User user = userDAO.create(defaults.getOrganization(), firstName, lastName, Role.ADMINISTRATOR, person, false);
    personDAO.updateDefaultUser(person, user);
}
Also used : PersonDAO(fi.otavanopisto.pyramus.dao.base.PersonDAO) StaffMemberDAO(fi.otavanopisto.pyramus.dao.users.StaffMemberDAO) Defaults(fi.otavanopisto.pyramus.domainmodel.base.Defaults) User(fi.otavanopisto.pyramus.domainmodel.users.User) InternalAuthDAO(fi.otavanopisto.pyramus.dao.users.InternalAuthDAO) DefaultsDAO(fi.otavanopisto.pyramus.dao.base.DefaultsDAO) InternalAuth(fi.otavanopisto.pyramus.domainmodel.users.InternalAuth) Person(fi.otavanopisto.pyramus.domainmodel.base.Person) UserIdentificationDAO(fi.otavanopisto.pyramus.dao.users.UserIdentificationDAO)

Aggregations

PersonDAO (fi.otavanopisto.pyramus.dao.base.PersonDAO)47 Person (fi.otavanopisto.pyramus.domainmodel.base.Person)42 Student (fi.otavanopisto.pyramus.domainmodel.students.Student)25 StudentDAO (fi.otavanopisto.pyramus.dao.students.StudentDAO)21 StaffMemberDAO (fi.otavanopisto.pyramus.dao.users.StaffMemberDAO)17 StaffMember (fi.otavanopisto.pyramus.domainmodel.users.StaffMember)14 User (fi.otavanopisto.pyramus.domainmodel.users.User)14 HashMap (java.util.HashMap)12 EmailDAO (fi.otavanopisto.pyramus.dao.base.EmailDAO)11 ContactTypeDAO (fi.otavanopisto.pyramus.dao.base.ContactTypeDAO)10 UserVariableDAO (fi.otavanopisto.pyramus.dao.users.UserVariableDAO)10 ContactType (fi.otavanopisto.pyramus.domainmodel.base.ContactType)10 StudyProgramme (fi.otavanopisto.pyramus.domainmodel.base.StudyProgramme)10 UserDAO (fi.otavanopisto.pyramus.dao.users.UserDAO)9 Language (fi.otavanopisto.pyramus.domainmodel.base.Language)9 Municipality (fi.otavanopisto.pyramus.domainmodel.base.Municipality)9 Nationality (fi.otavanopisto.pyramus.domainmodel.base.Nationality)9 School (fi.otavanopisto.pyramus.domainmodel.base.School)9 PhoneNumberDAO (fi.otavanopisto.pyramus.dao.base.PhoneNumberDAO)8 StudyProgrammeDAO (fi.otavanopisto.pyramus.dao.base.StudyProgrammeDAO)8