Thread: [Postfixadmin-devel] About Trunk version
Brought to you by:
christian_boltz,
gingerdog
From: Неворотин В. <nev...@gm...> - 2011-02-28 09:43:19
|
Hello! As I can see in trunk you try to rewrite PostfixAdmin with classes and objects (OOP). It's very good and can really make PA more clear. But in fact a code, which is present now in model/ folder, doesn't seem to be correct OOP. To be clear, it's not an OOP at all. You've simply renamed add_user($username, $quota, ....) to $user = new UserHandler($username); $user->add($quota, ...); There isn't any preferences in such renaming. The main goal in OOP is that one class (object) represent a *one* entity. For example, class User represent one user and *no more*. But now, e.g. UserHandler::add, try to represent whole PostfixAdmin, because it do (or will do, when you move code from old create-user.php) auth and privilege checks, domain checks and so on. But if it's a user, it shouldn't do anything, exept a work with one user. AliasHandler has same problems. I understand, that you haven't got enough time to develop PA, but, may be, it's not a good idea to do extra work and write a lot of useless code. Below some concept of possible architecture for PA based on OOP: There is one main class (e.g. pa_main), which handle sessions, configuration, language options etc. It has static field - $instance, which store an object of this class, and static method - getInstance(), which return value of $instance. It can be used like: pa_main::getInstance()->getText($name); pa_main::getInstance()->getConf($param); There is only one class to handle all operations with users. E.g. pa_user. pa_main has a filed $user, which store an pa_user object, which represent current logged in user. pa_user can have methods like: changePasswd($newpass), checkPasswd($pass), isAdmin(), isDomainAdmin($domain), save() [save new pa_user to database], update() [update userinfo in database from current object]. Object of pa_user should store all data for this user from mailbox table of database. pa_user shouldn't do any checks, which are not associated with the db table mailbox. And other parts of PA shouldn't interact with mailbox table directly, only by creating pa_user objects. Similar scheme should be for aliases and domains. And you can also add pa_userslist and pa_aliaseslist to work with groups of users and aliases (e.g. for search). Next: there should be database handler class, e.g. pa_db. pa_main should store one object, which is represent db. E.g. pa_main::getInstance()->getDbh()->query('...'); The similar concept is using in RoundCube - you can look to it's source code. And it's easy to work with RC, because each part of it do their specific job. And you should merge two login pages (for admins and for users) into one and delete two tables - admins and domain_admin, because they repeat the table mailbox and are totally redundant. There shouldn't be also two main pages etc. In fact, if you switch to architecture, based on object and classes, all duplicate pages will be removed automatically. I hope, you'll get something usefull from my letter and will develop PA to be more clear. And will not make classes like UserHandler :) Best regards, Vadim Nevorotin. |
From: Неворотин В. <ma...@ub...> - 2011-02-28 09:44:43
|
Hello! As I can see in trunk you try to rewrite PostfixAdmin with classes and objects (OOP). It's very good and can really make PA more clear. But in fact a code, which is present now in model/ folder, doesn't seem to be correct OOP. To be clear, it's not an OOP at all. You've simply renamed add_user($username, $quota, ....) to $user = new UserHandler($username); $user->add($quota, ...); There isn't any preferences in such renaming. The main goal in OOP is that one class (object) represent a *one* entity. For example, class User represent one user and *no more*. But now, e.g. UserHandler::add, try to represent whole PostfixAdmin, because it do (or will do, when you move code from old create-user.php) auth and privilege checks, domain checks and so on. But if it's a user, it shouldn't do anything, exept a work with one user. AliasHandler has same problems. I understand, that you haven't got enough time to develop PA, but, may be, it's not a good idea to do extra work and write a lot of useless code. Below some concept of possible architecture for PA based on OOP: There is one main class (e.g. pa_main), which handle sessions, configuration, language options etc. It has static field - $instance, which store an object of this class, and static method - getInstance(), which return value of $instance. It can be used like: pa_main::getInstance()->getText($name); pa_main::getInstance()->getConf($param); There is only one class to handle all operations with users. E.g. pa_user. pa_main has a filed $user, which store an pa_user object, which represent current logged in user. pa_user can have methods like: changePasswd($newpass), checkPasswd($pass), isAdmin(), isDomainAdmin($domain), save() [save new pa_user to database], update() [update userinfo in database from current object]. Object of pa_user should store all data for this user from mailbox table of database. pa_user shouldn't do any checks, which are not associated with the db table mailbox. And other parts of PA shouldn't interact with mailbox table directly, only by creating pa_user objects. Similar scheme should be for aliases and domains. And you can also add pa_userslist and pa_aliaseslist to work with groups of users and aliases (e.g. for search). Next: there should be database handler class, e.g. pa_db. pa_main should store one object, which is represent db. E.g. pa_main::getInstance()->getDbh()->query('...'); The similar concept is using in RoundCube - you can look to it's source code. And it's easy to work with RC, because each part of it do their specific job. And you should merge two login pages (for admins and for users) into one and delete two tables - admins and domain_admin, because they repeat the table mailbox and are totally redundant. There shouldn't be also two main pages etc. In fact, if you switch to architecture, based on object and classes, all duplicate pages will be removed automatically. I hope, you'll get something usefull from my letter and will develop PA to be more clear. And will not make classes like UserHandler :) Best regards, Vadim Nevorotin. |
From: Rudi F. <rud...@go...> - 2011-03-01 11:44:24
|
Sorry I meant scripts/snippets I've been working on a new Crypt Class and a model/controller setup. It would be nice if you can submit some of your ideas to this folder. If we have an amount of changes we can open a new trunk folder for PFA 3.0 As Cristian mentioned we try to change to OOP as far es we can and want. The step to MVC is important for various backends like CLI and Web, but we have not so much freetime to go to MVC in the next month. Am 28.02.2011 11:25, schrieb Неворотин Вадим: > Hm, I can't see extras/ folder in SVN repository: > http://postfixadmin.svn.sourceforge.net/viewvc/postfixadmin/ > > 28 февраля 2011 г. 12:59 пользователь Rudi Floren > <rud...@go... <mailto:rud...@go...>> написал: > > There is work on a New model system based on mvc. Watch > extras/snippets. > > Am 28.02.2011 10:45 schrieb "Неворотин Вадим" <ma...@ub... > <mailto:ma...@ub...>>: > > > Hello! > > > > As I can see in trunk you try to rewrite PostfixAdmin with > classes and > > objects (OOP). It's very good and can really make PA more clear. > But in fact > > a code, which is present now in model/ folder, doesn't seem to > be correct > > OOP. To be clear, it's not an OOP at all. You've simply renamed > > > > add_user($username, $quota, ....) > > > > to > > > > $user = new UserHandler($username); > > $user->add($quota, ...); > > > > There isn't any preferences in such renaming. The main goal in > OOP is that > > one class (object) represent a *one* entity. For example, class User > > represent one user and *no more*. But now, e.g. > UserHandler::add, try to > > represent whole PostfixAdmin, because it do (or will do, when > you move code > > from old create-user.php) auth and privilege checks, domain > checks and so > > on. But if it's a user, it shouldn't do anything, exept a work > with one > > user. AliasHandler has same problems. > > > > I understand, that you haven't got enough time to develop PA, > but, may be, > > it's not a good idea to do extra work and write a lot of useless > code. > > > > Below some concept of possible architecture for PA based on OOP: > > > > There is one main class (e.g. pa_main), which handle sessions, > > configuration, language options etc. It has static field - > $instance, which > > store an object of this class, and static method - > getInstance(), which > > return value of $instance. It can be used like: > > > > pa_main::getInstance()->getText($name); > > pa_main::getInstance()->getConf($param); > > > > There is only one class to handle all operations with users. > E.g. pa_user. > > pa_main has a filed $user, which store an pa_user object, which > represent > > current logged in user. > > > > pa_user can have methods like: changePasswd($newpass), > checkPasswd($pass), > > isAdmin(), isDomainAdmin($domain), save() [save new pa_user to > database], > > update() [update userinfo in database from current object]. > Object of > > pa_user should store all data for this user from mailbox table > of database. > > > > pa_user shouldn't do any checks, which are not associated with > the db table > > mailbox. And other parts of PA shouldn't interact with mailbox table > > directly, only by creating pa_user objects. > > > > Similar scheme should be for aliases and domains. And you can > also add > > pa_userslist and pa_aliaseslist to work with groups of users and > aliases > > (e.g. for search). > > > > Next: there should be database handler class, e.g. pa_db. > pa_main should > > store one object, which is represent db. E.g. > > > > pa_main::getInstance()->getDbh()->query('...'); > > > > The similar concept is using in RoundCube - you can look to it's > source > > code. And it's easy to work with RC, because each part of it do > their > > specific job. > > > > And you should merge two login pages (for admins and for users) > into one and > > delete two tables - admins and domain_admin, because they repeat > the table > > mailbox and are totally redundant. There shouldn't be also two > main pages > > etc. In fact, if you switch to > > architecture, based on object and classes, all duplicate pages > will be > > removed automatically. > > > > I hope, you'll get something usefull from my letter and will > develop PA to > > be more clear. And will not make classes like UserHandler :) > > > > Best regards, Vadim Nevorotin. > > |
From: Christian B. <pos...@cb...> - 2011-02-28 23:50:38
|
Hello, (CC'ing you because you are not subscribed to postfixadmin-devel) Am Montag, 28. Februar 2011 schrieb Неворотин Вадим: > As I can see in trunk you try to rewrite PostfixAdmin with classes > and objects (OOP). It's very good and can really make PA more clear. > But in fact a code, which is present now in model/ folder, doesn't > seem to be correct OOP. To be clear, it's not an OOP at all. You've > simply renamed > > add_user($username, $quota, ....) > > to > > $user = new UserHandler($username); > $user->add($quota, ...); [...] > I understand, that you haven't got enough time to develop PA, but, > may be, it's not a good idea to do extra work and write a lot of > useless code. I have to disagree slightly ;-) You are correct that model/* are not 100% pure OOP. I'd like to tell you our current targets regarding those files: First and most important: have one instance of the code for doing a job - and not one in "create- mailbox", one in "edit-mailbox" and another one in the commandline client. Besides that, I want to have a common interface in all classes (where it makes sense - things like "create", "update", "delete"), so that - adding custom fields is very easy (see $fm_struct and $fm_defaults in fetchmail.php - it will become something like this) - creating a new module in PostfixAdmin is easy (I'm dreaming of something like "define two arrays, add a menu entry and you'll get list and edit mode including input validation. Yes, that is possible.) Of course I also have the "usual" reasons for OOP in mind, but not always as primary goals. > Below some concept of possible architecture for PA based on OOP: [...] That looks like 100% OOP. Don't get me wrong - there's nothing wrong with OOP, but I don't insist on using OOP just because it is OOP. There has to be a clear advantage. For example, I don't see the advantage of a DB class over the db_* functions we have, and therefore I'm not too keen to write pa_main::getInstance()->getDbh()->query('...'); instead of db_query('...'); (I hate XSLT for similar reasons ;-) OTOH, your mail also contains lots of useful ideas for the model/* files. I won't comment on each of them and just say "thanks!" instead. > And you should merge two login pages (for admins and for users) into > one That's not as easy as it sounds - what if there are an admin and a mailbox with the same name? Choose the one where the password matches? ;-) > and delete two tables - admins and domain_admin, because they > repeat the table mailbox and are totally redundant. They are not - if you check the content of those tables, you'll notice that they contain very different stuff (especially domain_admin). If your intention is to use mailbox passwords for admin logins: that's something we discussed some time ago, but I don't really like it. > There shouldn't > be also two main pages etc. In fact, if you switch to > architecture, based on object and classes, all duplicate pages will > be removed automatically. You don't even want to know how much duplicate code I removed since I'm working on PostfixAdmin ;-) For example, edit-alias existed for domain admins, for superadmins and for users - and each of them had nearly the same code (except the UPDATE query) duplicated for GET and POST... (If you are really interested, checkout SVN r1 from sourceforge and look at the code. But: you have been warned! *eg*) There's no need to tell me that duplicate code is evil - the problem is that it needs some development time to remove/merge it (usually every copy comes with different bugs ;-) ), and unfortunately this doesn't happen "automatically". So we have the choice between a) doing a "90% OOP" class quite fast to avoid that we have to maintain 3 copies of the same functionality - or - b) do 100% OOP with at least double development time (you'll always find something that is not OOP'ed yet) and have to maintain the old code until that is done. My choice for now is "90% OOP", and the reason is quite easy: with the same time spent, we'll only have 50% of the "100% OOP" done, and still have to manage half of the "old" code ;-) The long term handling might be different and tend to 99% OOP ;-) > I hope, you'll get something usefull from my letter and will develop > PA to be more clear. And will not make classes like UserHandler :) The layout and interface is not set in stone (and not perfect). But it is much better than what we had before, and I already have some things in mind that I want to change. Unfortunately, the same problem about "time" applies here. Nevertheless: thanks for your comments! Regards, Christian Boltz PS: hand-picked .sig today ;-) -- In most cases, XSLT is good enough. But I agree, for some parts you need Aspirin. ;-) [Thomas Schraitle in opensuse-doc] |